Cucumber runner class, parallel execution - junit

I've integrated Cucumber with JUnit / Browserstack. When the cucumber runner class is executed in parallel (by Browserstack code) it generates the same report three times with the same name (effectively being overwritten each time).
Is there way this can be parameterised, so at runtime the report is generated with a unique name?
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(
plugin = {"pretty", "html:target/cukes/htmlreport.html",
"json:target/cucumber/jsonReports/",
},
glue = "/testFrameworks/cucumberSelenium/steps",
tags = "#sunny_day",
features = "src/test/resources/features/cucumber"
)
public final class CucumberRunner {
}

Related

Getting 0 Scenarios 0 Steps after running the Test Runner file

Below is the Test Runner File
package runner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(features="D:/InstalledSoftwares/Eclipse_Photon/workspace/March26/src/test/resources/features/login.Feature",
glue= {"D:/InstalledSoftwares/Eclipse_Photon/workspace/March26/src/test/java/stepDefinitions/LoginSteps.java"})
public class TestRunner {
}
Below is the Feature File-
Feature: Create Account on Facebook
Scenario: Check First Name
Given: User is already on Login Page
When: Enter First Name
And: Enter Last Name
Then: Check if value of First Name is there
Below is the Step Definition-
package stepDefinitions;
import cucumber.api.java.en.Given;
public class LoginSteps {
#Given("^User is already on Login Page$")
public void User_is_already_on_Login_Page()
{
}
}
Below is the Snapshot of Eclipse.
This is how my Project structures look like

Pact.io, Junit - How to test againts multiple consumers with different tags?

I have multiple (not only junit) consumer applications, which create pacts in pact broker.
These consumers have many different git branches - e.g.:
consumer1: release123, release007, release999
consumer2: release69, release420, release50
Question
how to run provider tests against specific combinations of consumers and their tags?
e.g. consumer1 release007, consumer2 release69 AND release50 ?
is these something like -Dpactbroker.consumers=consumer1:release007,consumer2:release69,consumer2:release50 ?
I especially need this for junit, as we mostly use java apps as providers.
What I have found:
in junit, there is annotation #PactBroker which allows you to specify tags and consumers
according to description, these can be set via system properties pactbroker.tags and pactbroker.consumers
there can be specified multiple of each, separated by comma - e.g.: -Dpactbroker.consumers=consumer1,consumer2
I havent found if tags and consumers can be paired while running provider tests
Please try below solution might be it will help
You can add like below on Provider Class
API used
import au.com.dius.pact.provider.junit.IgnoreNoPactsToVerify;
import au.com.dius.pact.provider.junit.Provider;
import au.com.dius.pact.provider.junit.State;
import au.com.dius.pact.provider.junit.loader.PactBroker;
import au.com.dius.pact.provider.junit.loader.PactBrokerAuth;
import au.com.dius.pact.provider.junit.loader.PactFolder;
import au.com.dius.pact.provider.junit.target.Target;
import au.com.dius.pact.provider.junit.target.TestTarget;
import au.com.dius.pact.provider.spring.SpringRestPactRunner;
import au.com.dius.pact.provider.spring.target.SpringBootHttpTarget;
Provider Added on Class
#IgnoreNoPactsToVerify
#PactBroker(
authentication = #PactBrokerAuth(password = "*******", username = "********"),
host = "*******",
tags = {"test", "dev", "latest"},
port = "*****",
failIfNoPactsFound = false,
protocol = "http")
On consumer end you can add on each test case like below
API used
import au.com.dius.pact.consumer.Pact;
import au.com.dius.pact.consumer.PactProviderRuleMk2;
import au.com.dius.pact.consumer.PactVerification;
import au.com.dius.pact.consumer.dsl.PactDslWithProvider;
import au.com.dius.pact.model.RequestResponsePact;
Test Case Level
#Pact(consumer = "consumer-service-name")

WELD-001318: Ambigous dependency when using JaxbJsonProvider and JsonProvider on WAS Liberty

I am running a server under WebSphere Application Server (17.0.0.1/wlp-1.0.16.cl170120170227-0220) and have added the changes recommended in this post (How to change Jackson version in JAX-RS app (WebSphere Liberty)) for upgrading the level of Jackson in WAS Liberty. I am using Postman to test my server. When I submit a GET request for an object, it completes successfully. (After adding this change, my server can return my objects in either XML or JSON.). However, I am now seeing these messages in the server console when my server builds the Response object.
[INFO ] FFDC1015I: An FFDC Incident has been created: "org.jboss.weld.exceptions.AmbiguousResolutionException: WELD-001318: Cannot resolve an ambiguous dependency between:
- Managed Bean [class com.ibm.zss.boundary.JaxbJsonProvider] with qualifiers [#Any #Default],
- Managed Bean [class com.ibm.zss.boundary.JsonProvider] with qualifiers [#Any #Default] com.ibm.ws.jaxrs20.cdi.component.JaxRsFactoryImplicitBeanCDICustomizer 425" at ffdc_17.06.13_15.59.57.0.log
com.ibm.zss.boundary.JaxbJsonProvider and com.ibm.zss.boundary.JsonProvider are the classes I added based on the instructions from the previous post.
I also updated my server.xml to include:
<feature>jsonp-1.0</feature>
<feature>jaxrs-2.0</feature>
I've been searching for solutions for handling a WELD ambiguousResolutionException, but most of them address issues with classes where the developer has control over what is being injected. So, I don't know if I have any control over the code that I need to change for this problem.
For completeness, here are the classes which I added to my application:
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Provider;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
#Provider
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public class JaxbJsonProvider extends JacksonJaxbJsonProvider {
}
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Provider;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
#Provider
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public class JsonProvider extends JacksonJsonProvider {
public JsonProvider() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibility(objectMapper.getVisibilityChecker().withFieldVisibility(JsonAutoDetect.Visibility.ANY));
setMapper(objectMapper);
}
}
Can you either mark it an #Specializes or an #Alternative with low #Priority, depending on whether you want it to be used for injection points?

JUnit NoClassDefFoundError

I'm new at JUnit and use inteliji idea.
import org.junit.Test;
import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.util.Date;
import static org.junit.Assert.*;
public class TestQuote {
#Test
public void testQuote() {
Date date = new Date(System.currentTimeMillis());
Quote quote=new Quote("a",date,200.0,300.0,100.0,107.0,1.0);
assertNull("Object is null",quote);
assertEquals("Symbol is ok",quote.getSymbol(),"a");
assertEquals("Date is ok",quote.getDate(),System.currentTimeMillis());
assertEquals("Open price is ok",quote.getOpenPrice(),200.0);
assertEquals("High price is ok",quote.getHighPrice(),300.0);
assertEquals("Low price is ok",quote.getLowPrice(),100.0);
assertEquals("Close price is ok",quote.getClosePrice(),107.0);
}
}
Here is code of my test class. JUnit.jar is added to classpath but when i run it it says:
java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
Any sollutions?
BTW main program work OK.
Go to the JUnit web site: http://junit.org/
Then click on "Download and install Guide" : https://github.com/junit-team/junit/wiki/Download-and-Install
Then read:
Download the following JARs and put them on your test classpath:
junit.jar
hamcrest-core.jar

Assert element color in Selenium IDE

I'm trying to setup a test automation that will assert an element color when clicked. However, I couldn't find the right way to do it. I'm a selenium newbie, I have tried every possible way to do it but failed.
HTML:
<a class="mg-friend-12345 friend selected" title="test" data-cid="12345" style="">
CSS:
.imweb #mgifting-dialog .mg-friends .friend.selected, .imweb #mgifting-dialog .mg-friends .non-friend.selected {
background-color: #9DD4FD;
}
IMHO the idea be the following:
we simply need to get css property(color, in particulat) of element before click. and get css property(color ) of the element after click on it.
so it be like (I work on java and we will execute a piece of javascript using jsExecutor to implement getColor function. It will take css selector of the element. And get return its color):
public String jsGetColor(String css){
JavascriptExecutor js = (JavascriptExecutor) driver;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("var x=$(\'"+css+"\');");
stringBuilder.append("return x.css('color')");
//stringBuilder.append("return x.css('background-color')");
String res= (String) js.executeScript(stringBuilder.toString());
return res;
}
String cssSelectorLink="a[class='mg-friend-12345 friend selected']";
WebElement linkToClick = driver.findElemebt(By.cssSelector(cssSelectorLink));
String colorBeforeClick = jsGetColor(cssSelectorLink);
linkToClick.click();
String colorAfterClick = jsGetColor(cssSelectorLink);
Assert.assertFalse(colorBeforeClick.equals(colorAfterClick));
Hope it be helpful for you.
well I work in intelij IDEA. So setUp to write selenium tests e.g. be the following:
1) install maven
Unzip the distribution archive, i.e. apache-maven-3.0.4-bin.zip to
the directory you wish to install Maven 3.0.4. These instructions
assume you chose C:\Program Files\Apache Software Foundation. The
subdirectory apache-maven-3.0.4 will be created from the archive.
Add the M2_HOME environment variable by opening up the system
properties (WinKey + Pause), selecting the "Advanced" tab, and the
"Environment Variables" button, then adding the M2_HOME variable
in the user variables with the value C:\Program Files\Apache
Software Foundation\apache-maven-3.0.4. Be sure to omit any
quotation marks around the path even if it contains spaces. 
In the same dialog, add the M2 environment variable in the user
variables with the value %M2_HOME%\bin.
2) install jdk
3)
4) verify that all environment variables you've set properly
5) run intelij IDEA
select Project structure to set up installed JDK
6)
press New.select jsdk. write path where we installed java, e.g C:\Program Files\Java\jdk1.6.0_29
7)create new project from scratch
8) maven module
9)
10)
11) add to POM appropriate dependencies:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.24.1</version>
</dependency>
12) if still someting underline with red line , press alt+enter on it >> idea should automatically suggest autoimport.
13)test structure in the project
14)common structure of selenium test
import com.thoughtworks.selenium.SeleneseTestBase;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.concurrent.TimeUnit;
public class HomePageTest extends SeleneseTestBase{
static WebDriver driver;
#Before
public void openFirefox(){
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}
#Test
public void testHomePage(){
driver.get("https://www.google.by/");
WebElement search = driver.findElement(By.xpath("//*[#id=\"gbqfq\"]"));
search.sendKeys("laptop");
search.submit();
}
#After
public void closeFirefox(){
// driver.quit();
}
}
15) also don't forget that you can export your created test in selenium IDE as JUNIT4- selenium and open them in IDEA
Regards

Categories