You can implement missing steps with the snippets below - maven

>## This my Pom.xml file structure ##
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cucumberExcecise</groupId>
<artifactId>Cucumber_Practice</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
## Feature File:##
Feature: Login Feature
Scenario: Login as a authenticated user
Given User is on Home Page
**Step Definition code:**
#Given("User is on Home Page$")
public void user_is_on_homepage() {
// Write code here that turns the phrase above into concrete actions
System.setProperty("webdriver.chrome.driver", "E:\\Downloads\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://sample.com");
}
**Runner Class:**
#RunWith(Cucumber.class)
#CucumberOptions(strict = true,features = "src/test/resources/featureFiles/sample.feature", glue = {
"src/test/java/com/stepDefinitions/Step.java" })
public class TestRunner {
}
**Whenever running Runner class its showing below error:**
1 Scenarios ([33m1 undefined[0m)
1 Steps ([33m1 undefined[0m)
0m0.000s
You can implement missing steps with the snippets below:
#Given("^User is on Home Page$")
public void user_is_on_Home_Page() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}

in your Testrunner class you have to put some stuff, or rather it has certain annotations (the class itself is empty)
You have to tell where the Feature files are and where the steps files are (the .java files, this comes in the "glue")
You can also specify tags (then you annotate your features or scenarios with #something to run these )
And there are other options that deal with things like reports.
an example would be:
package steps;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(features = "src/test/resources/"
, monochrome = false
, format = { "pretty", "html:target/results" }
, glue = { "steps" }
, strict = true
, tags = {"#RT-interact"}
)
public class TestRunner {
}
There are many tutorials such as http://www.automationtestinghub.com/cucumber-test-runner-class-junit/ where you can find more info.

Related

Maven + Surefire + #RunWith(JUnitPlatform.class) annotation

I have a Maven project where I want to run Junit 4 and 5 test cases. Some of the JUnit5 test cases also uses #RunWith(JUnitPlatform.class) annotation to run with Junit4. However, I have not been able to run both Junit 4 and 5 test cases in the same project so far.
See the code below. To compile JUnitPlatformClassDemoTest, I would need to add "junit-platform-runner" dependency in pom.xml, but the moment I add it, Maven ignores JUnit 5 test cases.
I have tried various combinations but nothing seems to work. Note that if I remove JUnitPlatformClassDemoTest class, then Maven is able to run the remaining Junit 4 and 5 test cases successfully. Problem seems to be only with #RunWith(JUnitPlatform.class) annotation.
How do I configure Maven such that it can run Junit 5 and 4 test cases and the tests which have #RunWith(JUnitPlatform.class) annotation ?
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>junit45</groupId>
<artifactId>junit45</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.opentest4j</groupId>
<artifactId>opentest4j</artifactId>
<version>1.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<version>1.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
<!-- After adding this dependency JUnit 5 test cases are ignored -->
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
</plugins>
</build>
</project>
SampleTest class
package example;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class SampleTest {
List<String> list;
#BeforeEach
void beforeEach() {
list = new ArrayList<>();
}
#Test
public void join() {
list.add("foo");
list.add("bar");
Assertions.assertEquals("fooXbar", String.join("X", list));
}
#Test
public void unjoin() {
String joinedString = "fooXbar";
String[] values = joinedString.split("X");
Assertions.assertArrayEquals(new String[] { "foo", "bar" }, values);
}
}
JUnit4Test class
package example;
import org.junit.Assert;
import org.junit.Test;
public class JUnit4Test {
#Test
public void dummyTest() {
Assert.assertTrue(true);
}
}
JUnitPlatformClassDemoTest class
package example;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
#RunWith(JUnitPlatform.class)
public class JUnitPlatformClassDemoTest {
#Test
void successTest1() {
System.out.println("successTest1");
}
#Test
void successTest2() {
System.out.println("successTest2");
}
}

TestRunner InitilisationError

I am new to the Gherkin / cucumber BDD. I have been trying to create a framework using Maven, TestNG and Cucumber. I created feature file, StepDefinitiions and TestRunner. When I run feature file my scenarios are executed successfully. However, when I try to run using 'TestRunner' I am getting InitialisationError I believe I have added all required dependencies in Maven-POM.xml
I am attaching screenshot of error:
TestRunnerInitialisationError
I am attaching additional information
Project Sttructure
Project Structure
POM.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>auto</groupId>
<artifactId>AAFramework</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>AAFramework</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<build>
<resources>
<resource>
<directory>src/main/java/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- 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/io.cucumber/gherkin -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin</artifactId>
<version>15.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.3.0</version>
<scope>test</scope>
</dependency>
<!-- Log4j dependencies: https://logging.apache.org/log4j/2.x/maven-artifacts.html#Using_Log4j_in_your_Apache_Maven_build -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.13.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.3</version>
</dependency>
<!-- For Screenshots: https://mvnrepository.com/artifact/org.apache.commons/commons-io -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>5.0.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.6.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>6.6.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>6.6.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-testng -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
</project>
Testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel = "tests">
<listeners>
<listener class-name="aaframework.Listeners"/>
</listeners>
<test name="AmazonHomeLins">
<classes>
<class name="cucumberOptions.TestRunner"/>
</classes>
</test>
</suite> <!-- Suite -->
Feature File
Feature: Verify Amazon India homne page header links are working and redirected to respective pages
Scenario: Mobile link is working on Amazon home page
Given I am on Amazon India home page
When I click on Mobiles link
Then I am redirected to Mobiles web page
Scenario: Best Sellers link is working on Amazon home page
Given I am on Amazon India home page
When I click on 'BestSellers' link
Then I am redirected to Best Sellers web page
Step Definitions
package stepDefs;
import java.io.IOException;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import pageObject.HomePagePF;
import resources.Base;
public class AmazonHome extends Base{
public WebDriver driver;
HomePagePF hp;
#Given("I am on Amazon India home page")
public void i_am_on_amazon_india_home_page() throws IOException {
// Write code here that turns the phrase above into concrete actions
driver = initialiseBrowser();
driver.get(prop.getProperty("url"));
}
#When("I click on Mobiles link")
public void i_click_on_mobiles_link() {
// Write code here that turns the phrase above into concrete actions
hp = new HomePagePF(driver);
hp.getMobiles().click();
}
#Then("I am redirected to Mobiles web page")
public void i_am_redirected_to_mobiles_web_page() throws InterruptedException {
// Write code here that turns the phrase above into concrete actions
Thread.sleep(2000);
String actualMobile = driver.getTitle();
// System.out.println(actualMobile);
String expectedMobile = "Mobile Phones: Buy New Mobiles Online at Best Prices in India | Buy Cell Phones Online - Amazon.in";
Assert.assertEquals(actualMobile, expectedMobile);
driver.close();
}
#When("^I click on 'BestSellers' link$")
public void i_click_on_bestsellers_link() throws Throwable {
hp = new HomePagePF(driver);
hp.getBestSellersLink().click();
}
#Then("^I am redirected to Best Sellers web page$")
public void i_am_redirected_to_best_sellers_web_page() throws Throwable {
Thread.sleep(2000);
String actualTitle = driver.getTitle();
// System.out.println(actualTitle);
String expectedTitle = "Amazon.in Bestsellers: The most popular items on Amazon";
Assert.assertEquals(actualTitle, expectedTitle);
driver.close();
}
}
TestRunner
package cucumberOptions;
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
#RunWith(Cucumber.class)
#CucumberOptions(features = "/src/test/java/features",
glue= {"src/test/java/stepDefs"})
public class TestRunner {
}

Allure not attaching to html report

I am trying to attach a screen shot to my allure report however I am failing miserably.
#Test (priority = 1, description="SS1 Verify the login section")
#Description ("Verify that user mngr116116 can logon to the system")
public void login()
{
page = new BankingLandingPage();
System.out.println("Test Case One in " + getClass().getSimpleName()
+ " with Thread Id:- " + Thread.currentThread().getId());
page.enterUser("mngr116116");
page.enterPass("ytUhUdA");
page.submitBtn();
page.saveImageAttach();
}
The saveImageAttach code in the Page class is as follows:
#Attachment
public byte[] saveImageAttach() {
try {
byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
return screenshot;
} catch (Exception e) {
e.printStackTrace();
}
return new byte[0];
}
What am I missing?
Report screen shot attached
enter image description here
Probably of note I have the following method also in my page class and it works a treat:
public void screenShot(String title) throws Exception {
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
String png = ("src/main/resources/screenshot/" + title + ".png");
FileUtils.copyFile(scrFile, new File(png));
}
So it would appear to be how I am implementing #Attachment
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.framework</groupId>
<artifactId>framework</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<aspectj.version>1.8.13</aspectj.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.7</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.5.3</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.5.3</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.0-BETA21</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<properties>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
<!-- those are the two default values, you can probably skip them -->
<forkCount>7</forkCount>
<reuseForks>true</reuseForks>
<!-- that's what made it work -->
<parallel>classes</parallel>
<threadCount>10</threadCount>
<includes>
<include>src/test/java/testsuite/*class</include>
</includes>
</properties>
</configuration>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.10</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>2.20.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<excludeDefaults>true</excludeDefaults>
<plugins>
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>2.8</version>
</plugin>
</plugins>
</reporting>
</project>
adding my pom as well in case that sheds any light
after save screenshot into file in screenShot(..) convert file in ByteArray. Example (kotlin):
fun returnScreenshot(screenshotPath: String): ByteArray {
val screenFile = File(screenshotPath)
val screenFileInBytes = ByteArray(screenFile.length().toInt())
val fis = FileInputStream(screenFile)
fis.read(screenFileInBytes)
fis.close()
return screenFileInBytes
}
then return this screenshot in ByteArray with #Attachment.
Example (java):
public interface ReportInterface {
String screenshotPath();
#Attachment(value = "current screenshot", type = "image/png")
default public byte[] showCurrentScreen() {
return ScreensHelperKt.returnScreenshot(screenshotPath());
}
After implement your test class by this ReportInterface and implement screenshotPath() to return screenshot path.
Call screenShot(String title) and showCurrentScreenshot() in test body or in teardown, or after failed test(with testRule). But make sure that showCurrentScreenshot() is runble anyway.
Hope, it helps.
try running the following code instead:
#Attachment(value = "screenshot", type = "image/png")
public byte[] saveScreenshotPNG (WebDriver driver) {
return ((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
}

Get console output an screenshot attached to allure report- selenium webdriver, testng, maven

I am using allure reporting. My report is generated correctly, but i screenshots and console output is not attached to report.
Here is my pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.testproject</groupId>
<artifactId>tests</artifactId>
<version>0.1-SNAPSHOT</version>
<properties>
<aspectj.version>1.8.10</aspectj.version>
</properties>
<dependencies>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.0-BETA14</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.16</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.16</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Please find screenshot attached of
It shows status pass/fail/broken and time taken to run test. But console output is not attached to it. Also screenshots for failed test cases are stored in folder surefire-reports/screenshots. I need to attach them too to allure reports.Can someone please help in knowing what i need to add to get this output?
Thanks!!
I am assuming that you are getting the failure screenshot using TestNG listener and you have access to the testNG listener. Else see how to create a TestNG listener (http://testng.org/doc/documentation-main.html#listeners-testng-xml) by overriding the TestListenerAdapter.
It seems you can create a method like the following for saving screenshot
#Attachment(value = "Page screenshot", type = "image/png")
public byte[] saveScreenshot() {
// Use selenium screenshot code to take screenshot and convert into byte[]
return byte[];
}
You can then call this method in your testNG listener used to take screenshot on test failure.
#Override
public void onTestFailure(ITestResult testResult) {
saveScreenshot();
super.onTestFailure(testResult);
}
For getting the console output to report, create the following method
#Attachment
public String logOutput(List<String> outputList) {
String output = "";
for (String o : outputList)
output += o + "<br/>";
return output
}
Call the method onTest(success, failure, skip) and onConfiguration (success, failure, skip) in the testNG listener
#Override
public void onTestSuccess(ITestResult testResult) {
// Reporter.getOutput(testResult)will give the output logged in testng reporter
logOutput(Reporter.getOutput(testResult));
super.onTestSuccess(testResult);
}
https://github.com/allure-framework/allure1/wiki/Attachments

Running an intersection of tests using Junit and Maven

I have a number of tests identified using the Spring #IfProfileValue flag
#IfProfileValue{"a", "c"}
#Test
public void testA{ Do Stuff }
#IfProfileValue{"a", "b"}
#Test
public void testB{ Do Stuff }
#IfProfileValue{"a", "b"}
#Test
public void testC{ Do Stuff }
#IfProfileValue{"b"}
#Test
public void testD{ Do Stuff }
I can run all the tests using
mvm clean install -Dtest-group=a -Dtest-group=b
I want to run only the tests that match #IfProfileValue={"a","b") (Test B/C)
so is there a way to run only an intersection of these two values using maven?
Edit:
You can annotate the class with #ProfileValueSourceConfiguration# and provide your own implementation ofProfileValueSource`, as described in this answer.
Looks like is not possible with Maven alone. It looks like it can build array from multiple arguments with same name:
mvn test -Dtest-group=a -Dtest-group=c
will ran test annotated with #IfProfileValue(name = "test-group", values = {"c"}). Neither comma notation will work, it will treat 'a,c' as literal:
mvn test -Dtest-group=a,c
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.s17t</groupId>
<artifactId>showcase</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.1.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compier-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
Java code:
package showcase;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(loader=AnnotationConfigContextLoader.class)
#TestExecutionListeners
public class SimpleTest {
#Configuration
static class ContextConfiguration {
}
#Test
#IfProfileValue(name = "test-group", values = {"a", "b"})
public void testPhoneLogIsReadable() {
System.out.println("I'm a and b");
assertTrue("Phone log is not readable.", true);
}
#Test
#IfProfileValue(name = "test-group", values = {"c"})
public void testPhoneLogHasRecords() {
System.out.println("I'm c");
assertFalse("Phone log does not have records.", false);
}
}

Resources