Assert.assertEquals (strng, "Scarf print");не работает для моего кода.в случае неудачи теста его первый журнал проверяет статус теста как пропущенный и запускает тот же тест снова, затем регистрирует статус теста как неудачный.Я создал тестовый слушатель, в котором я реализую ITestListener.Кто-нибудь может мне помочь
package utils.Listener;
import com.relevantcodes.extentreports.LogStatus;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;
import utility.Seleniumsetup;
import utils.ExtentReport.ExtentManager;
import utils.ExtentReport.ExtentTestManager;
public class TestListener extends Seleniumsetup implements ITestListener {
private static String getTestMethodName(ITestResult iTestResult) {
return iTestResult.getMethod().getConstructorOrMethod().getName();
}
//Before starting all tests, below method runs.
@Override
public void onStart(ITestContext iTestContext) {
System.out.println("I am in onStart method " + iTestContext.getName());
iTestContext.setAttribute("WebDriver", this.getdriver());
}
//After ending all tests, below method runs.
@Override
public void onFinish(ITestContext iTestContext) {
System.out.println("I am in onFinish method " + iTestContext.getName());
//Do tier down operations for extentreports reporting!
ExtentTestManager.endTest();
ExtentManager.getReporter().flush();
}
@Override
public void onTestStart(ITestResult iTestResult) {
System.out.println("I am in onTestStart method " + getTestMethodName(iTestResult) + " start");
//Start operation for extentreports.
ExtentTestManager.startTest(iTestResult.getMethod().getMethodName(),"");
}
@Override
public void onTestSuccess(ITestResult iTestResult) {
System.out.println("I am in onTestSuccess method " + getTestMethodName(iTestResult) + " succeed");
//Extentreports log operation for passed tests.
ExtentTestManager.getTest().log(LogStatus.PASS, "Test passed");
}
@Override
public void onTestFailure(ITestResult iTestResult) {
System.out.println("I am in onTestFailure method " + getTestMethodName(iTestResult) + " failed######" +iTestResult);
//Get driver from BaseTest and assign to local webdriver variable.
Object testClass = iTestResult.getInstance();
WebDriver webDriver = ((Seleniumsetup) testClass).getdriver();
//Take base64Screenshot screenshot.
String base64Screenshot = "data:image/png;base64,"+((TakesScreenshot)webDriver).
getScreenshotAs(OutputType.BASE64);
//Extentreports log and screenshot operations for failed tests.
ExtentTestManager.getTest().log(LogStatus.FAIL,"Test Failed",
ExtentTestManager.getTest().addBase64ScreenShot(base64Screenshot));
}
@Override
public void onTestSkipped(ITestResult iTestResult) {
System.out.println("I am in onTestSkipped method "+ getTestMethodName(iTestResult) + " skipped" +iTestResult);
//Extentreports log operation for skipped tests.
ExtentTestManager.getTest().log(LogStatus.SKIP, "Test Skipped");
}
@Override
public void onTestFailedButWithinSuccessPercentage(ITestResult iTestResult) {
System.out.println("Test failed but it is in defined success ratio " + getTestMethodName(iTestResult));
}
}
Home page method
public void opentest() throws InterruptedException
{
Newarrival.click();
waitfor(collection1);
collection1.click();
Thread.sleep(4000);
String strng=Pagecheck.getText();
System.out.println(strng);
Assert.assertEquals(strng,"Scarf print");// this is reason for skip
}
Test method
@Test (enabled = true, priority=0)
public void testcase1() throws InterruptedException
{
//ExtentTestManager.getTest().setDescription("valid Login Scenario with wrong username and password.");
homePage p= new homePage(getdriver());
p.opentest();
}
Я хочу, чтобы он запускал каждый @ тест только один раз, но он не просыпается, как ожидалось