I am not able to invoke screenshot for failure scenario:
this is my project structure:
hooks.js:
var Cucumber = require(‘cucumber’);
var fs = require(‘fs’);
var conf = require(‘../conf’).config;
var reporter = require(‘cucumber-html-reporter’);
var report = require(‘cucumber-html-report’);
var hooks = function () {
«use strict»;
var jsonReports = process.cwd() + ‘/reports/json’;
var htmlReports = process.cwd() + ‘/reports/html’;
var targetJson = jsonReports + ‘/cucumber_report.json’;
var outputDir = ‘./target/allure-results’;
this.registerHandler('BeforeFeature', { timeout: 10 * 1000 }, function (event) {
return browser.get(conf.baseUrl);
});
this.After(‘Successfully Applied Hooks’, function (scenario) {
if (scenario.isFailed()) {
browser.takeScreenshot().then(function (base64png) {
var decodedImage = new Buffer(base64png, ‘base64’).toString(‘binary’);
scenario.attach(decodedImage, ‘image/png’);
callback();
}, function (err) {
return callback(err);
});
}else{
callback();
}
});
var cucumberReportOptions = {
source: targetJson,
dest: htmlReports,
name: 'cucumber_report.html',
title: 'Cucumber Report'
}
var cucumberReporteroptions = {
theme: 'bootstrap',
jsonFile: jsonReports + '/cucumber_report.json',
output: htmlReports + '/cucumber_reporter.html',
reportSuiteAsScenarios: true
};
var JsonFormatter = Cucumber.Listener.JsonFormatter();
JsonFormatter.log = function (string) {
if (!fs.existsSync(jsonReports)) {
fs.mkdirSync(jsonReports);
}
try {
fs.writeFileSync(targetJson, string);
reporter.generate(cucumberReporteroptions); //invoke cucumber-html-reporter
report.create(cucumberReportOptions).then(function () { //invoke cucumber-html-report
// creating two reports(optional) here, cucumber-html-report gives directory already exists as cucumber-html-reporter already creates the html dir!
// suggestion- use either one of the reports based on your needs
console.log('cucumber_report.html created successfully!');
}).catch(function (err) {
if (err) {
console.error(err);
}
});
}
catch (err) {
if (err) {
console.log('Failed to save cucumber test results to json file.');
console.log(err);
}
}
};
this.registerListener(JsonFormatter);
}
module.exports = hooks;
reporter.js:
var reporter = require(‘cucumberjs-allure-reporter’);
var fs = require(‘fs’);
var xmlReports = process.cwd() + ‘/reports/xml’;
var createXmlDir = function () {
if (!fs.existsSync(xmlReports)) {
fs.mkdir(xmlReports);
}
} ();
reporter.config(
{
targetDir: ‘./target/allure-results’
}
);
module.exports = reporter;
Could you please help to sort it out.
I’m running a Selenium test with Maven and would like to have an Allure report generated in the end. Unfortunately, I get an error message.
Maven command line:
clean -Dtest=TestLogs test allure:report
Error message:
[INFO] --- allure-maven:2.9:report (default-cli) @ demo ---
[INFO] Allure installation directory C:UsersZoeDocumentsdemoselenium_testsdemo_selenium/.allure
[INFO] Try to finding out allure 2.3.1
[INFO] Generate Allure report (report) with version 2.3.1
[INFO] Generate Allure report to C:UsersZoeDocumentsdemoselenium_testsdemo_seleniumtargetsite/allure-maven-plugin
[ERROR] Directory C:UsersZoeDocumentsdemoselenium_testsdemo_seleniumtargettargetallure-results not found.
[WARNING] Allure report was skipped because there is no results directories found.
My POM.xml:
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.wesh.nc</groupId>
<artifactId>demo</artifactId>
<!--<packaging>pom</packaging>-->
<packaging>jar</packaging>
<version>1.0</version>
<properties>
<allure.version>1.5.2</allure.version>
<allure.maven.version>2.0</allure.maven.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<skip>${skip.selenium.tests}</skip>
<parallel>none</parallel>
<threadCount>1</threadCount>
<reuseForks>false</reuseForks>
<disableXmlReport>false</disableXmlReport>
</configuration>
<executions>
<execution>
<id>runSeleniumTests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>2.9</version>
<configuration>
<resultsDirectory>targetallure-results</resultsDirectory>
<inputDirectories>targetallure-results</inputDirectories>
<outputDirectory>targetallure-report</outputDirectory>
<reportVersion>2.3.1</reportVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-maven-plugin</artifactId>
<version>${allure.maven.version}</version>
<configuration>
<resultsPattern>targetallure-results</resultsPattern>
<outputDirectory>targettarget-report</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.7</version>
</dependency>
<dependency>
<groupId>org.gebish</groupId>
<artifactId>geb-core</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.gebish</groupId>
<artifactId>geb-spock</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.0-groovy-2.4</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>3.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>pl.pragmatists</groupId>
<artifactId>JUnitParams</artifactId>
<version>1.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.6</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-maven-plugin</artifactId>
<version>${allure.maven.version}</version>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-junit-adaptor</artifactId>
<version>${allure.version}</version>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-commons</artifactId>
<version>${allure.version}</version>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-report-data</artifactId>
<version>${allure.version}</version>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-java-adaptor-api</artifactId>
<version>${allure.version}</version>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-model</artifactId>
<version>${allure.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>
<reporting>
<excludeDefaults>true</excludeDefaults>
<plugins>
<plugin>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-maven-plugin</artifactId>
<version>${allure.maven.version}</version>
<configuration>
<outputDirectory>target/allure-report</outputDirectory>
</configuration>
</plugin>
</plugins>
</reporting>
I’m aware this POM is messy, I’ve been trying several things in order to make Allure work…
If someone knows what I can do to generate the allure-results directory, thanks in advance.
How to write a first API test with Python + Pytest + Allure
Plan:
- Install pytest as a tests framework
- Install Allure as a nice test report tool
- Write API test for Github API
- Run all together having beautiful report
Start with:
- Installed ubuntu 20.04 focal (running on vagrant, box is ubuntu/focal64)
- Python 3.8.5 installed by default with this box
Scripts could be found on QAProvider github
Create virtual environment
Update package information
$ sudo apt-get update
Install virtual environment
$ sudo apt install python3-venv
Go to working directory (/code/pytests in my example)
$ cd /code/pytests
Create virtual environment with name api-tests
$ python3 -m venv api-tests
If you work on windows environment with vagrant then you might have got next error: Error: [Errno 71] Protocol error: ‘lib’ -> ‘/code/pytests/api-tests/lib64’. In this case you need to create virtual environment with —always-copy option using next command:
$ virtualenv -p python3 api-tests —always-copy
Activate virtual environment
$ source api-tests/bin/activate
Installing Allure
We need to install Allure2. Following the instruction on Allure Github we need brew to install Allure. Let’s start with brew installation. The good article on how to do this on Ubuntu is here.
Install Ruby
$ sudo apt install ruby
Install brew
$ ruby -e «$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install)»
Add Linux-brew to your ~/.bash_profile by running
$ echo ‘export PATH=»/home/linuxbrew/.linuxbrew/bin:$PATH»‘ >>~/.bash_profile
$ echo ‘export MANPATH=»/home/linuxbrew/.linuxbrew/share/man:$MANPATH»‘ >>~/.bash_profile
$ echo ‘export INFOPATH=»/home/linuxbrew/.linuxbrew/share/info:$INFOPATH»‘ >>~/.bash_profile
Add Linuxbrew to your PATH
$ PATH=»/home/linuxbrew/.linuxbrew/bin:$PATH»
Finally install Allure
$ brew install allure
Check the version
$ allure —version
2.13.6
Installing Pytest
$ pip install -U pytest
Check the version
$ pytest —version
pytest 6.1.1
Install allure-pytest
$ pip install allure-pytest
Write tests
We will write 2 tests for get a user function of Github users API. 1 success test & 1 failed test just to see the difference in results.
Full example could be found here on Github
Complete project structure will look like that:
library is a folder with our small package to do an API request and have all stuff for Allure report
test_github.py is a file with 2 tests: test_success and test_failed
Run tests and check results
Run tests
$ pytest —alluredir=allure_results
server results with allure
$ allure serve allure_results/
Generating report to temp directory…
Report successfully generated to /tmp/17631871144287129490/allure-report
Starting web server…
2020-10-21 23:40:31.094:INFO::main: Logging initialized @1810ms to org.eclipse.jetty.util.log.StdErrLog
Can not open browser because this capability is not supported on your platform. You can use the link below to open the report manually.
Server started at . Press to exit
Open results in a browser. As we build it under Vagrant on Windows machine it could be opened with 192.168.10.22 IP address instead of 127.0.0.1.
First, you will see overview panel.
Success result. You will see detailed information in the report: request, method, url, headers, response.
Failed result. You will see detailed information in the report: request, method, url, headers, response (you need to collapse it and it will be the same as in success result above) and failed assert.