如何在Selenium WebDriver中使用TestNg?

时间:2016-06-02 10:44:27

标签: selenium selenium-webdriver

如何在Selenium WebDriver中使用TestNg?解释一下这是什么用法。 我是Selenium WebDriver的新学员

2 个答案:

答案 0 :(得分:1)

硒的主要用途之一是测试ui功能,作为测试框架,testNg有许多运行和报告测试的技术,可以利用硒进行ui测试。有效使用它的工具之一是selion(https://github.com/paypal/selion)。

答案 1 :(得分:1)

您好 TestNG 可以定义为

1。TestNG is a testing framework designed to simplify a broad range of testing needs, from unit testing (testing a class in isolation of the others) to integration testing (testing entire systems made of several classes, several packages and even several external frameworks, such as application servers).

2.对于官方TestNG文档Please Click Here

在你将TestNG与selenium一起使用之前,你必须先安装它。考虑到你正在使用eclipse(任何版本)

1. There are various ways to install TestNG either follow thisthis or simply go to Help/Eclipse MarketPlace. under Find type Test NG and click on the install

现在如何在日食中使用硒测试NG

@BeforeTest
    public void TearUP(){
        // preconditions for sample test 
        // like browser start with specific URL
    }


@Test
    public void SampleTest(){
        // code for the main test case goes inside
    }

@AfterTest
public void TearDown1(){
    // thing to done after test is run
    // like memory realese 
    // browser close 

}

以上代码的一些信息

  1. TestNG有关于注释的更多信息的各种注释转到上面的链接

    @BeforeSuite:在此套件中的所有测试运行之前,将运行带注释的方法。

    @AfterSuite: The annotated method will be run after all tests in this suite have run. 
    @BeforeTest: The annotated method will be run before any test method belonging to the classes inside the <test> tag is run. 
    @AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the <test> tag have run. 
    @BeforeGroups: The list of groups that this configuration method will run before. This method is guaranteed to run shortly before the first test method that belongs to any of these groups is invoked. 
    @AfterGroups: The list of groups that this configuration method will run after. This method is guaranteed to run shortly after the last test method that belongs to any of these groups is invoked. 
    @BeforeClass: The annotated method will be run before the first test method in the current class is invoked. 
    @AfterClass: The annotated method will be run after all the test methods in the current class have been run. 
    @BeforeMethod: The annotated method will be run before each test method. 
    @AfterMethod: The annotated method will be run after each test method.