Cucumber Browserstack JSON Report generation issue - cucumber

I have a cucumber runner class specifying the output location the cucumber.json file as below.
#RunWith(Cucumber.class)
#CucumberOptions(
plugin = {"pretty", "html:target/cukes/htmlreport.html",
"json:target/cukes/report.json",
"junit:target/cukes/junit.xml",
"html:target/cucumber-report.html",
"json:target/cucumber/jsonReports/cucumber.json"},
glue = "uk/gov/dwp/testFrameworks/cucumberSelenium/steps",
//tags = "#sunny_day",
features = "src/test/resources/features/browser_sample"
)
public class CucumberRunner {
}
When the reports are generated however from the json, they can't be found as the json has been generated into a folder prefixed with '-1-main' i.e;
target/cucumber-1-main/jsonReports/cucumber-1-main.json
This happens when integrating with Browserstack using the browserstack-java-sdk framework.
The workaround is to amend the pom.xml so that the input directory for report generation is pointed as follows;
<outputDirectory>${project.build.directory}/cucumber/masterthought</outputDirectory>
<inputDirectory>${project.build.directory}/cucumber-1-main/jsonReports</inputDirectory>
but that then fails when I am running locally against a single browser.
Could anyone offer any advice please on getting around this issue?

Related

Is additional context configuration required when upgrading cucumber-jvm from version 4 to version 6?

I am using cucumber-jvm to perform some functional tests in Kotlin.
I have the standard empty runner class:
#RunWith(Cucumber::class)
#CucumberOptions(features=[foo],
glue=[bar],
plugin=[baz],
strict=true,
monochrome=true)
class Whatever
The actual steps are defined in another class with the #ContextConfiguration springframework annotation.
This class also uses other spring features like #Autowire or #Qualifier
#ContextConfiguration(locations=["x/y/z/config.xml"])
class MyClass {
...
#Before
...
#Given("some feature file stuff")
...
// etc
}
This all work fine in cucumber version 4.2.0, however upgrading to version 6.3.0 breaks things. After updating the imports to match the new cucumber project layout the tests now fail with this error:
io.cucumber.core.backend.CucumberBackendException: Please annotate a glue class with some context configuration.
It provides examples of what it means...
For example:
#CucumberContextConfiguration
#SpringBootTest(classes = TestConfig.class)
public class CucumberSpringConfiguration {}
Or:
#CucumberContextConfiguration
#ContextConfiguration( ... )
public class CucumberSpringConfiguration {}
It looks like it's telling me I can just add #CucumberContextConfiguration to MyClass.
But why?
I get the point of #CucumberContextConfiguration, it's explained well here but why do I need it now with version 6 when version 4 got on fine without it? I can't see any feature that was deprecated and replaced by this.
Any help would be appreciated :)
Since the error matches exactly with the error I was getting in running Cucumber tests with Spring Boot, so I am sharing my fix.
One of the probable reason is: Cucumber can't find the CucumberSpringConfiguration
class in the glue path.
Solution 1:
Move the CucumberSpringConfiguration class inside the glue path (which in my case was inside the steps package).
Solution 2:
Add the CucumberSpringConfiguration package path in the glue path.
The below screenshot depicts my project structure.
As you can see that my CucumberSpringConfig class was under configurations package so it was throwing me the error when I tried to run feature file from command prompt (mvn clean test):
"Please annotate a glue class with some context configuration."
So I applied solution 2, i.e added the configurations package in the glue path in my runner class annotation.
And this is the screenshot of the contents of CucumberSpringConfiguration class:
Just an extra info:
To run tests from command prompt we need to include the below plugin in pom.xml
https://github.com/cucumber/cucumber-jvm/pull/1959 removed the context configuration auto-discovery. The author concluded that it hid user errors and removing it would provide more clarity and reduce complexity. It also listed the scenarios where the context configuration auto-discovery used to apply.
Note that it was introduced after https://github.com/cucumber/cucumber-jvm/pull/1911, which you had mentioned.
Had the same error but while running Cucumber tests from Jar with Gradle.
The solution was to add a rule to the jar task to merge all the files with the name "META-INF/services/io.cucumber.core.backend.BackendProviderService" (there could be multiple of them in different Cucumber libs - cucumber-java, cucumber-spring).
For Gradle it is:
shadowJar {
....
transform(AppendingTransformer) {
resource = 'META-INF/services/io.cucumber.core.backend.BackendProviderService'
}
}
For Maven something like this:
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/services/io.cucumber.core.backend.BackendProviderService</resource>
</transformer>
</transformers>
A bit more explanation could be found in this answer

Undefined steps after running test from TestRunner class

I have a very strange situation, I have created Features and Scenarios in the feature file and corresponding step definitions and methods in the separate class.
I have run tests by running a feature file, and everything was fine, all tests were green.
But, when I run tests from TestRunner class, I got the following message:
Undefined step: Given I am on the Facebook Login page and suggested code.
You can implement missing steps with the snippets below:
#Given("^I am on the Facebook Login page$")
public void i_am_on_the_Facebook_Login_page() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
I have noticed that the suggested method have underscore:
(i_am_on_the_Facebook_Login_page())
but my methods do not have underscore
(iAmOnTheFacebookLoginPage())
Does anybody have an idea why this happens? I can't run tests now even from the feature file.
Recently, I have started using Mac and IntelliJ instead of Windows and Eclipse.
Is it possible that IntelliJ causes the problem?
P.S. I have used the option "Create step definition" from IntelliJ
ah...I figured out what the problem was...I forgot to put this piece of code
snippets = SnippetType.CAMELCASE
in CucumberOptions.
So, when I put this line of code here
#CucumberOptions(
plugin = {"pretty"},
features = {"src/test/resources/features"}, glue = {"/java/stepDefinitions"}, snippets = SnippetType.CAMELCASE)
everything works just fine.
It is possible your features folder is not in the build path (being a test folder) so Cucumber is unable to find it. Try this.

karate: Picking up feature files from absolute class path

I am following the DemoTestSelected.java sample to run the feature file in my Karate Framework. It's working fine when i run them in intellij. But when i convert it into jar and then run from it, it is throwing the below error.
java.lang.RuntimeException: java.io.FileNotFoundException: file:\C:\Src_path\target\app-jar-with-dependencies.jar!\features\app\app_1.0.4_a.feature (The filename, directory name, or volume label syntax is incorrect)
I explored the Karate Core code and found the below class which might be problem.
public static URL toFileUrl(String path) {
path = StringUtils.trimToEmpty(path);
File file = new File(path);
try {
return file.getAbsoluteFile().toURI().toURL();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
I am stuck here, any help would be appreciated.
First - no one has ever reported this problem and teams normally don't need to bundle tests into a JAR.
Second - if you use the classpath: prefix, you should be able to load feature files from within even JAR files. So please use it and it is documented here: https://github.com/intuit/karate#reading-files
* def result = call read('classpath:some-reusable-steps.feature')
If this does not solve the problem, please follow the instructions here and submit an issue: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue - please explain what you are trying to do differently also.

using groovy script to validate assertions in robot framework when executing soap test by using suds library

In my soapui test I have written a groovy script to validate all the assertions.I want to do the same in robot framework .
I am executing soapui test from robot framework using suds library.
How can I use my groovy script in Robot framework to verify all the assertions in single go like we do in SOAPUI.
please help
Thanks
You can do your verification in Groovy, but its not very simple. If your verifications are all on the XML and not things like headers or status codes, you can take the XML response from SudsLibrary and pass it to a user library. I did all the tasks to make this work manually, but if you use Maven and the plugins for Groovy and Robot Framework, it would be easier to work with.
The user library must be compiled to a .class file using the compiler, groovyc. Here you can use the SoapUI helper classes you are familiar with. They need to be on the class path when compiling. From the SoapUI installation folder, I added bin\soapui-5.2.0.jar and lib\* to the class path. For Robot Framework to use your Groovy script, classes and public methods must be used per the test library API.
package com.example.soapui;
import com.eviware.soapui.support.XmlHolder
public class Verifications {
public void checkResponse(String xml) {
def holder = new XmlHolder(xml)
holder.namespaces["ns1"] = "http://www.webserviceX.NET"
def average = holder.getNodeValue("//ns1:Average[1]")
assert average == "2.5"
}
}
Here is a simple test that calls a public web service and invokes the Groovy script to check the response.
*** Settings ***
Library SudsLibrary
Library Collections
Library com.example.soapui.Verifications
*** Test Cases ***
Simple
Create Soap Client http://www.webservicex.net/Statistics.asmx?WSDL
Set Return Xml True # soap calls from now one will return XML
${dbl array}= Create Wsdl Object ArrayOfDouble
Append To List ${dbl array.double} 2.0
Append To List ${dbl array.double} 3.0
${result}= Call Soap Method GetStatistics ${dbl array}
Check Response ${result} # pass the XML to the user keyword written in Groovy
During execution, both Groovy and SoapUI jar files need to be on the class path.
C:\ws\groovy>jybot groovy.robot
==============================================================================
Groovy
==============================================================================
Simple | PASS |
------------------------------------------------------------------------------
Groovy | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output: C:\ws\groovy\output.xml
Log: C:\ws\groovy\log.html
Report: C:\ws\groovy\report.html

Entity Framework my DB Context does not have connection when Reference in other Project

So here is my problem Guys
In my Solution,
I have ORM Class Liberary where I've added EntityFramework 5 (so has .edmx containing Context.tt
Designer.cs, edmx.diagram and .tt) files.. So far so good
And I have Project called Repositories and has reference of ORM project above.
In HeaderRepository class of Repositories Project, when I write following code,
using(UFPEntities ufpEntities = new UFPEntities())
{
try{
Header header = ufpEntities.Headers.Single(x => x.VendorId == id);
}catche(Exception e)
{
}
}
Note: intellisense works fine COMPILER DOES NOT GIVE ERROR while writing above code, it happens at Run time
But, I get "No connection string named 'UFPEntities' could be found in the application config file."
App.config is in ORM Project, not in Repository Project where I am dealing with Data as Above.
Can you please help me so that I can CREATE MY MODEL class (such as Header) from Repository Project? or What I am doing wrong so it gives me Exceptions?
Thx in Advance.
The connection string must be in config of entry assembly - it is either web.config for web application or app.config for executable or unit test library. App.config for arbitrary library which is just referenced by executed code is completely ignored.

Resources