Module 20 -Video 6 and 7. Testng is skipping test | Selenium Forum
M
Posted on 05/10/2015
Hi all,
I am stuck badly and cannot seem to move forward at all. When I run my tests in batch using TestNG xml it skips some tests. I using Framework and following Ashish's instruction word by word (or so I think-may be). But somehow I do not see the same result. For instance I have following code.

TCID Description Runmode Results
TestCase_A1 xxxxxxxxxx Y
TestCase_A2 xxxxxxxxxx Y

//Code for TestCaseA2
public class TestCase_A2 extends TestSuiteBase{


@BeforeTest(alwaysRun = true)
public void testcheckSkip(){

if(!(TestUtil.isTestCaseRunnable(suiteAXls, this.getClass().getSimpleName()))){
APP_LOGS.debug("Skipping test because runMode is set to N");
throw new SkipException("Skipping test because runMode is set to N");
}
}


@Test
public void testCaseA2(){
System.out.println("testCaseA2");
}

}

When I run bath it skips A2 but as you can see above runmode is set to Y. Is there anyone else who has seen this issue or got stuck? Please help. I can provide more information if you need. I really need to move forward on this but cant seems to without solving this issue. Thanks in advance.

M
Replied on 05/10/2015

Hi Ashish,

Can you please help on my question above? I will really appreciate

Thanks,


M
Replied on 05/10/2015

To further Clarify my question. Here is my scenario. I have 3 tests suites in my framwork:
A Suite (It has TestCase_A1 and TestCase_A2)
B Suite (It has TestCase_B1 and TestCase_B2)
C Suite (It has TestCase_C1 and TestCase_C2)

I have 4 xlsx files Suite.xlsx, A Suite.xlsx, B Suite xlsx and C suite.xlsx files . These excel file define Runmodes (Yes or No).

On top I have TestBase class which initializes config files, logs and Xlsx files. Then for each suite I have TestSuiteBase classes which extends TestBase class and then for each test case I have for example classes such as TestClass_A1.java which extend TestSuiteBase. Please see code below:

//TestBase class code:

public class TestBase {

public static Logger APP_LOGS=null; //Import from org.apache.log4j. We will use the logger object below
public static Properties CONFIG = null;
public static Properties OR=null;
public static Xls_Reader suiteXls=null;
public static Xls_Reader suiteAXls=null;
public static Xls_Reader suiteBXls=null;
public static Xls_Reader suiteCXls=null;
public static boolean isInitialized=false;


// initializing the Tests
public void initialize() throws Exception{
// logs
if(!isInitialized){
APP_LOGS = Logger.getLogger("devpinoyLogger");
// config
APP_LOGS.debug("Loading Property files");
CONFIG = new Properties();
FileInputStream ip = new FileInputStream(System.getProperty("user.dir")+"//src//com//maximus//config/config.properties");
CONFIG.load(ip);

OR = new Properties();
ip = new FileInputStream(System.getProperty("user.dir")+"//src//com//maximus//config/OR.properties");
OR.load(ip);
APP_LOGS.debug("Loaded Property files successfully");
APP_LOGS.debug("Loading XLS Files");
ip.close();
// xls file
suiteAXls = new Xls_Reader(System.getProperty("user.dir")+"//src//com//maximus//xls//A suite.xlsx");
suiteBXls = new Xls_Reader(System.getProperty("user.dir")+"//src//com//maximus//xls//B suite.xlsx");
suiteCXls = new Xls_Reader(System.getProperty("user.dir")+"//src//com//maximus//xls//C suite.xlsx");
suiteXls = new Xls_Reader(System.getProperty("user.dir")+"//src//com//maximus//xls//Suite.xlsx");
APP_LOGS.debug("Loaded XLS Files successfully");
isInitialized=true;


}
// selenium RC/ Webdriver


}

//TestSuiteBase class code - This is for TestSuite base class for A suite (which has 2 test TestCase_A1 and TestCase_A2).

public class TestSuiteBase extends TestBase{

//Check if the execution of test case has to be skipped or not

@BeforeSuite
public void checkSuiteSkip() throws Exception{
initialize();
APP_LOGS.debug("Checking runmode of Suite A");
if(!TestUtil.isSuiteRunnable(suiteXls, "A Suite")){
APP_LOGS.debug("Skipped Suite A because runmode of Suite A was set to N");
throw new SkipException("Runmode of Suite A is set to No. So skipping all tests in Suite A");

}


}
}

//Code for TestCase_A1

public class TestCase_A1 extends TestSuiteBase{

@BeforeTest
public void checkTestSkip(){

if(!TestUtil.isTestCaseRunnable(suiteAXls, this.getClass().getSimpleName())){
APP_LOGS.debug("Skipping test case "+this.getClass().getSimpleName()+" as runmode was set to No");
throw new SkipException("Skipping test case "+this.getClass().getSimpleName()+" as runmode was set to No");

}
}

@Test
public void testCaseA1(){
System.out.println("testCaseA1");
}

}

//Code for TestCase_A2

public class TestCase_A2 extends TestSuiteBase{


@BeforeTest
public void checkTestSkip(){

if(!TestUtil.isTestCaseRunnable(suiteAXls, this.getClass().getSimpleName())){
APP_LOGS.debug("Skipping test case "+this.getClass().getSimpleName()+" as runmode was set to No");
throw new SkipException("Skipping test case "+this.getClass().getSimpleName()+" as runmode was set to No");

}
}


@Test
public void testCaseA2(){
System.out.println("testCaseA2");
}

}

//My TestNG xml file:
<suite name="My suite">


<suite-files>
<suite-file path="./Suite_A.xml" />
<suite-file path="./Suite_B.xml" />
<suite-file path="./Suite_C.xml" />

</suite-files>
</suite>

Question and issue: Lets say all runmodes in all files are set to Y (Yes) .Even then when I run my TestNG xml file (Run as TestNG suite) It skips tests. For the life of me I am not able to figure out why it is skipping test A2 in above example. My runmode is Y. Does it have something to do with throw new SkipException("fedfwe"). Please help.

The output is:

[TestNG] Running:
C:\Selenium_Framwork\Core_Framework_TestNG\Suite_A.xml

testCaseA1

===============================================
Suite A
Total tests run: 2, Failures: 0, Skips: 1
Configuration Failures: 0, Skips: 1
===============================================

[TestNG] Running:
C:\Selenium_Framwork\Core_Framework_TestNG\Suite_B.xml

testCaseB1

===============================================
Suite B
Total tests run: 2, Failures: 0, Skips: 1
Configuration Failures: 0, Skips: 1
===============================================

[TestNG] Running:
C:\Selenium_Framwork\Core_Framework_TestNG\Suite_C.xml

testCaseC1

===============================================
Suite C
Total tests run: 2, Failures: 0, Skips: 1
Configuration Failures: 0, Skips: 1
===============================================

[TestNG] Running:
C:\Selenium_Framwork\Core_Framework_TestNG\testng.xml


===============================================
My suite
Total tests run: 6, Failures: 0, Skips: 3
Configuration Failures: 0, Skips: 3
===============================================

Please help. Thanks again


M
Replied on 06/10/2015

in your selenium_pack.zip there are number of different projects. try to compare one of them with your project.

or

you have to debug the project by eclipse and go through it step by step.


M
Replied on 06/10/2015

Hi,
Thats exactly what I have been doing. Is there any other suggestion.

Can you please tell that in TestSuiteBase under @BeforeSuite or @BeforeTest can I use anything else to ignore test cases other than "Throw new SkipException("")?

I think this is what screwing up my test cases.

Thanks,