Null pointer exception while using Cucumber and Arquillian
suchita880 Jul 29, 2015 4:03 AMHi,
I am using Arquillian + selenium and cucumber but while running cucumber feature file @drone and @Page is not getting initialized. Even got the exception - "The Graphene runtime isn't initialized" and NullPointerException for the browser. I agree that Cucumber and Arquillian life cycle but how can I use both. Please see the code snippet for the reference.
Graphene Exception:
java.lang.IllegalStateException: The Graphene runtime isn't initialized.
at org.jboss.arquillian.graphene.GrapheneRuntime.getInstance(GrapheneRuntime.java:116)
at org.jboss.arquillian.graphene.Graphene.instance(Graphene.java:323)
at org.jboss.arquillian.graphene.Graphene.waitAjax(Graphene.java:163)
at com.ec.ecpa.util.LoginScreenTest.should_login_successfully(LoginScreenTest.java:36)
at ?.Given logindetails(C:/EC11/ecproductautomation/src/test/resources/it/feature/logindetails.feature:4)
Code Snippet:
LoginScreenTest.java file:
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.graphene.page.Page;
import org.jboss.arquillian.junit.Arquillian;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
import com.ec.ecpa.pages.LoginPage;
import com.ec.ecpa.pages.frmw.co.manageTable.SystemAttributePage;
import cucumber.api.java.Before;
import cucumber.api.java.en.Given;
@RunWith(Arquillian.class)
public class LoginScreenTest {
@Drone
WebDriver browser;
@Page
LoginPage loginPage;
@Page
SystemAttributePage systemAttributePage;
@Before
public void init(){
/*browser = new FirefoxDriver();
systemAttributePage = new SystemAttributePage();
Graphene.waitAjax();*/
}
@Given("logindetails")
public void should_login_successfully() throws Exception {
browser.get("http://www.google.com/");
}
}
Login.feature file:
Feature: login details
Scenario: logindetails
Given logindetails
Pom.xml file:
<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.ec.ecpa</groupId>
<artifactId>ecpa</artifactId>
<version>11.0.SP01-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ui-test</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- our default browser if no profile is specified -->
<browser>chrome</browser>
<remotebrowser>false</remotebrowser>
<chromedriverpath>${selenium.chromedriverpath}</chromedriverpath>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.testSource>1.7</maven.compiler.testSource>
<maven.compiler.testTarget>1.7</maven.compiler.testTarget>
</properties>
<profiles>
<profile>
<id>firefox</id>
<properties>
<browser>firefox</browser>
</properties>
</profile>
<profile>
<id>phantomjs</id>
<properties>
<browser>phantomjs</browser>
</properties>
</profile>
<profile>
<id>chrome</id>
<properties>
<browser>chrome</browser>
</properties>
</profile>
</profiles>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.7.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-drone-bom</artifactId>
<version>2.0.0.Alpha3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.graphene</groupId>
<artifactId>graphene-webdriver</artifactId>
<version>2.1.0.Alpha2</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ojdbc</groupId>
<artifactId>ojdbc</artifactId>
<version>14</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.graphene</groupId>
<artifactId>graphene-webdriver</artifactId>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.arquillian.extension</groupId>
<artifactId>arquillian-recorder-reporter-impl</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.graphene</groupId>
<artifactId>arquillian-browser-screenshooter</artifactId>
<version>2.1.0.Alpha2</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<!-- test resource filtering evaluates ${browser} expression in arquillian.xml -->
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Arquillian.xml File:
<?xml version="1.0" encoding="UTF-8"?>
<arquillian>
<extension qualifier="drone">
<property name="instantiationTimeoutInSeconds">0</property>
</extension>
<extension qualifier="webdriver">
<property name="browser">${browser}</property>
<property name="platform">ANY</property>
<property name="version">ANY</property>
<property name="chromeDriverBinary">${chromedriverpath}</property>
<property name="remoteReusable">${remotebrowser}</property>
<property name="remoteAddress">${gridhubaddress}</property>
<property name="reuseCookies">true</property>
</extension>
<!-- <extension qualifier="graphene">
<property name="waitGuiInterval">30</property>
<property name="waitAjaxInterval">60</property>
<property name="waitModelInterval">120</property>
<property name="waitGuardInterval">60</property>
</extension> -->
<extension qualifier="graphene">
<property name="waitGuiInterval">3</property>
</extension>
<extension qualifier="reporter">
<property name="report">html5</property>
<property name="file">arquillian_report</property>
<property name="reportAfterEvery">class</property>
<property name="maxImageWidth">500</property>
<property name="imageWidth">100</property>
<property name="imageHeight">100</property>
</extension>
<extension qualifier="screenshooter">
<property name="takeWhenTestFailed">true</property>
<property name="rootDir">target</property>
<property name="takeBeforeTest">false</property>
<property name="takeAfterTest">true</property>
</extension>
</arquillian>
Message was edited by: Suchita Bhalerao