我是Selenium及其框架的新手,在以下方面需要帮助:
我在程序1中使用了如下所示的set属性,因为我在发送密钥时遇到问题。密钥的发送速度非常慢,但是通过使用setProperty解决了这个问题。
然而,当我像在程序2中那样拆分这段代码进行测试时,尽管设置了属性,但密钥发送速度很慢。我的设置有什么问题吗?
计划1
public class BAU{
public static void main(final String[] args) throws interruptedException{
System .setProperty("webdriver.ie.driver","C:\\Selenium-Internet Explorer Driver Server v2.48.0(for 32 bit Windows IE)\\Selenium-Internet Explorer Driver Server v2.48.0(for 32 bit Windows IE)\\IEDriverServer.exe");
WebDriver drive = new InternetExplorerDriver();
drive.get("https:/testlogin.html");
drive.manage().window().maximize();
Thread.sleep(500);
drive.findElement(By.name("i_username")).sendKeys("Abcde");
drive.findElement(By.name("i_password")).sendKeys("Pass");
this.drive.findElement(By.className("btnPrimary")).click();
}
}节目2
public class BAU_TESTING{
@Test(priority = 1)
public void setProperty(){
System .setProperty("webdriver.ie.driver","C:\\Selenium-Internet Explorer Driver Server v2.48.0(for 32 bit Windows IE)\\Selenium-Internet Explorer Driver Server v2.48.0(for 32 bit Windows IE)\\IEDriverServer.exe");
}
WebDriver drive = new InternetExplorerDriver();
@Test(priority = 2)
public void launchBrowser() throws InterruptedException {
this.drive.get("https:/testlogin.html");
this.drive.manage().window().maximize();
Thread.sleep(500);
System.out.println("Test Case 1 for launching the page has been executed");
}
@Test(priority = 3)
public void loginPage() throws InterruptedException {
this.drive.findElement(By.name("i_username")).sendKeys("Abcde");
this.drive.findElement(By.name("i_password")).sendKeys("Pass");
this.drive.findElement(By.className("btnPrimary")).click();
}
}发布于 2018-06-08 22:38:16
我建议您将setProperty()、打开页面和其他常见操作放在单独的类文件中,然后在不同测试中需要时访问这些类。举个例子,你可以这样设置你的浏览器设置和打开url的方法。
`公共类浏览器{
static WebDriver driver;
public static WebDriver launchApp(String browser, String URL) {
if (browser.equals("firefox")) {
driver = new FirefoxDriver();
}
else if (browser.equals("chrome")) {
driver = new ChromeDriver();
driver.navigate().to(URL);
}else if (browser.equals("ie")){
System.setProperty("webdriver.ie.driver", "C:\\Softwares\\Drivers\\"+"IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.navigate().to(URL);
}
return driver;
}}`
并创建一个单独的类来调用这些浏览器并运行测试。
`public class testGoogleSearch {
@Test
public void testLaunchApp() {
WebDriver driver = Browser.launchApp("chrome","https://www.google.com");
System.out.println("search something");
driver.findElement(By.id("lst-ib")).sendKeys("Selenium");
driver.findElement(By.name("btnK")).click();
}}`
祝你好运!
https://stackoverflow.com/questions/50762548
复制相似问题