allure-framework / allure2

Allure Report is a flexible, lightweight multi-language test reporting tool. It provides clear graphical reports and allows everyone involved in the development process to extract the maximum of information from the everyday testing process
https://allurereport.org/
Apache License 2.0
4.18k stars 706 forks source link

Aspect annotation not intercepted by allure #948

Closed amrsa1 closed 9 months ago

amrsa1 commented 5 years ago

Screen Shot 2019-05-15 at 12 37 51 PM im trying to attach steps and screenshot to my allure report but no use, im using testng and aspectj plugin, however parameters in testng.xml file are appearing normally

but screenshot and steps are not

here is mu build.gradle

`plugins { id 'java' id 'ru.vyarus.quality' version '2.2.0' id "io.qameta.allure" version "2.7.0" }

apply plugin: "java-gradle-plugin" apply plugin: "com.gradle.plugin-publish" apply plugin: 'java' apply plugin: 'idea' apply plugin: "io.qameta.allure"

gradlePlugin { plugins { aspectjBase { id = "io.freefair.aspectj.base" implementationClass = "io.freefair.gradle.plugins.AspectJBasePlugin" } aspectjPostCompileWeaving { id = "io.freefair.aspectj.post-compile-weaving" implementationClass = "io.freefair.gradle.plugins.AspectJPostCompileWeavingPlugin" } aspectjCompileTimeWeaving { id = "io.freefair.aspectj.compile-time-weaving" implementationClass = "io.freefair.gradle.plugins.AspectJCompileTimeWeavingPlugin" }

}

}

pluginBundle { tags = ['aspectj']

plugins {
    aspectjBase {
        displayName = "AspectJ Base Plugin"
        description = "AspectJ Base Plugin"
    }
    aspectjPostCompileWeaving {
        displayName = "AspectJ Post-Compile Weaving Plugin"
        description = "AspectJ Weaving Plugin"
    }
    aspectjCompileTimeWeaving {
        displayName = "AspectJ Compile-Time Weaving Plugin"
        description = "AspectJ Weaving Plugin"
    }
}

}

group = 'newProject' version = '1.0-SNAPSHOT'

description = "Appium automation test"

sourceCompatibility = 1.8 targetCompatibility = 1.8 tasks.withType(JavaCompile) { options.encoding = 'UTF-8' }

configurations { agent }

test.doFirst { jvmArgs "-javaagent:${configurations.agent.singleFile}" }

dependencies { testImplementation 'junit:junit:4.12' implementation group: 'org.aspectj', name: 'aspectjweaver', version: '1.9.4' implementation group: 'org.aspectj', name: 'aspectjrt', version: '1.9.4' implementation group: 'org.aspectj', name: 'aspectjtools', version: '1.9.4' agent "org.aspectj:aspectjweaver:1.9.4" compile group: 'org.testng', name: 'testng', version: '6.14.3' compile group: 'io.appium', name: 'java-client', version: '7.0.0' testImplementation group: 'org.slf4j', name: 'slf4j-nop', version: '1.7.26' compile group: 'ru.yandex.qatools.ashot', name: 'ashot', version: '1.5.4' compile group: 'io.qameta.allure', name: 'allure-testng', version: '2.11.0' implementation group: 'io.qameta.allure', name: 'allure-junit4', version: '2.11.0' compileClasspath "io.qameta.allure:allure-gradle:2.7.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' }

test { useTestNG() { scanForTestClasses = false suites 'src/testng.xml' ignoreFailures = true } testLogging { events "PASSED", "STARTED", "FAILED", "SKIPPED" } systemProperty 'env', System.getProperty('env', 'all') }

allure { autoconfigure = true version = '2.7' useTestNG { version = '2.11.0' } }

idea { module { downloadJavadoc = true downloadSources = true } }

`

`// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript { repositories { google() jcenter() maven { url "https://plugins.gradle.org/m2/" }

}

dependencies {
    classpath 'com.android.tools.build:gradle:3.4.0'
    classpath "com.gradle.publish:plugin-publish-plugin:0.10.0"
    classpath "io.freefair.gradle:aspectj-plugin:3.5.1"

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

}

allprojects { repositories { google() jcenter()

}

}

task clean(type: Delete) { delete rootProject.buildDir } `

tesntng xml in that attached screenshot

TestListener class

`package Tests.listener; import org.apache.commons.io.FileUtils; import org.aspectj.lang.annotation.Aspect; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.testng.ITestContext; import org.testng.ITestListener; import org.testng.ITestResult; import org.testng.annotations.Listeners;

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;

@Aspect @Listeners public class TestListener extends LandingPageTest implements ITestListener {

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

@Attachment(value = "{0}", type = "text/html")
public static String attachHtml(String html) {
    return html;
}

@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")+"//build//allure-results//"+fileName+".png"));

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

}
@Attachment(value = "Page screenshot", type = "image/png")
private 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) {
        saveScreenshotPNG(driver);
        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) {}

}



test class

`package Tests;

import org.aspectj.lang.annotation.Aspect;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

import java.io.IOException;

import Configuration.BaseSetup;
import Pages.LandingPage;
import io.qameta.allure.Description;
import io.qameta.allure.Epic;
import io.qameta.allure.Feature;
import io.qameta.allure.Severity;
import io.qameta.allure.SeverityLevel;
import io.qameta.allure.Story;

@Listeners
@Epic("Regression Tests")
@Feature("sarajevo food dictionary")
@Severity(SeverityLevel.BLOCKER)
public class LandingPageTest extends BaseSetup {

    @Test(priority = 1 , description = "Verify user can use tourist mode")
    @Description("Application will be rest and user will select tourist mode")
    @Story("user should be able to log in as tourist")
    public  void Verify_user_can_use_tourist_mode() throws IOException {
        LandingPage page = new LandingPage(driver);
        page.sign_as_Tourist();
    }

    @Test (priority = 2 , description = "Verify user can use local mode")
    @Description("Application will be rest and user will select local mode")
    @Story("user should be able to log in as local")
    public  void Verify_user_can_use_local_mode() {
        LandingPage page = new LandingPage(driver);
        page.sign_as_Local();
    }

}
`

**page class**

`package Pages;

import org.aspectj.lang.annotation.Aspect;
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.Assert;
import org.testng.annotations.Listeners;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;

import Configuration.BaseSetup;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.pagefactory.AndroidFindBy;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import io.qameta.allure.Step;

@Aspect
@Listeners
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;

    @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);

    }
}`
Lewka commented 5 years ago

@Amrkamel1 plz format you message, it's just impossible to read. And also, would be nice if you could provide small git project where this error occurs.

baev commented 9 months ago

Closed as stale. Please create a GitHub discussion if the feature is still needed.