allure2: Unable to attach steps and screenshot

im using allure with testng in android studio and trying to attach screenshot that im getting from appium driver but it doesn’t want to appear in the allure report, how the screenshot is generated in the desired directory with allure report folder

this is my code

`package Tests.listener; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.testng.ITestContext; import org.testng.ITestListener; import org.testng.ITestResult;

import java.io.File; import java.io.IOException;

import java.text.SimpleDateFormat; import java.util.Date;

import Tests.LandingPageTest;

import io.appium.java_client.android.AndroidDriver;

import io.qameta.allure.Attachment;

public class TestListener extends LandingPageTest implements ITestListener {

@Attachment(value = "{0}", type = "text/plain")
private static String saveTextLog(String message) {
    return message;
}

@Attachment(value = "Page screenshot", type = "image/png")
private static File screenshot (AndroidDriver driver) throws IOException  {
    SimpleDateFormat sdf = new SimpleDateFormat("dd_MM_yyyy_hh_mm_ss");
    Date date = new Date();
    String fileName = sdf.format(date);
    File SrcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(SrcFile, new File(System.getProperty("user.dir")+"//allure-results//"+fileName+".png"));

// System.out.println(“Screenshot is captured”); return SrcFile;

}

// @Attachment(value = “Page screenshot”, type = “image/png”) // public byte[] saveScreenshotPNG(AndroidDriver driver) { // return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES); // }

@Override
public void onTestStart(ITestResult iTestResult) {}

@Override
public void onTestSuccess(ITestResult iTestResult) {}

@Override
public void onTestFailure(ITestResult iTestResult)  {
    if (driver != null) {
        System.out.println("Screenshot captured for test case");
        try {
            screenshot(driver);
        } catch (IOException e) {
            e.printStackTrace();
        }
        saveTextLog("failed and screenshot taken!");
    }

}



@Override
public void onTestSkipped(ITestResult iTestResult) {}

@Override
public void onTestFailedButWithinSuccessPercentage(ITestResult iTestResult) {}

@Override
public void onStart(ITestContext iTestContext) {}

@Override
public void onFinish(ITestContext iTestContext) {}

} `

`package Tests;

import org.testng.annotations.Listeners; import org.testng.annotations.Test;

import java.io.IOException;

import Configuration.BaseSetup; import Pages.LandingPage; import Tests.listener.TestListener; import io.qameta.allure.Description; import io.qameta.allure.Story;

@Listeners(TestListener.class) public class HomePageTest extends BaseSetup {

@Test(priority = 1)
@Story("SECOND TEST SUITE 1")
@Description("Application will be rest and user will select tourist mode")
public  void Verify_user_can_use_tourist_mode() throws IOException {
    LandingPage page = new LandingPage(driver);
    page.sign_as_Tourist();
}

@Test(priority = 2)
@Story("SECOND TEST SUITE")
@Description("Application will be rest and user will select local mode")
public  void Verify_user_can_use_local_mode() {
    LandingPage page = new LandingPage(driver);
    page.sign_as_Local();
}

} `

`package Pages;

import org.apache.commons.io.FileUtils; import org.junit.Assert; import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.annotations.Listeners; import org.testng.annotations.Parameters;

import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.concurrent.TimeUnit;

import Configuration.BaseSetup; import Tests.listener.TestListener; import io.appium.java_client.MobileElement; import io.appium.java_client.TouchAction; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.functions.ExpectedCondition; import io.appium.java_client.pagefactory.AndroidFindBy; import io.appium.java_client.pagefactory.AppiumFieldDecorator; import io.appium.java_client.touch.offset.ElementOption; import io.qameta.allure.Attachment; import io.qameta.allure.Step;

import static io.appium.java_client.touch.LongPressOptions.longPressOptions; import static io.appium.java_client.touch.offset.ElementOption.element; @Listeners({TestListener.class}) public class LandingPage extends BaseSetup {

protected AndroidDriver driver;
protected WebDriverWait wait;


public LandingPage(AndroidDriver driver ) {
    this.driver = driver;
    wait = new WebDriverWait(driver, 15);
    PageFactory.initElements(new AppiumFieldDecorator(driver), this);
}


@AndroidFindBy(uiAutomator = "new UiSelector().text(\"Visit your favourite venue or discover a new place\")")
private WebElement introText;

@AndroidFindBy(xpath = "//android.widget.TextView[contains(@text, 'Next')]")
private MobileElement nextButton;

@AndroidFindBy(xpath = "//android.widget.TextView[contains(@text, 'Skip')]")
private MobileElement skipButton;

@AndroidFindBy(uiAutomator = "new UiSelector().text(\"Tourist\")")
private  MobileElement touristMode;

@AndroidFindBy(uiAutomator = "new UiSelector().text(\"Local\")")
private  MobileElement localMode;

@AndroidFindBy(xpath = "//android.widget.TextView[contains(@text, 'Get Started')]")
private  MobileElement getStartedButton;

@AndroidFindBy(uiAutomator = "new UiSelector().text(\"PLACES NEARBY\")")
private  MobileElement placesnearby;

@AndroidFindBy(xpath = "//android.widget.EditText[contains(@text, 'Search')]")
private  MobileElement searchField;

@AndroidFindBy(className = "android.widget.ImageView")    //INDEX 2
private List <MobileElement> ringIcon;

@AndroidFindBy(className = "android.widget.ImageView")    //INDEX 0
private List <MobileElement> burgerMenu;

@AndroidFindBy(xpath = "//android.widget.EditText[contains(@text, 'Search')]")
private  MobileElement notificationHeader;

@AndroidFindBy(xpath = "//android.view.ViewGroup[contains(@content-desc = \"Go back\")]")
private  MobileElement goBack;

@AndroidFindBy(xpath = "//android.widget.TextView[contains(@text, 'Settings')]")
private MobileElement settings;

@AndroidFindBy(uiAutomator = "new UiSelector().text(\"Tourist\")")
private MobileElement veriTourist;

@AndroidFindBy(uiAutomator = "new UiSelector().text(\"Tourist\")")
private MobileElement veriLocal;



@Attachment
@Step("Application will start and user will navigate as tourist")
public void sign_as_Tourist () throws IOException {

    new WebDriverWait(driver,5).until(ExpectedConditions.visibilityOf(introText));
    nextButton.click();
    nextButton.click();
    nextButton.click();
    touristMode.click();
    getStartedButton.click();
    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
    burgerMenu.get(0).click();
    settings.click();
    Assert.assertEquals(veriTourist.getText(),"TourSist");

// try{ // Assert.assertEquals(veriTourist.getText(),“TouSrist”); // }catch(AssertionError e){ // System.out.println(“Tourist mode is not selected”); // screenshot(); // }

}

@Step("Application will start and user will navigate as local")
public void sign_as_Local () {

    new WebDriverWait(driver,5).until(ExpectedConditions.visibilityOf(introText));
    nextButton.click();
    nextButton.click();
    nextButton.click();
    localMode.click();
    getStartedButton.click();
    driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
    burgerMenu.get(0).click();
    settings.click();
    Assert.assertEquals(localMode.isDisplayed(),true);

}`

Dependencies

`plugins { id ‘ru.vyarus.quality’ version ‘3.4.0’ id ‘io.qameta.allure’ }

apply plugin: ‘com.android.application’ apply plugin: ‘io.qameta.allure’ //apply plugin: ‘java’ apply plugin: ‘idea’ apply plugin: ‘maven’

repositories { jcenter() google() mavenCentral() }

android { compileSdkVersion 28 defaultConfig { applicationId “com.example.demoproject” minSdkVersion 18 targetSdkVersion 28 versionCode 1 versionName “1.0” testInstrumentationRunner “android.support.test.runner.AndroidJUnitRunner” } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile(‘proguard-android-optimize.txt’), ‘proguard-rules.pro’ } } }

dependencies { implementation fileTree(dir: ‘libs’, include: [‘*.jar’]) implementation ‘com.android.support:appcompat-v7:28.0.0’ testImplementation ‘junit:junit:4.12’ // androidTestImplementation ‘com.android.support.test🏃1.0.2’ // androidTestImplementation ‘com.android.support.test.espresso:espresso-core:3.0.2’ implementation group: ‘io.appium’, name: ‘java-client’, version: ‘7.0.0’ testImplementation group: ‘org.testng’, name: ‘testng’, version: ‘6.14.3’ testImplementation group: ‘org.slf4j’, name: ‘slf4j-nop’, version: ‘1.7.26’ // implementation group: ‘org.seleniumhq.selenium’, name: ‘selenium-server-standalone’, version: ‘2.53.0’ implementation group: ‘org.seleniumhq.selenium’, name: ‘selenium-server’, version: ‘3.141.59’ implementation group: ‘org.seleniumhq.selenium’, name: ‘selenium-java’, version: ‘3.141.59’ implementation group: ‘org.seleniumhq.selenium’, name: ‘selenium-remote-driver’, version: ‘3.141.59’ testImplementation group: ‘io.qameta.allure’, name: ‘allure-testng’, version: ‘2.11.0’ testImplementation group: ‘org.aspectj’, name: ‘aspectjweaver’, version: ‘1.9.3’ implementation group: ‘io.qameta.allure’, name: ‘allure-generator’, version: ‘2.11.0’ implementation group: ‘io.qameta.allure’, name: ‘allure-java-commons’, version: ‘2.11.0’ implementation group: ‘com.relevantcodes’, name: ‘extentreports’, version: ‘2.41.2’ implementation group: ‘ru.yandex.qatools.ashot’, name: ‘ashot’, version: ‘1.5.4’ implementation group: ‘commons-io’, name: ‘commons-io’, version: ‘2.6’ implementation group: ‘org.apache.commons’, name: ‘commons-lang3’, version: ‘3.9’

}

idea { module { downloadJavadoc = true downloadSources = true }

} `

testng file Screen Shot 2019-05-12 at 7 07 46 PM

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 36 (17 by maintainers)

Most upvoted comments

@Amrkamel1 Did you try this?

import io.qameta.allure.Allure;

Allure.addAttachment(nameTest, new ByteArrayInputStream(((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES)));

@fescobar Yes it seems some issue was with my allure.properties I put in wrong directory

Thx

@fescobar im encountering a new issue after updating some plugins version this is my currrent POM and whenever im running mvn clean mvn site mvn test i didnt get allure-report folder in target as before it was working fine

here is the POM

4.0.0

<groupId>MobileAutomationTest</groupId>
<artifactId>App</artifactId>
<version>1.0-SNAPSHOT</version>


<properties>
    <jre.level>1.8</jre.level>
    <jdk.level>1.8</jdk.level>
    <aspectj.version>1.9.5</aspectj.version>
</properties>

<build>
    <plugins>
        <!-- Compiler plug-in -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>${jdk.level}</source>
                <target>${jdk.level}</target>
            </configuration>
        </plugin>
        <!-- Added Surefire Plugin configuration to execute tests -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M4</version>
            <configuration>
                <testFailureIgnore>true</testFailureIgnore>
                <argLine>
                    -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                </argLine>
                <suiteXmlFiles>
                    <suiteXmlFile>src/test/java/TestNG.xml/</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjweaver</artifactId>
                    <version>${aspectj.version}</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

<dependencies>
    <!-- https://mvnrepository.com/artifact/org.testng/testng -->
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>7.1.0</version>
    </dependency>
    <!--https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server-->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-server</artifactId>
        <version>3.141.59</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.appium/java-client -->
    <dependency>
        <groupId>io.appium</groupId>
        <artifactId>java-client</artifactId>
        <version>7.3.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/junit/junit -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.13</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.relevantcodes/extentreports -->
    <dependency>
        <groupId>com.relevantcodes</groupId>
        <artifactId>extentreports</artifactId>
        <version>2.41.2</version>
    </dependency>
    <!-- log4j2 -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.29</version>
    </dependency>
</dependencies>
<reporting>
    <excludeDefaults>true</excludeDefaults>
    <plugins>
        <plugin>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-maven</artifactId>
            <version>2.10.0</version>
            <configuration>
                <reportDirectory>${basedir}\target\allure-report</reportDirectory>
            </configuration>
        </plugin>
    </plugins>
</reporting>

image

Did you fix it?