Monday, 5 January 2015

BDD JVM Cucumber with masterthoughts reporting pom.xml workable

<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>org.stag.simplecucumber</groupId>
    <artifactId>simple-cucumber-jvm</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <cucumber-jvm.version>1.0.11</cucumber-jvm.version>
        <selenium.version>2.44.0</selenium.version>
        <junit.version>4.11</junit.version>
        <picocontainer.version>2.13.6</picocontainer.version>
        <cucumber-reporting.version>0.0.17</cucumber-reporting.version>
    </properties>
    
    
    <repositories>
       <repository>
           <id>repo.bodar.com</id>
           <url>http://repo.bodar.com</url>
       </repository>
       <repository>
                <id>sonatype-releases</id>
                <url>https://oss.sonatype.org/content/repositories/releases/</url>
            </repository>
   </repositories>

  
    <dependencies>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>${cucumber-jvm.version}</version>
            <scope>test</scope>
        </dependency>
        
         <dependency>
           <groupId>com.googlecode.totallylazy</groupId>
           <artifactId>totallylazy</artifactId>
           <version>1077</version>
   </dependency>
         
             <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.0</version>
            <scope>test</scope>
        </dependency>
   <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
        </dependency>
        <dependency>
            <groupId>org.picocontainer</groupId>
            <artifactId>picocontainer</artifactId>
            <version>${picocontainer.version}</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>${selenium.version}</version>
        </dependency>
      <dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
      
        <dependency>
            <groupId>net.masterthought</groupId>
            <artifactId>cucumber-reporting</artifactId>
            <version>${cucumber-reporting.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.10</version>
                <configuration>
                    <skipTests>false</skipTests>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.masterthought</groupId>
                <artifactId>maven-cucumber-reporting</artifactId>
                <version>0.0.5</version>
                <executions>
                    <execution>
                        <id>execution</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <projectName>cucumber-jvm-example</projectName>
                            <outputDirectory>${project.build.directory}/cucumber-html-reports</outputDirectory>
                            <cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
                
                            <enableFlashCharts>false</enableFlashCharts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
             
        </plugins>
    </build>


</project>

org.junit.runner.Description.createSuiteDescription(Ljava/lang/String;Ljava/io/Serializable;[Ljava/lang/annotation/Annotation;)Lorg/junit/runner/Description

org.junit.runner.Description.createSuiteDescription(Ljava/lang/String;Ljava/io/Serializable;[Ljava/lang/annotation/Annotation;)Lorg/junit/runner/Description

I found the cause of this the problem is that the cucumber.json file does not exist.

I addressed this in my project by adding json:target under the @CucumberOptions annotation, this then generated the json. for example @CucumberOptions(features = "src/test/resources/features/some.feature", monochrome = false, format = {"pretty", "json:target/cucumber.json"})

The masterthought plugin then processes the generated JSON by looking for it at ${project.build.directory}/cucumber.json

At this point the Maven plugin generates the HTML from the JSON.


For this you have to setup as below at both the places

and in Junit runner .. mention "json:target/cucumber.json" problem will resolve.


package skeleton;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(format = {
        "pretty","html:target/cucumber-html-reports","json:target/cucumber.json" })


public class RunCukesTest {
}



In pom.xml do like this
 <plugin>
                <groupId>net.masterthought</groupId>
                <artifactId>maven-cucumber-reporting</artifactId>
                <version>0.0.5</version>
                <executions>
                    <execution>
                        <id>execution</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <projectName>cucumber-jvm-example</projectName>
                            <outputDirectory>${project.build.directory}/cucumber-html-reports</outputDirectory>
                            <cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
                
                            <enableFlashCharts>false</enableFlashCharts>
                        </configuration>
                    </execution>
                </executions>

            </plugin>


References

https://github.com/masterthought/maven-cucumber-reporting-mojo

http://www.masterthought.net/section/cucumber-reporting-downloads

Tuesday, 30 December 2014

pom.xml does not exist selenium java

pom.xml does not exist selenium java

In your pom.xml you are using modules..  so  you have to include

There must absolutely be a pom.xml file under projectName, and it must have an artifact id that matches the one under the parent declaring the module, i.e.

<artifactId>projectName</artifactId>


OR else

use this on pom.xml


<packaging>pom</packaging>


http://stackoverflow.com/questions/26021141/maven-child-module-does-not-exist

Project build error: 'packaging' with value 'jar' is invalid. Aggregator projects require 'pom' as packaging.

Project build error: 'packaging' with value 'jar' is invalid. Aggregator projects require 'pom' as packaging.

Add this to your pom.xml it solves the problem.
 
 
  <packaging>pom</packaging>
 
 
  if the parent project contains source code, I strongly suggest you to:

move this code in a new module (let's call it commons)
make commons a child module of your parent project
add the commons module as a dependency of all other modules requiring it (maybe all of them)
add <packaging>pom</packaging> in the parent pom.xml


More details you can have a look on this...

Thursday, 11 December 2014

How to wait until the element is present or load a banner in selenium java cucumber

Here the way how to wait until the element is present .

there are many ways to do this..

Thread.sleep(1000) is old static way of doing...

If you are waiting to load any image or banner or progress bar then you have to use javascriptexecutor technique

Another trick is to realise that the WebDriver instances implement JavascriptExecutor. This interface can be used to execute arbitrary Javascript within the context of the browser (a trick selenium finds much easier). This allows us to use the state of javascript variables to control the test. For example – we can have a variable populated once some asynchronous action has completed; this can be the trigger for the test to continue.

First, we add some Javascript to our example page above. Much as before, it simply loads a new page and updates the <div> with this content. This time, rather than show the div, it simply sets a variable – “working” – so the div can be visible already.

   

 /**
 * Call this method before an event that will change the page.
 */
private void beforePageLoad() {
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("document.mpPageReloaded='notYet';");
}

/**
 * Call this method after an event that will change the page.
 *
 * @see #beforePageLoad
 *
 *      Waits for the previous page to disappear.
 */
private void afterPageLoad() throws Exception {
    (new WebDriverWait(driver, 10)).until(new Predicate<WebDriver>() {

        @Override
        public boolean apply(WebDriver driver) {
            JavascriptExecutor js = (JavascriptExecutor) driver;
            Object obj = js.executeScript("return document.mpPageReloaded;");
            if (obj == null) {
                return true;
            }
            String str = (String) obj;
            if (!str.equals("notYet")) {
                return true;
            }
            return false;
        }
    });
}

 http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/JavascriptExecutor.html

http://stackoverflow.com/questions/5868439/wait-for-page-load-in-selenium

Way 1:

WebDriverWait wait = new WebDriverWait(driver, 15);
  wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath here")));
 
  System.out.print("Text box text3 is now visible");

Way 2:

In webdriver:
driver.findElement(By.id("")).isSelected or Enabled or Displayed)
{
//actions
Do some thing...
}

Way 3:

 //To verify element is present on page or not.
   String XPath = "//input[@id='text"+i+"']";
   Boolean iselementpresent = driver.findElements(By.xpath(XPath)).size()!= 0;
   if (iselementpresent == true)
   {
    System.out.print("element present..");
   }
   else
   {
    System.out.print("Element is not present");
   }


Way 4:

  if(selenium.isElementPresent(objectId)) 
//** it will check for the ObjectID in the Input sheet
                    {
                        driver.findElement(By.id(objectId)).clear();
 //** it will execute ,once it got the respective ObjectID

 }

Ref

http://stackoverflow.com/questions/20903231/selenium-wait-until-element-is-present

http://www.selenium-automation.co.uk/blog/selenium-iselementpresent-in-webdriver/

http://stackoverflow.com/questions/19851518/selenium-webdriver-wait-for-element-to-be-present-when-locating-with-webdriver

Wednesday, 24 September 2014

Easy to use editor to navigate from feature files to step definations for jvm Cucumber in eclipse

To navigate from feature files to step definitions easily .. you can use this Natural plug in.  
You can download this file from here

https://github.com/rlogiacco/Natural/wiki/Installation-Guide

Download Natural.zip file manually to your local machine

Open Eclipse 
Help-> Install New software

On available software click on Add button

Click on Archive button choose Nature.zip file and install .

Restart Eclipse 

If you are not sure how to archive file you can get help here
http://help.eclipse.org/indigo/index.jsp?topic=/org.eclipse.platform.doc.user/tasks/tasks-127.htm


Now it will works.

Friday, 19 September 2014

How to check whether css selector is correct or not in Chrome selenium inspect elements

How to check whether css selector is correct or not in Chrome selenium inspect elements


Open Chrome browser
Right Click on any element click Inspect elements as a result you will get development tool

Select Console Tool there


And after that


$$(" here give your css selector path ")

for xpath we can check like this
$x('//*[@id="header-container"]')

And click enter path should select .