Cucumber feature file unable to locate glue code when clicking on Recalculate Steps and throws error message - selenium

I am currently working on creating a Test Suite using Cucumber framework. I have created feature files for each of the functionality I have to test.
The feature file never shows the conditions to be covered via glue code. On click of Recalculate steps it throws an error : An internal error occurred during: "Scanning for step definitions".
java.lang.NullPointerException
I tried to change the path of glue in the Test Runner class but it did not solve the problem as well. The feature can be executed without any issue and the code runs fine, only issue is feature files keep on stating that there is no matching glue code.
#OrderInteraction
#Orders
Feature: Validating Order functionality
Background: Pre-requisites of Order Functionality
Given WebDriver is initialized
And Website is up and running
When User Enter "Username" and "Password" as Credentials
Then Validate User Login
Test Runner :
package Cucumber;
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
#RunWith(Cucumber.class)
#CucumberOptions(features = "Features", glue=
{"src/main/java/CucumberStepDefinitions"})
public class CucumberTestRunner {
}
I would like to find a way in which Cucumber feature files can recognize the glue code present. Feel free to guide me to a existing question which answers this or a documentation which will be of help.

There is a possible solution in this discussion https://github.com/cucumber/cucumber-eclipse/issues/303
Which basically says to make sure you don't have
import cucumber.api.java.en.*;
in your steps files, and to use
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
instead.
Which fixed it for me

I finally was able to find the solution to this issue. Issue lies with the cucumber plugin version, I referred to Cucumber-Eclipse-Update-SiteSnapshot for resolution.
The steps were as below :
1.From Eclipse, go to menu Help > Install New software
2.Work with: https://cucumber.github.io/cucumber-eclipse-update-site-snapshot
3.Select the check-box for Cucumber Eclipse Plugin
4.Select Next as per the instruction shown during installation.
5.Restart your Eclipse after completion of instruction.
Once the plugin was updated Feature file automatically scanned for steps and found the matching glue code.

Related

Import org.apache.commons.io.FileUtils; not possible in latest apache poi.Instead import org.apache.tools.ant.util.FileUtils; is coming

In the latest Apache poi download(poi-3.15-beta2), while taking screenshot, I need to use FileUtils.copyFile. In its previous version, the imported package was import org.apache.commons.io.FileUtils;. In the latest download, this package is not coming, and it is giving error in my existing executable code. Now I tried to remove the previous import and it gave import org.apache.tools.ant.util.FileUtils;
Code:
FileUtils.copyFile(
scrFile,
new File(location+"LR_"+strDate+"_scr1.png")
);
Gives the error:
Cannot make a static reference to the non-static method
`copyFile(File, File)` from the type `FileUtils`
Apache POI never bundled or required Apache Commons IO, which contains the FileUtils class and so it seems some other project dragged in this code previously, but does not any longer. See http://poi.apache.org/overview.html#components for the list of third-party projects that Apache POI uses.
You should simply add a recent commons-io dependency to your project depending on which type of buildsystem you use, e.g. a normal dependency in Gradle/Maven or the actual jar-file if you have a buildsystem without full dependency-support.
Use the code below:
FileUtils.getFileUtils().copyFile(sourceFile, new File(directory + filename));
And import file should be:
import org.apache.tools.ant.util.FileUtils;

Intellij IDEA > Cucumber Test Results don't display Scenario name

Problem:
When running my Cucumber Acceptance tests from Intellij, the Test Results don't display the scenario name, just <no name> - making it difficult/impossible to determine which Scenario actually failed!
e.g.
I'm using JDK8 with Intellij IDEA 15 Community Edition (Build #IC-143.2287) with the following Intellij IDEA plugins:
Cucumber for Java (v 143.382) - github.com / plugins.jetbrains.com
Cucumber for Groovy (v 143.382) - github.com / plugins.jetbrains.com
The following Cucumber libraries (gradle):
testCompile "info.cukes:cucumber-junit:1.2.4"
testCompile "info.cukes:cucumber-java8:1.2.4"
testCompile "info.cukes:cucumber-spring:1.2.4"
This is my AcceptanceTests.groovy file:
import cucumber.api.CucumberOptions
import cucumber.api.junit.Cucumber
import org.junit.runner.RunWith
#RunWith(Cucumber.class)
#CucumberOptions(
strict = false,
plugin = ["pretty", "html:build/reports/cucumber"],
tags = ['~#ignore']
)
public class AcceptanceTests {}
Just wondering:
Is there anyway to display the scenario name?
Is it something I'm doing OR is it just not implemented yet? (OR does it exist in the Intellij IDEA Ultimate Edition?)
Who can I suggest this feature to, if it doesn't exist yet?
Update - 21/03/2016
I've forwarded my question to the author (Andrey Vokin) and raised an issue - https://youtrack.jetbrains.com/issue/IDEA-153338 .
I have same problem, and found where it's coming from in my case. For "scenario" at least, it seems to come from dots (".") : remove them from your scenario description and see what happens.
I was also facing the same problem, but I haven't used any dots (".") in scenario description. Though the full stop (dot) was present in the Feature file description and after removing that it worked for me.
Feature file description:
After result how it looks like:

Running evosuite generated tests in Eclipse

I have generated the test cases using evosuite from the command line in Linux.
I try to execute the tests in Eclipse. I have imported in my project the evosuite-standalone-runtime-0.2.0.jar.
All the imported classes regarding evosuite are marked with the error sign.
import org.evosuite.runtime.EvoRunner;
import org.evosuite.runtime.EvoRunnerParameters;
import org.evosuite.runtime.testdata.EvoSuiteFile;
import org.evosuite.runtime.testdata.EvoSuiteLocalAddress;
import org.evosuite.runtime.testdata.EvoSuiteRemoteAddress;
import org.evosuite.runtime.testdata.EvoSuiteURL;
I don't understand this. It looks like these classes are unknown even though are in the imported jar file.
Try:
Right button in your project-->build path--> Add External Archives
(select evosuite-0.2.0.jar)
Do not forget to put the two classes in the project. (ESTest.java and ESTest_scaffolding)
I hope this helps.

Undefined step definitions in IntelliJ

I'm trying to follow this article to match Cucumber specs with step definitions in IntelliJ.
When I press Alt+Enter, I see Inspection 'Undefined Step' options. However, I should see the intention action Create Step Definition.
I thought I had the Cucumber IntelliJ plugin installed, so that shouldn't be a problem. Any help is greatly appreciated.
Turns out I had the Gherkin plugin but not the Cucumber for Java plugin.
I wasted around an hour to solve this. My issue was, Idea was able to navigate from feature to step file. But when I wanted to execute one cucumber test from feature file (Right click and Run Scenario), it was giving error as undefined steps.
Solution: In the Edit Configuration -> provide the Glue for the cucumber which should be absolute path till steps folder. Please see below screen shot
This fixed my problem of running feature file from Idea.
Hope this helps others.
Most probably you need to install the cucumber for java plugin, if already installed then you need to enable from File>>Settings>>pugins.
I had to uncheck the "Create separate module per source set" checkbox under the "Build, Execution, Deployment" -> "Build Tools" -> "Gradle" settings, and then rebuild the project.
"Undefined" step error message would appear if you import a new BDD project.
This error could appear due to two reasons.
If you have not installed the "Cucumber for Java" plugin.
If you import any BDD projects then it will not detect step definition file.
Solution:
1. If the plugin is not found then you need to install from the below location.
File->Settings->Plugins->MarketPlace->Cucumber for Java
2. After Importing the project disable the plugin and enable once again in the Installed section under Installed.
For me there was a collision between Sidesteps plugin and Cucumber plugin in Intellij and as a result *.feature file extension was taken over by the Sidesteps plugin and was expecting Sidesteps step definitions ignoring Cucumber step definitions. No clue what Sidesteps actually is. So went to IntelliJ settings and reassigned the *.feature extension to Cucumber Scenario type and then everything worked fine and Cucumber steps are recognized by Intellij now.
I had the same issue where all of a sudden my feature to step definition glue was missing. All i did was goto Run->Edit Configurations->and removed the cucumber java
configuration and restarted IntelliJ. it worked fine.
I found that even with the Cucumber for Java plugin installed it was still generating only one step. I eventually uninstalled the Cucumber for Java plugin and reinstalled it and all step definitions were generated.
The issue was fixed after updating the Intelij to the latest version and after updating the cucumber and gherkin intelij plugins
Me not help not one of suggestions above.
But i find if you start one test from runner the problem goes on (it is worked if you have runner for some tests( Runner is class that have line #CucumberOptions(
features = "src/test/resources/stability_*****_features/",
glue = "steps"
)
And may be the next line in config helped you^
in configurations i put line: --plugin org.jetbrains.plugins.cucumber.java.run.CucumberJvm4SMFormatter
in Programm arguments line - it help me
If still not working, you can add runner class
add -> runner package -> Main Runner class
-test
-runner - Create this package
-stepPackage
-resources
-features
#CucumberOptions(features = {"classpath:features"}, glue = {"stepDefinition"},
monochrome = false,dryRun = false)
public class MainRunner extends AbstractTestNGCucumberTests {
}
That is it. Just run this class first. Right mouse click and Run'MainRunner'
Then it will work if you just go back and run Scenarios as well
I had the same issue and was resolved by going to Run> Edit configuration> Before Launch then click on the add option "+" and add Build Project option.
enter image description here

How to run an exported selenium test case using TestNG in Eclipse

I recorded a test case using Selenium IDE 1.10.0. I exported the case as Java/TestNG/Remote Control.
My Eclipse version is 4.2.0 and I installed TestNG plug-in version 6.8
I am wondering how can I create a project within the eclipse to run this exported test case?
Please give me some instructions or share with me some online tutorial / documentations. Thanks!
Below is the java code generated by the Eclipse:
package com.example.tests;
import com.thoughtworks.selenium.*;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import java.util.regex.Pattern;
public class SearchDonor extends SeleneseTestNgHelper {
#Test public void testSearchDonor() throws Exception {
// set overall speed of the test case
selenium.setSpeed("4000");
selenium.open("/?html=openid");
selenium.click("css=input[type=\"submit\"]");
selenium.waitForPageToLoad("30000");
Thread.sleep(4000);
selenium.click("id=cmp_admin");
selenium.waitForPageToLoad("30000");
selenium.click("id=quicksearch_anchor");
selenium.click("css=img[alt=\"Member\"]");
selenium.waitForPageToLoad("30000");
selenium.type("id=search_name", "suzy");
selenium.click("css=input[type=\"image\"]");
selenium.click("link=Balagia, Suzy");
selenium.waitForPageToLoad("30000");
}
}
After some trial and errors. I managed to execute the exported code in Eclipse as TestNG Test. Here are the steps I took to make it compile.
1.created a Java Project within the Eclipse
2.add a class to the Java Project
2a. I copied and pasted the code into the newly created the class
3.Right click on the project>build path>configure build path
3a. on the Java Build Path window select libraries>Add External JARS, then adding all the JAR files from Selenium Java Driver folder (e.g. folder name in this case is libs), plus selenium-java-2.31.0.jar and selenium-java-2.31-src.jar
4.click the Run icon next the debug icon on the top menu bar, Run AS TestNG Test
My code is compiling, but I got some exception errors. I am getting stared on a TestNG test case!