【发布时间】:2019-08-22 18:52:11
【问题描述】:
我不擅长使用 web 驱动程序编写 selenium 测试用例。
请告诉我如何设置我的测试用例。
注意:我不想使用 Selenium IDE。
谢谢
【问题讨论】:
标签: selenium selenium-webdriver
我不擅长使用 web 驱动程序编写 selenium 测试用例。
请告诉我如何设置我的测试用例。
注意:我不想使用 Selenium IDE。
谢谢
【问题讨论】:
标签: selenium selenium-webdriver
您可以使用 selenium webdriver 从您的代码驱动浏览器。从 firefox 驱动程序开始,因为您不需要对其进行任何设置。对于其他浏览器,如 chrome,您需要设置驱动程序。您可以开始这里:
http://seleniumhq.org/docs/03_webdriver.html#introducing-the-selenium-webdriver-api-by-example
HTH
【讨论】:
自己完成了设置。。谢谢
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:testContextWeb.xml"})
public class SeleniumTest {
WebDriver driver;
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
}
@After
public void tearDown() throws Exception {
driver.close();
}
@Test
public void testCase() throws Exception {
//open the event page
driver.get("https://websiteAddress/Context");
driver.findElement(By.xpath(".//*[@id='username']")).sendKeys("someUserName");
driver.findElement(By.xpath(".//*[@id='password']")).sendKeys("xxxx"); // "xxxx" means some password
}
}
【讨论】: