import cucumber.api.DataTable; cannot be resolved - maven

I am trying to automate DataTables in Cucumber where i have written the appropriate feature and step definition for the same.
Eclipse is suggesting to import io.cucumber.datatable.DataTable; and when I use the raw() method, eclipse throws an error saying "The method raw() is undefined for the type DataTable"
Feature : Then user enters username and password
| mngr193115 | edytadA |
Step Definition :
#Then("^user enters username and password$")
public void user_enters_username_and_password(DataTable credentials) {
//driver.findElement(By.linkText("ACCOUNT")).click();
List<List<String>> data = credentials.raw();
driver.findElement(By.xpath("//input[#type='text']")).sendKeys();
driver.findElement(By.name("password")).sendKeys(password);
}
Below is my POM.xml file
<dependencies>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-jvm -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>4.3.0</version>
<type>pom</type>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.3.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-jvm-deps -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.6</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/net.masterthought/cucumber-reporting -->
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>4.6.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>3.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/gherkin -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin</artifactId>
<version>5.1.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
expected - to resolve the import issues and import cucumber.api.DataTable;
Actual - Eclipse is suggesting to import import io.cucumber.datatable.DataTable; for DataTable and when I import the same, i am not able to use raw() method.

Main Point: People have been facing few errors (mentioned below) as they mix direct & transitive dependencies. So we shall not mix direct & transitive dependencies specially their versions! Doing so can cause unpredictable outcome.
The import cucumber.api.junit cannot be resolved
java.lang.NoClassDefFoundError: gherkin/IGherkinDialectProvider
import cucumber.api.DataTable; cannot be resolved
Solution: Please remove cucumber-java, cucumber-core, cucumber-jvm-deps, gherkin & junit. They're transitive dependencies and will be provided by your dependencies. You can add below set of minimal cucumber dependencies.
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.3.0</version>
<scope>test</scope>
</dependency>

If you are using io.cucumber instead of cucumber.api import then use cells() method which is an alternative of the raw() method in io.cucumber package.
Example:
List<List<String>> testData = data.cells();
System.out.println(testData.get(0).get(0)); //displays the first element of dataTable //of 0th row and 0th column

I. option
https://mvnrepository.com/artifact/io.cucumber/datatable-dependencies/1.1.12
https://mvnrepository.com/artifact/io.cucumber/datatable/1.0.3
<!-- https://mvnrepository.com/artifact/io.cucumber/datatable-dependencies -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>datatable-dependencies</artifactId>
<version>1.1.12</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/datatable -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>datatable</artifactId>
<version>1.0.3</version>
</dependency>
II. option
Try out to update cucumber-core and cucumber java dependencies up to latest versions:
https://mvnrepository.com/artifact/io.cucumber/cucumber-core/4.3.1
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>4.3.1</version>
</dependency>
https://mvnrepository.com/artifact/io.cucumber/cucumber-java
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.3.1</version>
</dependency>
And after that- do maven reimport.
Hope this helps

I also had an issue while using raw() so instead I changed it to cells() which worked fine
#And("^I enter following for login$")
public void iEnterFollowingForLogin(DataTable table) throws Throwable{
List<List<String>> data = table.cells();
System.out.println("Username: "+data.get(1).get(0));
System.out.println("Password: "+data.get(1).get(1));
}

Feature : Then user enters username and password
| mngr193115 | edytadA |
From your question what is notice was above was the feature file you used.
I agree that you have to do import for datatable and before that can you please change the feature file to below if not
Feature : To check the UN and Pwd
Scenario : ScenarioName
Then user enters username and password
| mngr193115 | edytadA |

Related

Eclipse unable to find raw()method while using Cucumber datatable

In my feature file i am using datatable
Feature File
And verify for incorrect or incomplete Address
|/api/ |
|/api/2020-05-30|
|/api/20200404 |
|/api/abcfghj |
I am using eclipse and In step definition file, when I am trying to add raw() method for datatable its unable to populate the method. While mouse hovering DataTable it imported package as import io.cucumber.datatable.DataTable;
#And("^verify for incorrect or incomplete Address$")
public void verify_for_incorrect_or_incomplete_url(DataTable address) throws Throwable {
List<List> data = address.
I am not sure what is missing in my dependency file, please guide.
POM.xml
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>5.5.0</version>
<scope>test</scope>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>datatable-dependencies</artifactId>
<version>1.1.12</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>datatable</artifactId>
<version>1.0.3</version>
</dependency>
</dependencies>
the raw() method is outdated.
So you can instead do something like this:
List<List<String>> data = address.asLists(String.class);
The Result will be:
[[/api/], [/api/2020-05-30], [/api/20200404], [/api/abcfghj]]

Extentreport support for Cucumber-JVM 4.0 (io.cucumber)

I am trying to migrate my Cucumber automation project from cucumber (info.cukes ) to cucumber (io.cucumber)
During this process, i having trouble with migrating extend reports. Could you please help me with what I am missing?
dependency:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.2.6</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.2.6</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>4.2.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-html -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-html</artifactId>
<version>0.2.7</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.26-incubating</version>
</dependency>
<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>cucumber-extentsreport</artifactId>
<version>3.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>4.0.9</version>
</dependency>
Runner class:
package CucumberWithAfterStep.AfterStepPOC;
import java.io.File;
import org.junit.AfterClass;
import org.junit.runner.RunWith;
import com.cucumber.listener.Reporter;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(features = "src/test/resources/features", glue = { "testSteps" }, plugin = { "pretty",
"html:target/cucumber", "json:target/cucumber.json" , "com.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/report.html" },
monochrome = true,
tags = {"#WAC003 "}, dryRun = false)
public class MainRunnerTest {
#AfterClass
public static void writeExtentReport() {
Reporter.loadXMLConfig(new File(FileReaderManager.getInstance().getConfigReader().getReportConfigPath()));
}
}
Error:
cucumber.runtime.CucumberException: Couldn't load plugin class: com.cucumber.listener.ExtentCucumberFormatter. It does not implement
cucumber.api.Plugin
at cucumber.runtime.formatter.PluginFactory.loadClass(PluginFactory.java:176)
at cucumber.runtime.formatter.PluginFactory.pluginClass(PluginFactory.java:163)
at cucumber.runtime.formatter.PluginFactory.getPluginClass(PluginFactory.java:220)
at cucumber.runtime.formatter.PluginFactory.isStepDefinitionReporterName(PluginFactory.java:203)
at cucumber.runtime.RuntimeOptions$ParsedPluginData.addPluginName(RuntimeOptions.java:386)
at cucumber.runtime.RuntimeOptions.parse(RuntimeOptions.java:165)
at cucumber.runtime.RuntimeOptions.(RuntimeOptions.java:108)
There are 2 ways of implementing extent report in Cucumber
1. Using Cucumber-JVM 4 adapter for Extent Framework(extentreports-cucumber4-adapter) & below are the steps to implement -
Add adapter dependency under POM.XML
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports-cucumber4-adapter</artifactId>
<version>1.0.6</version>
</dependency>
Add the com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter plugin to the runner.
#RunWith(Cucumber.class)
#CucumberOptions(plugin = {"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"})
public class RunCukesTest {
// ..
}
Report Output Directory - ../Project Directory/test-output/HtmlReport
2. Adding aventstack dependency under POM.XML
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.1.5</version>
</dependency>
In this workflow, Do not Add the com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter plugin to the runner.
I had the same issue. you can use the following combination of dependencies,
Cucumber-core 4.2.0
Cucumber-java 4.2.0
Cucumber-junit 4.2.0
extentreports-cucumber4-adapter 1.0.7
Please note Cucumber-extntsreport which is developed by vimalselvam is not supporting cucumber version 4. Because cucumber 4 is using event based reporting, not the formatter.
so remove this dependency.
cucumber-extentsreport 3.0.2

httpbuilder and apache.poi.workbook maven problems

In Maven POM file I have the following:
<dependency>
<groupId>org.codehaus.groovy.modules.http-builder</groupId>
<artifactId>http-builder</artifactId>
<version>0.7.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.5</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>stax</groupId>
<artifactId>stax</artifactId>
<version>1.2.0</version>
</dependency>
I want to use Httpbuilder and Workbook in my project to parse Excel files.
def res = http.post("path": "....", "requestContentType": JSON, contentType: ContentType.BINARY)
Workbook book = WorkbookFactory.create(res.responseData)
Errors:
If I use my Maven dependencies
java.lang.LinkageError: loader constraint violation in interface itable
initialization: when resolving method "org.apache.xerces.dom.NodeImpl
If I add exclusion to stax or to httpbuilder
java.lang.NoSuchMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V
If I delete stax dependency
javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.EventFactory not found
Any ideas on how to use HttpBuilder with Workbook?
Exclude xerces from http-builder dependencies. In my case it solved problem
<dependency>
<groupId>org.codehaus.groovy.modules.http-builder</groupId>
<artifactId>http-builder</artifactId>
<version>0.7.1</version>
<exclusions>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
</exclusions>
</dependency>

java.lang.NoClassDefFoundError: Could not initialize class com.datastax.driver.core.Cluster

I have a maven project A
pom.xml for the project A :
<dependencies>
<dependency>
<groupId>com.app.cops</groupId>
<artifactId>cassandra-logging</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
pom.xml of the project cassandra-logging:
<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
<version>3.9.0.Final</version>
</dependency>
<dependency>
<groupId>com.codahale.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
The cops-logging projecct has the following code :
CassandraCopsComponentLogger.instance = new CassandraCopsComponentLogger();
String hosts = CassandraClientUtil.getHost();
String localDC = CassandraClientUtil.getLocalDC();
Cluster cluster;
if (StringUtils.isNotEmpty(localDC))
{
cluster = Cluster.builder().addContactPoints(hosts.split(","))
.withCredentials(CassandraCopsComponentLogger.USER_NAME, CassandraCopsComponentLogger.AUTH_CODE)
.withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.LOCAL_ONE))
.withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().withLocalDc(localDC).build())).build();
}
else
{
cluster = Cluster.builder().addContactPoints(hosts.split(","))
.withCredentials(CassandraCopsComponentLogger.USER_NAME, CassandraCopsComponentLogger.AUTH_CODE)
.withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.LOCAL_ONE)).build();
}
Session session = cluster.connect();
CassandraCopsComponentLogger.mappingManager = new MappingManager(session);
I keep on getting exception on the following line :
cluster = Cluster.builder().addContactPoints(hosts.split(","))
I have a unit test in cassandra-logging project which works fine with this code. But when I call the same code from project A I get the
java.lang.NoClassDefFoundError: Could not initialize class com.datastax.driver.core.Cluster
I was able to resolve this by downgrading the cassandra dependency version to <version>2.1.9</version>. Not sure how that helped but I was able to move forward.
Update the version of cassandra-driver-core and cassandra-driver-mapping to 3.3.0 - this worked for me:
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
<version>3.3.0</version>
</dependency>
I ran into similar issue. The error i got was :
Factory method 'sqlSession' threw exception;
nested exception is java.lang.NoClassDefFoundError: com/datastax/oss/protocol/internal/SegmentCodec
relevant pom.xml segment:
<properties>
..
<oss-java-driver.version>4.9.0</oss-java-driver.version>
..
</properties>
..
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-core</artifactId>
<version>${oss-java-driver.version}</version>
</dependency>
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-query-builder</artifactId>
<version>${oss-java-driver.version}</version>
</dependency>
Solution that worked for me : I have to explicitly declare dependency on native-protocol to override the version of native-protocol.
<properties>
..
<cassandra-native-protocol.version>1.4.11</cassandra-native-protocol.version>
..
</properties>
..
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>native-protocol</artifactId>
<version>${cassandra-native-protocol.version}</version>
</dependency>
Reference : https://community.datastax.com/answers/8185/view.html

arquillian #Drone injections always returning "about:blank" page

I am having this problem for 2 days now, and I am tending to think that something in my configuration is off. I'll post first my code and then explain:
public class MyTest extends Arquillian {
#Deployment(name = "MyPlatform", testable = false)
public static WebArchive createDeployment() {
WebArchive war;
war = ShrinkWrap
.create (WebArchive.class, "MyPlatform.war")
.merge (Maven
.resolver()
.loadPomFromFile("pom.xml")
.resolve("MyPlatform:My.Platform:war:0.0.1-SNAPSHOT")
.withoutTransitivity()
.asSingle(WebArchive.class));
return war;
}
#Drone
private PhantomJSDriver browser;
#ArquillianResource
private URL deploymentUrl;
#Test(dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER)
#RunAsClient
public void should_login_successfully(#InitialPage LoginPage loginPage) {
System.out.println ("ACTUAL: " + browser.getCurrentUrl ());
System.out.println ("DEPLOYMENT URL: " + deploymentUrl.toExternalForm ());
loginPage.login ("demo", "demo");
Assert.assertEquals (deploymentUrl.toExternalForm () + "index.tm", "https://127.0.0.1:8443/MyPlatform/index.tm");
}
The #ArquillianResource injection works fine, and shows the correct URL. However the #Drone injection shows "about:blank". after some testing i found something weird:
if my war file is called something like MyPlatform.blabla.war, then the Drone trancates after the first "dot" and i get "http://127.0.0.1:8080/MyPlatform/login.tm" which is not what i deployed...so for some reason the #Drone is always trancating my deployment URL and cant seem to find the root of it.
here is my POM just in case
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-api-maven</artifactId>
<version>2.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap</groupId>
<artifactId>shrinkwrap-api</artifactId>
<version>1.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<version>1.1.2.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap</groupId>
<artifactId>shrinkwrap-impl-base</artifactId>
<version>1.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<version>2.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.2.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-drone-bom</artifactId>
<version>1.2.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.graphene</groupId>
<artifactId>graphene-webdriver</artifactId>
<version>2.0.1.Final</version>
<type>pom</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.graphene</groupId>
<artifactId>graphene-webdriver-spi</artifactId>
<version>2.0.1.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.graphene</groupId>
<artifactId>graphene-webdriver-impl</artifactId>
<version>2.0.1.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-remote</artifactId>
<version>7.1.1.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.testng</groupId>
<artifactId>arquillian-testng-container</artifactId>
<version>1.1.2.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>bsh</groupId>
<artifactId>bsh</artifactId>
<version>2.0b4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.1</version>
<scope>test</scope>
</dependency>
I would be greatful if someone can help me in solving this pickle..!
Typical, After I posted the question i found the problem, and it was simply that my applicaiton is running over SSL and phantomjs is not redirecting from 8080 -> 8443...
Now to figure out how to do this ...

Resources