Exception on Selenium Grid program - selenium-grid

Have started the hub and registered the node. Then wrote a program in eclipse:
after running the program i am getting below exception:-
Exception in thread "main" java. lang.Class Cast Exception: java.lang.String cannot be cast to java.util.Map.
the remote web driver is :
Remote Web Driver driver = new Remote Web Driver(client URL,capability);

I've had the same error. The problem was in class org.openqa.selenium.remote.RemoteWebDriver (75):
Map<String, Object> rawCapabilities = (Map<String, Object>) response.getValue();
It's happened because I've given the wrong URL parameter for RemoteWebDriver():
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/"), capability);
That's why response had a String type.
Please check your url. It should be:
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
I hope it will help you :)

Related

How can I initialize Chrome Remote web driver using WebDriverManager while passing ChromeOptions and a Selenium Grid standalone server url?

Trying to initialize a Chrome Remote web driver using WebDriverManager, while passing ChromeOptions and a Selenium Grid standalone server URL using Java.
From online examples;
Passing Chrome options would look like this:
WebDriverManager.chromedriver().setup();
RemoteWebDriver remoteWebDriver = new ChromeDriver(options);
threadLocalDriver.set(remoteWebDriver);
Passing the hub URL for the selenium grid standalone server would look like this:
WebDriverManager.chromedriver().setup();
RemoteWebDriver remoteWebDriver = ((RemoteWebDriver) WebDriverManager
.chromedriver()
.remoteAddress(hubURL)
.create());
threadLocalDriver.set(remoteWebDriver);
How can I pass both to a RemoteWebDriver object?
Thanks
EDIT:
Here is my code. I am getting an error from create() method
[main] ERROR io.github.bonigarcia.wdm.WebDriverManager - There was an error creating WebDriver object for Chrome
io.github.bonigarcia.wdm.config.WebDriverManagerException: Timeout of 30 seconds creating WebDriver object
public void createDriver() throws IOException {
ChromeOptions options = getPlatformSpecificOptions();
logger.info("Driver options: " + options.toString());
String hubURL = "http://127.0.0.1:4444/wd/hub";
WebDriver driver = WebDriverManager.chromedriver()
.capabilities(options)
.remoteAddress(hubURL)
.create();
threadLocalDriver.set(((RemoteWebDriver) driver));
}
TestHelper.setPlatform(PLATFORM);
}
You need to use the method capabilities() for that:
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
WebDriver driver = WebDriverManager.chromedriver()
.capabilities(options)
.remoteAddress(hubURL)
.create();
Also calling setup() is not needed as it is called by create() method.

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?

Unable to invoke internet explorer by using remotewebdriver in c#

I am able to run my test on a local machine with IWebDriver but
unable to run the test on a remote computer with Selenium.
DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability(CapabilityType.BrowserName, DesiredCapabilities.InternetExplorer());
capability.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Windows));
capability.SetCapability("webdriver.ie.driver", #"E:\WebDriver\Browser\");
string host = "localhost:4444/wd/hub";
RemoteWebDriver driver = new RemoteWebDriver(new Uri("http://" + host), capability);
The error I am getting is
Additional information: The path to the driver executable must be set by the webdriver.ie.driver
system property; for more information, see http://code.google.com/p/selenium/wiki/InternetExplorerDriver.
The latest version can be downloaded from http://code.google.com/p/selenium/downloads/list

How to use Phantomjs for opening a website in Selenium

I'm trying to use headless webkit of PhantomJs for opening google.com through selenium webdriver but when I execute the code system throws an error. phantomJs.exe is placed in E directory. Please help me resolve this issue.
public static void main(String[] args) throws Exception {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "E:\\phantomjs.exe");
WebDriver driver = new PhantomJSDriver();
driver.get("http://www.google.com");
}
Error:
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the phantomjs.binary.path capability/system property/PATH variable; for more information, see https://github.com/ariya/phantomjs/wiki. The latest version can be downloaded from http://phantomjs.org/download.html
at com.google.common.base.Preconditions.checkState(Preconditions.java:197)
at org.openqa.selenium.phantomjs.PhantomJSDriverService.findPhantomJS(PhantomJSDriverService.java:236)
at org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:181)
at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:104)
at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:94)
at multidrivers.main(multidrivers.java:35)
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the phantomjs.binary.path capability/system property/PATH variable;
The above issue is due to the driver not being initialized with the DesiredCapabilities object:
WebDriver driver = new PhantomJSDriver();
Updating the code as below should solve your issue:
WebDriver driver = new PhantomJSDriver(caps);
Let me know if you have any queries.

Using Selenium to test Safari gives GridException

I am using the code from this site (http://darrellgrainger.blogspot.com/2011/02/using-selenium-20-with-webdriver-and.html) to run Selenium tests in Safari 5. The code goes like this:
Selenium sel = new DefaultSelenium("localhost", 4444, "*safari", baseURL);
CommandExecutor executor = new SeleneseCommandExecutor(sel);
DesiredCapabilities dc = new DesiredCapabilities();
WebDriver browser = new RemoteWebDriver(executor, dc);
browser.get("http://www.google.com");
WebElement input = browser.findElement(By.name("q"));
input.sendKeys("Selenium");
So I start a Selenium server standalone version on the localhost machine and I register a test node (also on localhost) to the Selenium hub. Then I start the test. I then get the following exception: org.openqa.selenium.WebDriverException: Could not start Selenium session: org%2Eopenqa%2Egrid%2Ecommon%2Eexception%2EGridException%3A+Error+forwarding+the+new+session+The+server+returned+an+error+%3A+
I don't know what error. There is no server output on the console. Does anyone have ideas? I used the newest version (2.17.0) of Selenium.
EDIT: I just tried "firefox" instead of safari and it outputs the same exception. So actually it's not the fault of safari. Maybe there is something wrong with executing Selenium 1 code via the grid?
Try This:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("safari");
capabilities.setJavascriptEnabled(true);
CommandExecutor executor = new SeleneseCommandExecutor(new URL("http://localhost:5555/"), new URL("http://www.google.com/"), capabilities);
WebDriver driver = new RemoteWebDriver(executor, capabilities);
driver.get("http://google.com");
Don't create DefaultSelenium object. The above code works well for me with Safari browser.