Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
4.8k views
by The go-to Tester (218 points)
retagged by

I am getting error runing maven test in Ubuntu
 

public class Test1 {

    @Test
    public void GoogleTest() {
        String OS = System.getProperty("os.name").toLowerCase();
        // Create a new instance of the Firefox driver
        // Notice that the remainder of the code relies on the interface,
        // not the implementation.
        if(OS.contains("windows")){
            System.setProperty("webdriver.gecko.driver", "src/test/resources/com/guidomaiola/cucumber/selenium/example/windows/geckodriver.exe");
        }else if(OS.contains("linux")){
            System.setProperty("webdriver.gecko.driver", "src/test/resources/com/guidomaiola/cucumber/selenium/example/unix/geckodriver");
        }
        
        WebDriver driver = new FirefoxDriver();

        // And now use this to visit Google
        driver.get("http://www.google.com");
        // Alternatively the same thing can be done like this
        // driver.navigate().to("http://www.google.com");

        // Find the text input element by its name
        WebElement element = driver.findElement(By.name("q"));

        // Enter something to search for
        element.sendKeys("Cheese!");

        // Now submit the form. WebDriver will find the form for us from the
        // element
        element.submit();

        // Check the title of the page
        System.out.println("Page title is: " + driver.getTitle());

        // Google's search is rendered dynamically with JavaScript.
        // Wait for the page to load, timeout after 10 seconds
        (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver d) {
                return d.getTitle().toLowerCase().startsWith("cheese!");
            }
        });

        // Should see: "cheese! - Google Search"
        System.out.println("Page title is: " + driver.getTitle());

        // Close the browser
        driver.quit();
    }
}

 

The error is
 

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.guidomaiola.cucumber.selenium.example.Test1
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.263 sec <<< FAILURE! - in com.guidomaiola.cucumber.selenium.example.Test1
GoogleTest(com.guidomaiola.cucumber.selenium.example.Test1)  Time elapsed: 0.184 sec  <<< ERROR!
java.lang.IllegalStateException: The driver executable does not exist: /home/guido/workspace-selenium-cucumber-java/Selenium-example/src/test/resources/com/guidomaiola/cucumber/selenium/example/unix/geckodriver
at com.google.common.base.Preconditions.checkState(Preconditions.java:518)
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:123)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:118)
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 com.guidomaiola.cucumber.selenium.example.Test1.GoogleTest(Test1.java:25)

Results :

Tests in error:
 Test1.GoogleTest:25 &raquo; IllegalState The driver executable does not exist: /home...

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.334 s
[INFO] Finished at: 2017-03-29T11:38:23-03:00
[INFO] Final Memory: 21M/204M

 

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)
selected by
 
Best answer

As your stacktrace says, the executable does not exist at below location.

/home/guido/workspace-selenium-cucumber-java/Selenium-example/src/test/resources/com/guidomaiola/cucumber/selenium/example/unix/geckodriver

Make sure the path is correct and you have necessary permission to access the file. You might want to change permission of the file.

Let us know more about the location and permission of the file. 

by The go-to Tester (218 points)
There was error because path was wrong. But how can I write code that is platform independent.
by The go-to Tester (181 points)
Existing implementation you have using "os.name" is good.

We usually keep driver files directly inside work-space, here your work-space is "Selenium-example" folder. So inside that you can create a new folder called driver and there you can keep all your driver binaries.

So, inside the code, I can just call it as

System.setProperty("webdriver.gecko.driver", "driver/geckodriver");


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...