使用TestNG

时间:2015-11-13 05:50:27

标签: selenium-webdriver testng

我对selenium很新,并试图在eclipse中创建一个测试脚本。当使用TestNG执行类时,抛出testngexception。有人可以检查我写的脚本是否有问题?

package first_package;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class Test_Class_Automation {

    @Test
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        WebDriver driver = new FirefoxDriver();
        driver.manage().window().maximize();
        driver.get("https://www.google.lk");
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        driver.close();
    }
}

1 个答案:

答案 0 :(得分:1)

如果您正在使用testng注释,那么您不需要在那里编写main方法。你可以用这种方式写它: package first_package;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class Test_Class_Automation {

    @Test
    public void testCase {
        // TODO Auto-generated method stub
        WebDriver driver = new FirefoxDriver();
        driver.manage().window().maximize();
        driver.get("https://www.google.lk");
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        driver.close();
    }
  }