我正在尝试编写用于在两个浏览器和Chrome浏览器上进行测试的代码,两个浏览器都已打开但是URL没有被传递。
需要帮助才能进一步开展工作,谢谢。
WebDriver driver;
@BeforeTest
@Parameters("browser")
public void setup(String browser) throws Exception {
if (browser.equalsIgnoreCase("firefox")) {
driver = new FirefoxDriver();
driver.manage().window().maximize();
} else if (browser.equalsIgnoreCase("chrome")) {
System.setProperty("webdriver.chrome.driver", "E:\\disha.shah/myWork/eclipse/chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
} else {
throw new Exception("Browser is not correct");
}
// driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@Test
@Parameters({ "username", "password" })
public void login(String username, String password) throws InterruptedException {
driver.get("url goes here");
driver.findElement(By.id("UserName")).sendKeys(username);
driver.findElement(By.id("Password")).sendKeys(password);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.id("btnLogin")).sendKeys(Keys.RETURN);
}
}
这是XML文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Sample Test Suite" verbose="3" thread-count="2"
parallel="methods">
<test name="ChromeTest">
<parameter name="browser" value="Chrome" />
<classes>
<class name="testngDemo.Login">
<methods>
<include name="setup"></include>
</methods>
</class>
</classes>
</test>
<test name="FirefoxTest">
<parameter name="browser" value="Firefox" />
<classes>
<class name="testngDemo.Login">
<methods>
<include name="setup"></include>
</methods>
</class>
</classes>
</test>
<test name="Login Test">
<parameter name="username" value="dishashah" />
<parameter name="password" value="disha1234" />
<classes>
<class name="testngDemo.Login">
<methods>
<include name="login"></include>
</methods>
</class>
</classes>
</test>
</suite>