Screenshot is taken and i can see the attachment in allure results in Eclipse. I can also see the screenshot in Allure report but upon clicking on it. It displays no image. I will be attaching the screenshot so you can see what i m experiencing
package com.IVAPP.qa.TestUtil;
import io.qameta.allure.Attachment;
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 com.IVAPP.qa.Base.BaseClass;
/**
*
* @author NaveenKhunteta
*
*/
public class TestAllureListener implements ITestListener {
private static String getTestMethodName(ITestResult iTestResult) {
return iTestResult.getMethod().getConstructorOrMethod().getName();
}
// Text attachments for Allure
@Attachment(value = "Page screenshot", type = "image/png")
public byte[] saveScreenshotPNG(WebDriver driver) {
return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
}
// Text attachments for Allure
@Attachment(value = "{0}", type = "text/plain")
public static String saveTextLog(String message) {
return message;
}
// HTML attachments for Allure
@Attachment(value = "{0}", type = "text/html")
public static String attachHtml(String html) {
return html;
}
@Override
public void onStart(ITestContext iTestContext) {
System.out.println("I am in onStart method " + iTestContext.getName());
iTestContext.setAttribute("WebDriver", BaseClass.getDriver());
}
@Override
public void onFinish(ITestContext iTestContext) {
System.out.println("I am in onFinish method " + iTestContext.getName());
}
@Override
public void onTestStart(ITestResult iTestResult) {
System.out.println("I am in onTestStart method " + getTestMethodName(iTestResult) + " start");
}
@Override
public void onTestSuccess(ITestResult iTestResult) {
System.out.println("I am in onTestSuccess method " + getTestMethodName(iTestResult) + " succeed");
}
@Override
public void onTestFailure(ITestResult iTestResult) {
System.out.println("I am in onTestFailure method " + getTestMethodName(iTestResult) + " failed");
Object testClass = iTestResult.getInstance();
WebDriver driver = BaseClass.getDriver();
// Allure ScreenShotRobot and SaveTestLog
if (driver instanceof WebDriver) {
System.out.println("Screenshot captured for test case:" + getTestMethodName(iTestResult));
saveScreenshotPNG(driver);
}
// Save a log on allure.
saveTextLog(getTestMethodName(iTestResult) + " failed and screenshot taken!");
}
Это код для добавления неудачного скриншота с использованием слушателя в верхней части тестового класса, который я выполнил. Это также напечатало бы Тест "Имя метода" Не удалось. Снимок экрана сделан. То есть печать, но не скриншот, не видно. Я вижу файл скриншота, но он ничего не отображает. при открытии его пусто
@Override
public void onTestSkipped(ITestResult iTestResult) {
System.out.println("I am in onTestSkipped method " + getTestMethodName(iTestResult) + " skipped");
}
@Override
public void onTestFailedButWithinSuccessPercentage(ITestResult iTestResult) {
System.out.println("Test failed but it is in defined success ratio " + getTestMethodName(iTestResult));
}
}
==========================================================================
//Test I m executing = LOGIN PAGE TEST
package com.IVAPP.qa.OffShoreTestCases;
import io.qameta.allure.Description;
import io.qameta.allure.Severity;
import io.qameta.allure.SeverityLevel;
import io.qameta.allure.Story;
import java.io.IOException;
import org.apache.log4j.Logger;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import com.IVAPP.qa.Base.BaseClass;
import com.IVAPP.qa.OffShorePage.HomePage;
import com.IVAPP.qa.OffShorePage.LoginPage;
import com.IVAPP.qa.TestUtil.CustomListener;
import com.IVAPP.qa.TestUtil.TestAllureListener;
import com.IVAPP.qa.TestUtil.TestUtil;
@Listeners({TestAllureListener.class})
//@Listeners(CustomListener.class)
public class LoginPageTest extends BaseClass {
LoginPage loginpage;
HomePage homePage;
TestUtil testUtil;
Logger log = Logger.getLogger(LoginPageTest.class);
//WebDriver driver;
public LoginPageTest() throws IOException{
super();
}
@BeforeMethod
public void setUp() throws IOException{
log.info("****************************** Starting Test Case Execution ******************************");
intialization();
log.info("Launching browser IE");
// String exePath = "C:\\Users\\Jomonli\\Desktop\\IEDriverServer_x64_3.14.0\\IEDriverServer.exe";
// //For use of IE only; Please enable for IE Browser
// System.setProperty("webdriver.ie.driver", exePath);
// driver = new InternetExplorerDriver();
this.loginpage =new LoginPage();
homePage = new HomePage();
}
@Test(description="Logging in with valid credentials")
@Severity(SeverityLevel.NORMAL)
@Description("Test Case Description : Verifying Login Screen in Offshore Account")
@Story("Story Name: To check Login functionality in IVAPP OffShore account")
public void LoginTest() throws IOException, InterruptedException{
log.info("****************************** Starting Test Case ******************************");
log.info("****************************** Login Test ******************************");
homePage = loginpage.login(prop.getProperty("UserID"), prop.getProperty("Password"));
log.info("****************************** Getting Data from Congfig File ******************************");
Thread.sleep(3000);
testUtil.alertAccept();
String header =driver.getTitle();
System.out.println("This the Title of the page:: " +header);
String expectedTitle = "iVAPP 2.0 - S1";
Assert.assertEquals(header, "iVAPP 2.0 - S1");
log.info("****************************** Verified Title ******************************");
log.info("****************************** Ending Test Case ******************************");
log.info("****************************** Login Test ******************************");
//testUtil.getScreenshot("LoginPage Test");
//System.out.println(driver.getTitle());
}
@Test
public void sampleTest(){
Assert.assertEquals(true, false);
}
@AfterMethod
public void teardown() throws IOExcep[enter image description here][1]tion{
driver.quit();
log.info("****************************** Browser is closed ******************************");
}
}
This is my loginpage test. I changed the credentials to make the test case fail and i also made a class with assertions mismatching so that it fails
[1]: https://i.stack.imgur.com/06K8E.png