虽然测试是一个接一个地执行但是最初启动了两个chromes而不是一个接一个。 我的java代码
package dOUBT;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class TEST {
WebDriver driver = new ChromeDriver();
@Parameters({ "URL"})
@Test()
public void login(String URL) {
try {
driver.get(URL);
System.out.println("Website opened");
} catch (Exception e) {
e.printStackTrace();
}} }
下面是我的testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite1">
<test name="GOOGLESmoke1">
<parameter name="URL" value="http://google.com"/>
<classes>
<class name="dOUBT.TEST">
</class></classes>
</test>
<test name="YAHOOSmoke2">
<parameter name="URL" value="http://yahoo.com"/>
<classes>
<class name="dOUBT.TEST">
</class></classes>
</test>
</suite>
答案 0 :(得分:1)
公共课TEST {
WebDriver driver;
@Parameters({"URL"})
@BeforeTest
public void b(String URL){
System.setProperty("webdriver.chrome.driver", "C:/Users/admin/Downloads/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get(URL);
}
@Test()
public void login() {
try {
//verification code
System.out.println("Website opened");
} catch (Exception e) {
e.printStackTrace();
}} }