Module 9-I have 2 questions related to testng | Selenium Forum
M
Posted on 14/08/2016
Ques1: My testng.xml file display as below(please see screen shot), how can I make it the way you have shown in video?

Quest2: When there is only one test case and if I use @BeforeSuite and @AfterSuite annotations.. @Aftersuite part is not there in output (used below code)

package package1;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class SampleTest {

@BeforeSuite
public void verystart(){
System.out.println("this is before suit");
}

@AfterSuite
public void veryend(){
System.out.println("this is after suit");
}

@BeforeTest
public void start(){
System.out.println("this is befortest execution");
}
@AfterTest
public void End(){
System.out.println("this is aftertest execution");
}

@BeforeMethod
public void openbrowser()
{
System.out.println("opening browser-before each method");
}

@AfterMethod
public void closebrowser()
{
System.out.println("closing browser-after each method");
}


@Test
public void test1(){
System.out.println("this is test1 execution");
}

@Test
public void test2(){
System.out.println("This is test2 execution");
}

}


[color=#FF0000:2owvl0ql]Output:[/color:2owvl0ql]

[TestNG] Running:
C:\Users\Dell\AppData\Local\Temp\testng-eclipse--13879346\testng-customsuite.xml

this is before suit
this is befortest execution
opening browser-before each method
this is test1 execution
closing browser-after each method
opening browser-before each method
This is test2 execution
closing browser-after each method
this is aftertest execution
[Utils] Attempting to create D:\JavaPrograms\TestNgLearn\test-output\Default suite\Default test.xml
[Utils] Directory D:\JavaPrograms\TestNgLearn\test-output\Default suite exists: true
PASSED: test1
PASSED: test2

M
Replied on 16/08/2016

click on source
[attachment=0:14lqukvy]Capture.PNG[/attachment:14lqukvy]

@aftersuite is executed after the entire test.

Responsive image