Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
250 views
in Technique[技术] by (71.8m points)

How to use TestNg in Selenium WebDriver?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Hi TestNG can be defined as

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.For official TestNG documentation Please Click Here

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 this or this or simply go to Help/Eclipse MarketPlace. under Find type Test NG and click on the install

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 

}

Some information for above code

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...