Module 20 [Soft Assertion] | Selenium Forum
M
Posted on 03/09/2016
Hi Ashish,
I am trying to do soft assertion as show in video but problem is that control is not move onto @AfterMethod (I investigate it through debug the code) due to that it if my softAssert is fail it not generate the reports. so please suggest i am doing any mistake over it?

[b:2cej6pta][u:2cej6pta]Project and ScreenShot Attached[/u:2cej6pta][/b:2cej6pta]


[b:2cej6pta]Stack Trace :-[/b:2cej6pta]

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

log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
FAILED CONFIGURATION: @AfterMethod Quit
java.lang.AssertionError: The following asserts failed:
E1 expected [true] but found [false],
E2 expected [true] but found [false],
E3 expected [true] but found [false]
at org.testng.asserts.SoftAssert.assertAll(SoftAssert.java:43)
at ddf.testCases.DummyTestB.Quit(DummyTestB.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:707)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:152)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:57)

PASSED: testB

===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
Configuration Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
Configuration Failures: 1, Skips: 0
===============================================

[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@60f82f98: 46 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@7a5d012c: 38 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@edf4efb: 96 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@3d8c7aca: 21 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 3 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@6b2fad11: 6 ms

M
Replied on 03/09/2016

what is in @AfterMethod? send a screen shot.


M
Replied on 03/09/2016

Please refer attached screenshot of @AfterMethod.

Responsive image

M
Replied on 05/09/2016

Please suggest i am waiting for your reply.


M
Replied on 05/09/2016

yeah, wait for sometime i'm on call with some other person.


M
Replied on 05/09/2016

put [color=#FF0000:26123vzb]softAssert.AssertAll();[/color:26123vzb]
at the the end @Test.

it will fail the test and move on to @AfterMethod.
or
it will pass the test and move on to @AfterMethod.

either way it will be shown in extent report.


M
Replied on 05/09/2016

Sorry, I am not getting you. [b:1523obe0]As you say "put softAssert.AssertAll();
at the the end @Test."[/b:1523obe0]---- I already put softAssert.AssertAll(); at the end of @Test in my code. but still Reports are not generate.


[b:1523obe0]Code :[/b:1523obe0]-

package ddf.testCases;
import java.io.IOException;
import java.util.Hashtable;

import org.testng.SkipException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;

import com.relevantcodes.extentreports.LogStatus;
import ddf.baseTest.BaseTest;

public class DummyTestB extends BaseTest {

//String testCaseName ="TestA";
SoftAssert softAssert;



@Test(dataProvider="Excel_Datprovider")
public void testB(Hashtable<String, String> data) throws IOException{
softAssert=new SoftAssert();
test= rep.startTest("DummyTestB");
test.log(LogStatus.INFO, "Starting the Test,TestB");

/* if(data.get("RunMode").equals("N")){
test.log(LogStatus.SKIP, "Skipping the Test as RunMode is N");
throw new SkipException("Skipping the Test as RunMode is N");
}*/

openBrowser("Mozilla");
test.log(LogStatus.INFO, "Open the browser");
navigate("appUrl");


//Verify signin text on the page

/*if(!verifyTitle("signtitleText_xpath","signinText"))
softAssertion.assertTrue(false, "Title is not matched");*/

softAssert.assertTrue(false, "E1");
softAssert.assertTrue(false, "E2");
softAssert.assertTrue(false, "E3");
softAssert.assertTrue(true, "Test is pass");


//Check that if EmailId is not present
if(!isElementPresent("email_xpath"))
reportFailure("Element is not present");

type("email_id","sambhasin4@gmail.com");
click("btn_Click_xpath");

takeScreenshot();

}

[b:1523obe0]@AfterMethod
public void Quit(){

try{
softAssert.assertAll();
}catch(Exception e){
test.log(LogStatus.FAIL, e.getMessage());
}
rep.endTest(test);
rep.flush();
[/b:1523obe0]
}

@DataProvider
public Object [][]Excel_Datprovider(){

xl = new Xls_Reader("D:\\Data.xlsx");
String testCaseName ="TestB";

String sheetName="Data";


int TestcaseExecuteRowNumber = 1;
while (!xl.getCellData(sheetName, 0, TestcaseExecuteRowNumber).equals(testCaseName))
{
TestcaseExecuteRowNumber++;
}

System.out.println("TestCase is start from -- " +TestcaseExecuteRowNumber);

int colStartRowNumber= TestcaseExecuteRowNumber+1;
int dataStartRowNumber= TestcaseExecuteRowNumber+2;

//Calculate rows of Executed data

int rows=0;
while (!xl.getCellData(sheetName, 0, dataStartRowNumber+rows).equals("")){
rows++;
}
System.out.println("Total row for execution of data are -- " +rows);

//Calculate cols of Executed data

int cols=0;
while(!xl.getCellData(sheetName, cols, colStartRowNumber).equals("")){
cols++;
}
System.out.println("Total columns of exected data are -- " +cols);

//Read the data

Object[][] data= new Object[rows][1];
int rowsCount=0;
Hashtable<String, String> table=null;
for(int rNum=dataStartRowNumber;rNum<dataStartRowNumber+rows;rNum++){
table=new Hashtable<String,String>();
for(int cNum=0;cNum<cols;cNum++){
String key= xl.getCellData(sheetName, cNum, colStartRowNumber);
String value=xl.getCellData(sheetName, cNum, rNum);
table.put(key, value);
}
data[rowsCount][0]= table;
rowsCount++;
}
return data;
}

}


M
Replied on 05/09/2016

[code:1i56ik3h]@Test(dataProvider="Excel_Datprovider")
public void testB(Hashtable<String, String> data) throws IOException{
softAssert=new SoftAssert();
test= rep.startTest("DummyTestB");
test.log(LogStatus.INFO, "Starting the Test,TestB");

/* if(data.get("RunMode").equals("N")){
test.log(LogStatus.SKIP, "Skipping the Test as RunMode is N");
throw new SkipException("Skipping the Test as RunMode is N");
}*/

openBrowser("Mozilla");
test.log(LogStatus.INFO, "Open the browser");
navigate("appUrl");


//Verify signin text on the page

/*if(!verifyTitle("signtitleText_xpath","signinText"))
softAssertion.assertTrue(false, "Title is not matched");*/

softAssert.assertTrue(false, "E1");
softAssert.assertTrue(false, "E2");
softAssert.assertTrue(false, "E3");
softAssert.assertTrue(true, "Test is pass");


//Check that if EmailId is not present
if(!isElementPresent("email_xpath"))
reportFailure("Element is not present");

type("email_id","sambhasin4@gmail.com");
click("btn_Click_xpath");

takeScreenshot();
softAssert.assertAll();

}

@AfterMethod
public void Quit(){
rep.endTest(test);
rep.flush();

}
[/code:1i56ik3h]