使用硒登录页面的测试用例; java和Eclipse IDE
我是新的selenium webdriver,java(junit)和eclipse IDE。
请帮助我提供登录页面的所有测试用例。
我已经设法使用selenium和Junit在eclipse IDE中的测试套件中编写一个测试用例。
供您参考的两个课程是:
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
public class TestSuite1 extends TestCase {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(TestCase1.class);
//suite.addTestSuite((Case1) Testcase1.newInstance());
//suite.addTestSuite(TestCase1.newInstance());
return suite;
}
public static void main(String arg[]) {
TestRunner.run(suite());
}
}
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
import com.thoughtworks.selenium.SeleneseTestCase;
public class TestCase1 extends SeleneseTestCase {
public void setUp() throws Exception {
login();
}
public void login() {
WebDriver driver = new FirefoxDriver();
driver.get("http://");
WebElement id = driver.findElement(By.name("username"));
WebElement pass = driver.findElement(By.name("password"));
WebElement button = driver.findElement(By.xpath("/html/body/div/div/div[2]/div/form/p[3]/input"));
id.sendKeys("tuser991@yahoo.co.in");
pass.sendKeys("abc123");
button.submit();
}
}
尝试使用button.click()
而不是button.submit()
。 我看到使用提交的一些问题。 此外,如果你正在使用eclipse进入selenium webdriver,请查看Conductor框架。 它大大简化了事情。 你的测试看起来像:
@Config(url="http://mypage/login", browser=Browser.FIREFOX)
public class TestCase1 extends Locomotive {
@Test
public void login() {
setText(By.name("username"), "tuser991@yahoo.co.in")
.setText(By.name("password"), "abc123")
.click(By.xpath("/html/body/div/div/div[2]/div/form/p[3]/input"))
.validateTextPresent("You are now logged in");
}
}
链接地址: http://www.djcxy.com/p/52329.html
上一篇: test cases for login page using selenium ; java and Eclipse IDE
下一篇: How to open too many browsers using Selenium WebDriver?