Do you have questions ? We got the answers!

Ask a question:

0
I am setting up selenium 3 with cucumber and this is the error I am getting: java.lang.IllegalStateException:

Open 1 Answers 60 Views

Here's my pom.xml:
 

<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>selenium-cucumber</groupId>
    <artifactId>selenium-cucumber-java</artifactId>
    <version>0.0.1</version>
    <packaging>jar</packaging>
    <name>selenium-cucumber-java</name>

    <dependencies>
        <!-- These are the cucumber dependencies -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>

        <!-- These are the cucumber-junit dependencies -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.2</version>
            <scope>test</scope>
        </dependency>

        <!-- These are the junit dependencies -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        
        <!-- These are the selenium-webdriver dependencies -->    
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.3.1</version>
        </dependency>
    
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>3.3.1</version>
        </dependency>
        
        <!-- These are the selenium-cucumber methods dependencies -->
        <dependency>
            <groupId>sample</groupId>
            <artifactId>com.sample</artifactId>
            <version>1.0.0</version>
            <type>jar</type>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/resources/selenium-cucumber-methods-1.0.0.jar</systemPath>
        </dependency>  
    </dependencies>

    
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArgument>-Werror</compilerArgument>
                    
                    <systemPropertyVariables>
                        <property>
                            <name>browser</name>
                            <value>${browser}</value>
                         </property>
                     </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Browser: Firefox
 

[31mFailed scenarios:[0m
[31mfeatures/my_first.feature:4 [0m# Scenario: I login with valid credential

1 Scenarios ([31m1 failed[0m)
7 Steps ([31m1 failed[0m, [36m6 skipped[0m)
0m0.403s

java.lang.ExceptionInInitializerError
    at stepDefintions.PredefinedStepDefinitions.navigate_to(PredefinedStepDefinitions.java:20)
    at ✽.Given I navigate to "http://www.gmail.com"(features/my_first.feature:5)
Caused by: java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases
    at com.google.common.base.Preconditions.checkState(Preconditions.java:738)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:111)
    at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:38)
    at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:112)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:302)
    at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:233)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:121)
    at env.Env.CreateWebDriver(Env.java:35)
    at env.BaseTest.<clinit>(BaseTest.java:18)
    at stepDefintions.PredefinedStepDefinitions.navigate_to(PredefinedStepDefinitions.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at cucumber.runtime.Utils$1.call(Utils.java:40)
    at cucumber.runtime.Timeout.timeout(Timeout.java:16)
    at cucumber.runtime.Utils.invoke(Utils.java:34)
    at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:38)
    at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
    at cucumber.runtime.Runtime.runStep(Runtime.java:300)
    at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
    at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
    at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:91)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:93)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:37)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.api.junit.Cucumber.run(Cucumber.java:98)

 

1 Answer

1

You will have to set PATH environment variable to set gekoriver.

Download gekodriver from here: https://github.com/mozilla/geckodriver/releases

You have to append the path to the directory containing gekodriver binary to your PATH environment variable value string.

Eg.

In Unix based system,

export PATH = $PATH:/path/to/directory/of/gekodriver/executable/

in windows based system,

setx path "%path%;c:\path\to\gekodriver\dir"

And, in webdriver.Firefox construction, do not pass anything. Provided that your Firefox is installed at the default location.

So, your code should look like below.

def setUp(self):
        //gecko = os.path.normpath(os.path.join(os.path.dirname(__file__), 'geckodriver'))
        //self.driver = webdriver.Firefox(executable_path=gecko+'.exe')

        self.driver = webdriver.Firefox()

answered Apr 7 by stbadmin (4,970 points)

Top Contributors

  • 4970 pointsstbadmin

    34 questions 454 answers218 comments

  • 433 pointsSunilBhaskar

    41 questions 15 answers32 comments

  • 425 pointsMehedi

    36 questions 3 answers14 comments

  • 363 pointssumitkumarwatts

    0 questions 13 answers0 comments

  • 354 pointsSoft Tester

    43 questions 0 answers4 comments

  • 327 pointsKeeshaGolden

    0 questions 17 answers2 comments

  • 322 pointsVipul Sharma

    44 questions 0 answers24 comments

  • 310 pointsvysh.sharma

    25 questions 0 answers0 comments

  • 267 pointsOnkar_Nimje

    33 questions 15 answers15 comments

  • 258 pointsVanitha

    26 questions 0 answers6 comments

...