如何在Selenium WebDriver中使用TestNg? [英] How to use TestNg in Selenium WebDriver?

查看:190
本文介绍了如何在Selenium WebDriver中使用TestNg?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Selenium WebDriver中使用TestNg?请解释一下这有什么用. 我是Selenium WebDriver的新手

How to use TestNg in Selenium WebDriver? Explain me what is the usage of that. I am new Learner in Selenium WebDriver

推荐答案

您好 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官方文档请单击此处

2.For official TestNG documentation Please Click Here

在将TestNG与硒一起使用之前,必须先安装它.考虑到您正在使用eclipse(任何版本),请先进行讨论

Before you can use TestNG with selenium you have to install it first.Talking in consideration that you are working with eclipse (any version)

1. There are various ways to install TestNG either follow 现在如何在含硒的日食中使用Test NG

now how to use Test NG in eclipse with selenium

@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具有各种注释,有关注释的更多信息,请转到上面的链接

  1. TestNG have various annotations for more info on annotation go to the above link

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

@BeforeSuite: The annotated method will be run before all tests in this suite have run.

@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.

这篇关于如何在Selenium WebDriver中使用TestNg?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆