Hot questions for Using Cucumber in jenkins

Question:

I'm trying to click a button on top of the page.I'm using CSS selector and it works perfectly fine when I run it in my local eclipse.But when I try to run it on Jenkins server on my local machine it fails, saying element not clickable. When I saw the screenshot of failed test on Jenkins I see that the header is overlapping the button that I want to click. I have tried almost everything using XPath,CSS,move to element,move mouse. But still can't fix it, Someone please help.

I'm tring to click on add buttoun

org.openqa.selenium.WebDriverException: Element is not clickable at point (775.25, 10.166671752929688). Other element would receive the click: <div class="globalHeader-UtilTop"></div>
Command duration or timeout: 69 milliseconds
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host', ip: '', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_80'

<div class="Componet-intels**strong text**-Container">
<div class="Componet-intels-Container-Header">
<div class="Componet-intels-Container-Content">
<div class="Componet-intels-Container-Content-Row">
<span class="Componet-intels-Item"> Item # </span>
<span class="Componet-intels-Text-Item">
<span class="Componet-intels-Lable-Quantity"> Qty: </span>
<span class="Componet-intels-Text-Quantity">
<span class="Componet-intels-Button">
**<input class="Componet-intelsButtonIcon" type="button" value="Add">**
</span>
</div>

Answer:

Element is not clickable at point (775.25, 10.166671752929688). Other element would receive the click:

It clearly says, the element we want to click is hidden by some other element div in this case, which would receive the click.

I think it is a problem with the UI and the header shouldn't hide the element, but you can try few things :

  1. Maximize the window of the browser from webdriver to see if header still hides the element

    driver.manage().window().maximize() 
    
  2. Use JavaScript to click element

    WebElement element = driver.findElement(By.<locator>);
    JavascriptExecutor executor = (JavascriptExecutor)driver;
    executor.executeScript("arguments[0].click()", element)`
    

Question:

I have created a testing framework using Cucumber, Selenium and Maven. I am using the cucumber-jvm-parallel plugin to run my tests in parallel. Below is how my pom.xml looks:

<?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.tests</groupId>
<artifactId>test-project</artifactId>
<version>1.0</version>

<name>Test Project</name>
<properties>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <cucumber.version>1.2.3</cucumber.version>
    <extentreports.version>2.41.0</extentreports.version>
    <selenium.version>2.53.1</selenium.version>
    <cucumber.jvm.parallel.version>2.1.0</cucumber.jvm.parallel.version>
</properties>

<dependencies>
    <dependency>
        <groupId>com.github.temyers</groupId>
        <artifactId>cucumber-jvm-parallel-plugin</artifactId>
        <version>${cucumber.jvm.parallel.version}</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber.version}</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>
    <dependency>
        <groupId>org.assertj</groupId>
        <artifactId>assertj-core</artifactId>
        <version>1.7.0</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>${selenium.version}</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>${cucumber.version}</version>
    </dependency>
    <dependency>
        <groupId>com.sitture</groupId>
        <artifactId>cucumber-jvm-extentreport</artifactId>
        <version>1.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.directory.studio</groupId>
        <artifactId>org.apache.commons.codec</artifactId>
        <version>1.8</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>1.2.3</version>
    </dependency>
    <dependency>
        <groupId>com.vimalselvam</groupId>
        <artifactId>cucumber-extentsreport</artifactId>
        <version>1.1.1</version>
    </dependency>

</dependencies>
<profiles>
    <profile>
        <id>win</id>
        <activation>
            <os>
                <family>windows</family>
            </os>
        </activation>
        <properties>
            <webdriver.chrome.path>${basedir}${file.separator}resources${file.separator}chromedriver.exe</webdriver.chrome.path>
        </properties>
    </profile>
    <profile>
        <id>linux</id>
        <activation>
            <os>
                <family>!windows</family>
            </os>
        </activation>
        <properties>
            <webdriver.chrome.path>resources${file.separator}chromedriver</webdriver.chrome.path>
        </properties>
    </profile>
</profiles>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <fork>true</fork>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.github.temyers</groupId>
            <artifactId>cucumber-jvm-parallel-plugin</artifactId>
            <version>${cucumber.jvm.parallel.version}</version>
            <executions>
                <execution>
                    <id>generateRunners</id>
                    <phase>generate-test-sources</phase>
                    <goals>
                        <goal>generateRunners</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/generated-test-sources/cucumber</outputDirectory>
                        <featuresDirectory>src/test/resources/features</featuresDirectory>
                        <cucumberOutputDir>target/cucumber-parallel</cucumberOutputDir>
                        <format>json,html,rerun</format>
                        <strict>true</strict>
                        <monochrome>true</monochrome>
                        <useTestNG>false</useTestNG>
                        <namingPattern>Parallel{c}IT</namingPattern>
                        <namingScheme>simple</namingScheme>
                        <parallelScheme>FEATURE</parallelScheme>
                        <glue>com.cucumber.stepdefinitions</glue>
                        <tags>"~@ignore"</tags>
                        <filterFeaturesByTags>true</filterFeaturesByTags>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19</version>
            <configuration>
                <additionalClasspathElements>
                    <additionalClasspathElement>resources</additionalClasspathElement>
                </additionalClasspathElements>
                <!-- Increase Fork Count to increase parallel execution count.
                Currently it is set to 2 which means 2 runners will run in parallel-->
                <forkCount>2</forkCount>
                <reuseForks>true</reuseForks>
                <includes>
                    <include>**/Parallel*IT.java</include>
                </includes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.2.1</version>
            <executions>
                <execution>
                    <id>default</id>
                    <goals>
                        <goal>perform</goal>
                    </goals>
                    <configuration>
                        <pomFileName>${basedir}${file.separator}pom.xml</pomFileName>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

I use

mvn clean install

to run my suite. After the run is complete, I have a downstream job configured in Jenkins that generates some failed cases file. I create separate runners for these. Now I was looking to rerun failed test cases and I have created files called failedScenario1.java, failedScenario2.java and so on. I would now like to run these. I am assuming I need to define something similar to org.apache.maven.plugins in the above POM and trigger the run. Can someone please let me know how I can include this in the same POM. Also how can I trigger this run for failedScenario*.java.


Answer:

I'm afraid this is not possible exactly as you like within the same POM.

You would need something like the following:

  <profiles>
    <profile>
      <id>suite</id>
      <activation>
        <property>
          <name>re-test</name>
          <value>!true</value>
        </property>
      <activation>

      ... your suite's declarations ...

    </profile>

    <profile>
      <id>failed-scenario</id>
      <activation>
        <property>
          <name>re-test</name>
          <value>true</value>
        </property>
      <activation>
      <build>
        <testSourceDirectory>${project.build.directory}/generated-test-sources/cucumber</testSourceDirectory>
        <plugins>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
              <executions>
                <execution>
                  <id>failed-scenario-test-compile</id>
                  <goals>
                    <goal>testCompile</goal>
                  </goals>
                </execution>
              </executions>
            ...
         <plugin>
           <artifactId>maven-surefire-plugin</artifactId>
             ...  

But, see Introduction to Build Profiles, Profiles in POMs:

Profiles specified in the POM can modify the following POM elements:

  • ...

  • a subset of the <build> element, which consists of:

    <defaultGoal>

    <resources>

    <testResources>

    <finalName>

So, <testSourceDirectory> is missing there.

If you'd generate-test-sources to the default <testSourceDirectory>${project.basedir}/src/test/java you could use the maven-surefire-plugin's <excludes>/<includes> in the re-test profile. The drawback is that all the failedScenarioX will be also run the next time you build your suite, unless you delete them before.

Question:

I'm able to generate the HTML report for cucumber on Jenkins.But I would like to know if there is any way to convert that HTML to pdf as a post build action or send the HTML report without losing any format. I'm able to send the HTML report to email but it's not formatted.It is missing the folder structure. Plugin I'm using as post build action is Editable Email Notification and in Attachments I give this , js/,fonts/,embeddings/,css/* .

Any help would be greatly appreciated.


Answer:

I've done this a while ago via 3th party service. You can use this htmlpdf site and send a request with form-data URL parameter (or there is stand-alone app as well) or this html2pdfrocket API.

In case you are looking just for the content as image, you can create dedicated build step using Selenium's screenshot option and add it as attachment in the email body.

Question:

I want to configure cucumber report tool in Bamboo. It has procedure to do it in Jenkins.

https://github.com/damianszczepanik/cucumber-reporting

I know there are bunch of plugins available in marketplace. But I don't need them. Did anyone succeeded in configuring the damian's cucumber report plugin in Bamboo.

Thanks


Answer:

As this plugin generates HTML report you can create artifact in Bamboo to include that report as build artifact. Then you will see it in artifact list and view it via web browser. It will be not inlined into Bamboo UI, but you can view test results anyway

Question:

I have a Automation test scripts which are running fine Jenkins Master but on slaves it is giving below error:

11:47:50 [ERROR] Failed to execute goal com.github.temyers:cucumber-jvm-parallel-plugin:4.2.0:generateRunners (generateRunners) on project riverbed-automation-tests: Unable to parse configuration of mojo com.github.temyers:cucumber-jvm-parallel-plugin:4.2.0:generateRunners for parameter tags: Cannot assign configuration entry 'tags' with value '"~@ignored"' of type java.lang.String to property of type java.util.List -> [Help 1]
11:47:50 org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.temyers:cucumber-jvm-parallel-plugin:4.2.0:generateRunners (generateRunners) on project riverbed-automation-tests: Unable to parse configuration of mojo com.github.temyers:cucumber-jvm-parallel-plugin:4.2.0:generateRunners for parameter tags: Cannot assign configuration entry 'tags' with value '"~@ignored"' of type java.lang.String to property of type java.util.List
11:47:50    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:221)
11:47:50    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
11:47:50    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
11:47:50    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
11:47:50    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
11:47:50    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
11:47:50    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
11:47:50    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
11:47:50    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
11:47:50    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
11:47:50    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
11:47:50    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
11:47:50    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
11:47:50    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
11:47:50    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
11:47:50    at java.lang.reflect.Method.invoke(Method.java:498)
11:47:50    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
11:47:50    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
11:47:50    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:414)
11:47:50    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:357)

this Cucumber java junit project with Serenity. Only difference between master and slave is that Xvfb (headless browser) is working on Master but not on Slave, but since it looks a Maven or Cucumber error I doubt Xvfb has anything to with it.

What am I doing wrong?


Answer:

Check https://github.com/temyers/cucumber-jvm-parallel-plugin There is stated:

As of cucumber-jvm:4.0.0 parallel execution is supported natively by cucumber. As such, upgrading to Cucumber 4.0.0 is recommended and this plugin is no longer maintained.

So consider leave cucumber-jvm-parallel-plugin

It looks like you have in your pom.xml something like

<tags>"~@ignore"</tags>

try to change it to

    <tags>
      <tag>~@ignore</tag>
    </tags>

BTW proper new style is now not @ignore check https://github.com/cucumber/cucumber/tree/master/tag-expressions#migrating-from-old-style-tags

Question:

I have created a java project which has implemented cucumber and Junit. When I am running the project from my IDE the reports and snapshots are generating finely but after pushing the code when my build is run by Jenkins, none of the reports and snapshot is generating in my workspace. My build also showing success without any issue, just the files are not created.

Configuration :-

  • Window 10
  • Jenkins.war -> Jenkins ver. 2.74

I am using the below command from terminal which is working fine

mvn clean install

In Jenkins maven plug-in, I have set goal as

clean install

I have also giving Full control permission to Jenkins war from properties->security.

It looks like a permission issue to me but what exactly it is?

I have also change the workspace from c driver to d still facing the same issue


Answer:

In configure -> build -> Root POM, the path of POM file should be of your Jenkins workspace projects not of your local/development env

Question:

in my project am using cucumber junit ANT.

am running 10 scenarios from jenkins, if some scenarios fails how to run only that scenarios again.

my test ruuner class

@RunWith(Cucumber.class)

@CucumberOptions(
    features = "Feature Files"

    ,plugin = {"json:target/cucumber-json-report.json","html:target/html/"}
    ,glue={"com.mlc.testDefinitionLayer"}
    ,tags ={"@Tag1,@tag2,@tag3,@tag4"}  

  )

public class TestRunner {

    public static void main(String[] args) {

    }
}

if not possible from Jenkins, at least can I read from excel sheet data like include/exclude inputs... and call java function(excel logic to read data) in test runner class and pick include(data in excel) test cases in tags.


Answer:

Cucumber offers a solution to rerun the failed scenarios.

It mentions it in the docs here.

When you run cucumber you add a rerun formatter

cucumber -f rerun --out rerun.txt 

This rerun.txt contains the failed scenarios. You can rerun them with:

cucumber @rerun.txt

In Jenkins this means adding another build step that will execute that command.