我是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();
}
}
答案 0 :(得分:0)
我建议你把setProperty(),打开页面和其他常见操作放在一个单独的类文件中,然后在不同的测试中随时访问这些类。举个例子,你可以用这种方式设置浏览器设置和url打开方法。
`public class Browser {
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();
}
}`
祝你好运!!