Selenium Grid: Not able to create Gecko Driver Session [duplicate] - selenium

I fail to drive Firefox from Selenium with geckodriver. This is odd, because chrome is driven with same framework without errors!
These are my Version numbers:
Firefox 54.0 (64-bit)
Chrome Version 62.0.3202.94 (Official Build) (64-bit)
selenium-server-standalone-3.7.1.jar
client-combined-3.5.3-nodeps.jar
geckodriver-v0.19.1-linux64
chromedriver_linux64
Ubuntu 16.10
The error I get from Selenium webdriver with java is the following:
--------------------------------Error:
leder#leder-VirtualBox:~/Source/SeleniumCheese/bin$ ./execute_grid.sh
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new service: GeckoDriverService
Build info: version: '3.7.1', revision: '8a0099a', time: '2017-11-06T21:07:36.161Z'
System info: host: 'leder-VirtualBox', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.8.0-59-generic', java.version: '1.8.0_131'
Driver info: driver.version: unknown
Command duration or timeout: 1.39 seconds
---------------------------------Schnapp
This is my setup, where firefox is broken and chrome is OK:
Grid_SetUp.java
package de.auticon.selenium_server;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.MalformedURLException;
import java.net.URL;
public class Grid_SetUp {
public static WebDriver driver;
public static void main(String[] args) throws MalformedURLException, InterruptedException{
System.setProperty("webdriver.chrome.driver","/opt/selenium/chromedriver");
String URL = "http://www.google.de";
String Node = "http://192.168.40.40:4444/wd/hub";
DesiredCapabilities cap = DesiredCapabilities.firefox();
driver = new RemoteWebDriver(new URL(Node), cap);
driver.navigate().to(URL);
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());
Thread.sleep(5000);
driver.quit();
}
}
selenium_grid.sh:
#!/bin/bash
java -jar /opt/selenium/selenium-server-standalone-3.7.1.jar -role hub &
java -Dwebdriver.gecko.driver=/opt/selenium/geckodriver -jar /opt/selenium/selenium-server-standalone-3.7.1.jar -role webdriver -hub http://192.168.40.40:4444/grid/register -nodeConfig /opt/selenium/defaultNodeConfig.json -browser "browserName=firefox,platform=LINUX" &
execute_grid.sh:
#!/bin/bash
java -cp ".:/opt/selenium/selenium-server-standalone-3.7.1.jar" de.auticon.selenium_server.Grid_SetUp
I updated the question for working configuration now. But when running the firefox Selenium TC the TC completes, unfortunately the server ends with an error message "session not created":
13:49:10.376 INFO - Removing session org.openqa.selenium.remote.server.ServicedSession#70c81601
13:49:10.381 INFO - To downstream: {"value":{"error":"session not created","message":"Tried to run command without establishing a connection","stacktrace":"stack backtrace:\n 0: 0x4edb3c - backtrace::backtrace::trace::hc4bd56a2f176de7e\n 1: 0x4edb72 - backtrace::capture::Backtrace::new::he3b2a15d39027c46\n 2: 0x4409a1 - webdriver::error::WebDriverError::new::h81babdd86c977032\n 3: 0x4280ea - <webdriver::server::Dispatcher<T, U>>::run::h2119c674d7b88193\n 4: 0x4029b9 - std::sys_common::backtrace::__rust_begin_short_backtrace::h21d98a9ff86d4c25\n 5: 0x40be65 - std::panicking::try::do_call::h5cff0c9b18cfdbba\n 6: 0x5e6a6c - panic_unwind::__rust_maybe_catch_panic\n at /checkout/src/libpanic_unwind/lib.rs:99\n 7: 0x41eb22 - <F as alloc::boxed::FnBox<A>>::call_box::h413eb1d9d9f1c473\n 8: 0x5df13b - alloc::boxed::{{impl}}::call_once<(),()>\n at /checkout/src/liballoc/boxed.rs:692\n - std::sys_common::thread::start_thread\n at /checkout/src/libstd/sys_common/thread.rs:21\n - std::sys::imp::thread::{{impl}}::new::thread_start\n at /checkout/src/libstd/sys/unix/thread.rs:84"}}

A few words about Selenium Grid Configuration:
You mentioned your Test Bed as selenium-server-standalone-3.7.1.jar and client-combined-3.5.3-nodeps.jar. As per Best Practices, you should use either of the following not both
Always try to use the latest released version i.e. selenium-server-standalone-3.7.1.jar
In selenium_grid.sh: you need to change the following :
java -Dwebdriver.gecko.driver=/opt/selenium/geckodriver

I simply follow this code using my firefox browser, seleinum grid with Testng in eclipse
System.setProperty("webdriver.gecko.driver","E:\\FireFoxDriver\\geckodriver.exe");
String URL = "http://demo.automationtesting.in/Register.html";
String Node = "http://192.168.43.97:4444/wd/hub";
DesiredCapabilities cap = DesiredCapabilities.firefox();
driver = new RemoteWebDriver(new URL(Node), cap);
driver.get(URL);
driver.manage().window().maximize();
System.out.println("Page title is: " + driver.getTitle());
Thread.sleep(5000);
driver.close();
For creating hub in your local machine
java -jar E:\SeleniumGrid\selenium-server-standalone-3.141.59.jar -role hub
open cmd and enter above line where your selenium standalone server is downloaded
Then you will get these two
Nodes should register to http://192.168.43.97:4444/grid/register/
Clients should connect to http://192.168.43.97:4444/wd/hub
Then again open cmd and type this for node
java -Dwebdriver.gecko.driver="E:\FireFoxDriver\geckodriver.exe" -jar E:\SeleniumGrid\selenium-server-standalone-3.141.59.jar -role node -hub http://192.168.43.97:4444/grid/register

Related

My selenium script is running fine in eclipse but not in jenkins

I have created script using TestNG annotation and maven. It runs expected in Eclipse, I also tried to run testng.xml file which looks good. and then I configured Jenkins but now Its not running. Jenkins giving error as below : (FYI : I have successful built in Jenkins previously , how this could broken in one day ???)
Starting ChromeDriver 72.0.3626.69 (3c16f8a135abc0d4da2dff33804db79b849a7c38) on port 48847
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Tests run: 7, Failures: 1, Errors: 0, Skipped: 6, Time elapsed: 4.774 sec <<< FAILURE! - in TestSuite
launchBrowser(com.pages.VisibilityAnnotationDemo) Time elapsed: 4.208 sec <<< FAILURE!
org.openqa.selenium.WebDriverException:
unknown error: Chrome failed to start: crashed
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Program Files (x86)\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=72.0.3626.69 (3c16f8a135abc0d4da2dff33804db79b849a7c38),platform=Windows NT 10.0.19042 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 872 milliseconds
I added below Jenkins config Root POM =
C:\Users....\workspace\VRsessions\pom.xml
Goals and options = clean install
The code I am try to run , Its script to do UI validation.
**public String baseUrl = " URL OF PAGE";
String driverPath = "C:\\Selenium\\chromedriver_win32\\chromedriver.exe";
public WebDriver driver;
JavascriptExecutor js = (JavascriptExecutor) driver;
#BeforeTest
public void launchBrowser() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", driverPath);
driver = new ChromeDriver();
driver.get(baseUrl);
}**
Tests on chrome, as far as I know, must be in headless mode to run on Jenkins. You'll need to set chrome options like this:
import org.openqa.selenium.chrome.ChromeDriver;
...
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
driver = new ChromeDriver(chromeOptions);
To fix this:
Add the the --disable-dev-shm-usage, --headless, --no-sandbox command line option to Chrome. And you also need to pass the ChromeOptions object to new ChromeDriver(options);
Code:
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("disable-infobars");
System.setProperty("webdriver.chrome.driver", driverPath);
driver = new ChromeDriver(options);
driver.get(baseUrl);

Unable to run selenium web driver project for 3.8.1 version

Unable to run web driver 3.8.1 geckodriver 0.19.1 with guava 21 and 22 .
Firefox version 58.0.2 (64-bit)
getting error as :
java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V
running on iMac
System.setProperty("webdriver.gecko.driver", "//Users//(username)//Downloads//engage-test//engage-test-common//exes//geckodriver");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
driver= new FirefoxDriver(capabilities);
The error says it all :
java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V
Class NoSuchMethodError
public class NoSuchMethodError extends IncompatibleClassChangeError and as per the Java Docs it is thrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has a definition of that method. Normally, this error is caught by the compiler and this error can only occur at run time if the definition of a class has incompatibly changed.
Solution
Perform the following steps :
When providing absolute paths either use double back slashes (\\) or single front slashes (/). Both are equivalent. So you need to update the System.setProperty() as follows :
System.setProperty("webdriver.gecko.driver", "/Users/<username>/Downloads/engage-test/engage-test-common/exes/geckodriver"); //Linux Style
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
Update your JDK to the most recent versions JDK 8u161
Upgrade Selenium-Java Clients to v3.10.0.
Clean up the Project Space from your IDE.
Run CCleaner tool to wipe off all the OS system chores.
If your base Web Browser version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of the Web Browser.
Take a System Reboot.
Execute your #Test
Update
As you are using Selenium-Java Client 3.11.0 where support of DesiredCapabilities is deprecated from the list of constructors for FirefoxDriver Class you have to use the method merge(Capabilities extraCapabilities) and merge the capabilities into an FirefoxOptions Class object as follows :
package demo;
import java.util.logging.Level;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
public class A_Firefox_DC_Opt
{
public static void main(String[] args)
{
System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe");
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("marionatte", true);
FirefoxOptions opt = new FirefoxOptions();
opt.merge(dc);
FirefoxDriver driver = new FirefoxDriver(opt);
driver.get("https://stackoverflow.com");
System.out.println("Application opened");
System.out.println("Page Title is : "+driver.getTitle());
driver.quit();
}
}
Console Output :
1522037759633 geckodriver INFO geckodriver 0.20.0
1522037759653 geckodriver INFO Listening on 127.0.0.1:20073
1522037760415 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" "C:\\Users\\ATECHM~1\\AppData\\Local\\Temp\\rust_mozprofile.hRnaFvWiVBua"
1522037762202 Marionette INFO Enabled via --marionette
1522037765376 Marionette INFO Listening on port 1176
1522037765636 Marionette WARN TLS certificate errors will be ignored for this session
Mar 26, 2018 9:46:05 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Application opened
Page Title is : Stack Overflow - Where Developers Learn, Share, & Build Careers

MicrosoftWebDriver loading web driver null

I have the error when run selenium on local machine which is Windows 10 Enterpise 64-bit (Microsoft Edge Version: 25.10586.672.0)and Microsoft WebDriver - Release 10240. My Selenium version is: 3.6.0
public class SeleniumTest {
private WebDriver driver;
#BeforeClass
public void getWebDriver() {
try {
System.setProperty("webdriver.edge.driver", "myapp/driver/MicrosoftWebDriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.edge();
capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
capabilities.setCapability(CapabilityType.PAGE_LOAD_STRATEGY, "eager");
capabilities.setPlatform(Platform.WIN10);
capabilities.setBrowserName(BrowserType.EDGE);
capabilities.setVersion("");
driver = new EdgeDriver(capabilities);
} catch (Exception e) {
e.printStackTrace();
}
driver.get(Constant.URL);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
}
#AfterClass
public void quitDriver() throws InterruptedException {
Thread.sleep(3000);
driver.quit();
}
#Test ()
public void aTest() {
}
#Test ()
public void bTest() {
}
}
When I run code it open the Edge Browser and has error:
org.openqa.selenium.NoSuchSessionException: null (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 873 milliseconds
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
System info: host: 'computername', ip: 'myip', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_111'
Driver info: driver.version: EdgeDriver
You may consider to look into the Release Notes as it mentions:
Updating .NET bindings to not send incorrect W3C Firefox capabilities
Previously, RemoteWebDriver would send the same capabilities dictionary
using both the "desiredCapabilities" and "capabilities" properties when
requesting a new remote session. In the case of the language bindings
expressly requesting to use the legacy Firefox driver, the capabilities
dictionary will include properties that are invalid for the W3C-compliant
remote server. To resolve that issue, we will mask the explicit attempt by
setting a property that causes the .NET RemoteWebDriver to send a
legacy-only compatible new session request when explicitly requesting the
legacy driver.
I don't see any significant error as such in your code except one, to see NoSuchSessionException. Instead of:
DesiredCapabilities capabilities = DesiredCapabilities.edge();
You should use:
DesiredCapabilities cap = new DesiredCapabilities();
It's possible you also need to start a driver service, i.e.
service = new EdgeDriverService.Builder()
.usingDriverExecutable(new File("path/to/my/MicrosoftWebDriver.exe"))
.usingAnyFreePort()
.build();
service.start();
Have a look at this example of an EdgeDriver.

Selenium test on VM with Geckodriver

Hi I have been trying to run a test on a virtual machine. I have gone through the Internet and none of the solutions worked for me.
I want to open firefox on Windows virtual machine. Here is my code:
#BeforeTest
public void launchapp() throws MalformedURLException
{
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
String URL = "http://www.google.com";
System.out.println(" Executing on FireFox");
String Node = "http://XX.XX.X.XX:5555/wd/hub";
URL url = new URL(Node);
DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
desiredCapabilities.setCapability("marionette", true);
desiredCapabilities.setBrowserName("firefox");
//driver = new FirefoxDriver(cap);
driver = new RemoteWebDriver(url, desiredCapabilities);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.navigate().to(URL);
driver.manage().window().maximize();
}
The error I get on the virstual machine is:
The path to the driver executable must be set by the webdriver gecko.driver system property....
On my PC I only see on the console that its trying to connect the node but it fails:
Marking the node http://.... as down: cannot reach the node for 2 tries
and
Unregistering the node http://... because it's been down for XXX ms
and in Eclipse:
org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{marionette=true, browserName=firefox, version=, platform=ANY}], required capabilities = null
Do you have any idea why this is not working? What should I check?

Webdriver: Tests crash with internet explorer7 with error Modal dialog present

Following tests is automated by using java and selenium-server-standalone-2.20.0.jar.
The test crashes with the error:
Page title is: cheese! - Google Search
Starting browserTest
2922 [main] INFO org.apache.http.impl.client.DefaultHttpClient - I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond
2922 [main] INFO org.apache.http.impl.client.DefaultHttpClient - Retrying request
Exception in thread "main" org.openqa.selenium.UnhandledAlertException: Modal dialog present (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.20 seconds
Build info: version: '2.20.0', revision: '16008', time: '2012-02-27 19:03:04'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_24'
Driver info: driver.version: InternetExplorerDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:170)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:129)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:438)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:139)
at org.openqa.selenium.ie.InternetExplorerDriver.setup(InternetExplorerDriver.java:91)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:48)
at com.pwc.test.java.InternetExplorer7.browserTest(InternetExplorer7.java:34)
at com.pwc.test.java.InternetExplorer7.main(InternetExplorer7.java:27)
Test Class:
package com.pwc.test.java;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import com.thoughtworks.selenium.Selenium;
public class InternetExplorer7 {
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver webDriver = new HtmlUnitDriver();
webDriver.get("http://www.google.com");
WebElement webElement = webDriver.findElement(By.name("q"));
webElement.sendKeys("cheese!");
webElement.submit();
System.out.println("Page title is: "+webDriver.getTitle());
browserTest();
}
public static void browserTest() {
System.out.println("Starting browserTest");
String baseURL = "http://www.mail.yahoo.com";
WebDriver driver = new InternetExplorerDriver();
driver.get(baseURL);
Selenium selenium = new WebDriverBackedSelenium(driver, baseURL);
selenium.windowMaximize();
WebElement username = driver.findElement(By.id("username"));
WebElement password = driver.findElement(By.id("passwd"));
WebElement signInButton = driver.findElement(By.id(".save"));
username.sendKeys("myusername");
password.sendKeys("magic");
signInButton.click();
driver.close();
}
}
I don't see any modal dialog when I launched the IE7/8 browser manually. What could be causing this?
You may take a screenshot by webDriver to see the modal dialog when this Exception occurs.
I was also getting the same exception on Firefox. I observed that the username and password fields were autocompleted because the option "Remember passwords for sites" was enabled in Firefox. So, while recording even if I erase the contents and enter, it would not record the data entered. I disabled the option and rerecorded my test case. Now, it works fine.
Hope it helps.