Selenium Grid with safari browser - selenium

Plese Help me
How do I instantiate the Safari in selenium grid
capabilities = new DesiredCapabilities();
// Version browser
capabilities.setVersion(versaoBrowser);
capabilities.setBrowserName("safari");
capabilities.setJavascriptEnabled(true);
// Platform test runner
capabilities.setPlatform(platform);
On the server is weel
-browser "browserName=safari,version=5,platform=WINDOWS,javascriptEnable=true"

If the question is about using Safari the new way, with SafariDriver over Grid2, then this would be the typical method I believe (more or less):
import org.openqa.selenium.*;
import org.openqa.selenium.remote.*;
import java.net.*;
DesiredCapabilities c = new DesiredCapabilities();
c.setBrowserName("safari");
/* you can then set version & platform as well, but the minimum is just browser. Maybe for Grid2 you need the others, but for remote web driver only, you don't.
*/
WebDriver d = new RemoteWebDriver(new URL("http://hubIpOrHostname:hubPort/wd/hub"),c);
and that should work. On the server side, I believe you just instantiate normally for Grid2 per the wiki docs (last I check, could be diff now):
//start hub
java -jar selenium-server-standalone-2.21.0.jar -role hub -port theHubPort
//start the node
java -jar selenium-server-standalone-2.21.0.jar -role node -hub http:
//172.22.6.198:4446/wd/hub -port theNodePort
however, seems that the current Grid2 doesn't offer Safari support. When I looked up the console for the registered node in hub, it didn't show icon for Safari. Maybe I missed something. I'll try adding platform and version next time to see if that makes a diff but think not.
Here's a snippet of the error I get for Grid2 with SafariDriver:
May 11, 2012 6:01:11 PM org.openqa.selenium.remote.RemoteWebDriver execute
INFO: Executing: [null, newSession {"desiredCapabilities":"Capabilities [{browse
rName=safari}]"}]
// Error: // Uncaught Exception: Typed variable declaration : Object constructor
: at Line: 7 : in file: : new RemoteWebDriver ( new URL ( "http:
//172.22.6.198:4446/wd/hub" ) , c )
Target exception: org.openqa.selenium.WebDriverException: Error forwarding the n
ew session cannot find : {browserName=safari}
Command duration or timeout: 109 milliseconds
To note: with webdriver, same code can be used for (standalone) remote webdriver execution vs grid, difference is that for remote you use remote server ip and with grid2, you use hub ip. SafariDriver works over remote webdriver, but currently doesn't seem to work over Grid2 yet.
remote webdriver startup:
java -jar selenum-server-standalone-2.21.0.jar [-port somePort]
//default port of 4444

I believe what you are asking for is something like this?
selenium = new DefaultSelenium("localhost", 4444, *safari,"http://google.com.au");
selenium.start();
I generally use WebDriver, but my understanding is capabilities are options for when you create an instance of a browser, not to open the browser itself. Though I could be wrong as I am not experienced with Selenium Grid.
EDIT: This and this might help.

Related

WebDriver Exception while running Selenium Tests on Remote Standalone server: org.openqa.selenium.WebDriverException: Unable to parse remote response

I have two personal laptops. Laptop A is the client from where I am running Selenium tests through Eclipse IDE. The tests are to be executed on Laptop B which runs the standalone server. Both laptops run Windows 10
To run Selenium Standalone server on Laptop B, I use the following command:-
java -jar selenium-server-standalone-3.141.59.jar -role standalone
The configuration steps I took:-
On Laptop B, the selenium server jar and the webdriver [geckodriver] are kept in the same folder
I have included the path to this folder in the PATH system environment variable on Laptop B
Both laptops are able to ping each other over my home wifi-fi
For Laptop B:
IPv4 Address: 192.168.1.9
Subnet Mask: 255.255.255.0
Default Gateway: 192.168.1.1
For Laptop A:
IPv4 Address: 192.168.1.5
Subnet Mask: 255.255.255.0
Default Gateway: 192.168.1.1
Once the standalone server is started on Laptop B, I am able to access the console page of standalone server from Laptop A from browser. Like so:-
http://192.168.1.9:5555/console
I use TestNG to run my Selenium test from Eclipse. The Test class has #BeforeClass annotated method like so:-
#BeforeClass
public void beforeClass() throws MalformedURLException, InterruptedException {
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setCapability("browserName", "firefox");
firefoxOptions.setCapability("platformName", "WIN10");
firefoxOptions.setCapability("marionette", true);
webdriver = new RemoteWebDriver(new URL("http://192.168.1.9:5555"), firefoxOptions);
...
..
.
}
I get the following error while running Selenium Tests [the standalone server's console HTML page is returned in error response]:-
FAILED CONFIGURATION: #BeforeClass beforeClass
org.openqa.selenium.WebDriverException: Unable to parse remote response: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
...
Notes:-
I got the same error when I tried with different browsers/webdriver combinations as given below:-
Chrome Browser version 81.x.x
FireFox Browser version 75.x
ChromeDriver versions 76.x,80.x,81.x,83.x
GeckoDriver versions 0.23.0, 0.26.0
While using ChromeDriver, I ensure the following are taken care of:-
a.On Laptop B, the selenium server jar and the webdriver [chromedriver] are kept in the same folder
b.I have included the path to this folder in the PATH system environment variable on Laptop B
c.TestNG annotated test class:-
#BeforeClass
public void beforeClass() throws MalformedURLException, InterruptedException {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setCapability("browserName", "chrome");
chromeOptions.setCapability("browserVersion", "81.x.x"); //76.x,80.x,81.x,83.x
chromeOptions.setCapability("platformName", "WIN10");
webdriver = new RemoteWebDriver(new URL("http://192.168.1.9:5555"), chromeOptions);
}
The end result is that the browsers are not invoked on laptop B and the tests not run
I searched the web (including Stackoverflow) but couldn't find a resolution to this error. Any inputs will be highly appreciated
Looks like you have wrong remote URL. Let's try:
http://192.168.1.9:5555/wd/hub
Please check the below for Selenium Grid configuration. It makes the procedure of configuring the selenium grid very easy and the part of this utility is it can increase and decrease the node automatically. If you face any issue while configuring the selenium grid then please drop me an email prajapatiabhishek1996#gmail.com I will love to solve that issue on screen share.
https://github.com/frostyaxe/Talongrid

How to run a test on a specific IP using Selenium Grid

i have a few queries regarding Selenium Grid.
Consider the below scenario:
Machine A:
registered as hub by command=
java -jar selenium-server-standalone-2.44.0.jar -role hub
Machine B:having Windows 7 and chrome browser
registered as node by command=java -Dwebdriver.chrome.driver="path of chrome driver" –jar selenium-server-standalone-2.44.0.jar –role webdriver –hub http://ipnameofHub:4444/grid/register -port 5566
Machine C: having Windows 7 and chrome browser​
registered as node​ by command=java -Dwebdriver.chrome.driver="path of chrome driver" –jar selenium-server-standalone-2.44.0.jar –role webdriver –hub http://ipnameofHub:4444/grid/register -port 5566
Machine D: having Windows 7 and chrome browser​
registered as node​ by command=java -Dwebdriver.chrome.driver="path of chrome driver" –jar selenium-server-standalone-2.44.0.jar –role webdriver –hub http://ipnameofHub:4444/grid/register -port 5566
DesiredCapabilities dc=new DesiredCapabilities();
dc.setBrowserName("chrome");
dc.setPlatform(Platform.WINDOWS);
​WebDriver driver=new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),dc);
When i run a test, which node will grid choose and on what basis, since all the nodes have the same platform and browser as specified in the DesiredCapabilities.
Is the node randomly chosen or the first node matching the DesiredCpabilities is chosen?
Question No.2
If i want to run a test on specifically Machine D, how can that be done.
Thanks in advance.
it is chosen based on first matching capability and available node.
To run on specific node, you can write your own algorithm to choose. the following link may help to write custom capability matcher https://www.assertthat.com/posts/make_your_selenium_grid_nodes_personalized

Selenium Grid 2 from mac hub to windows node

I am setting up selenium grid to be able to test IE in a Virtual Machine. I am running into:
geb.driver.DriverCreationException: failed to create driver from callback
which generally means the driver is not being found. I'm pointing it to the correct location, however something isn't working. FYI refers to my hub machine's intranet IP address.
Here are my files/commands:
From Mac hub terminal:
java -jar selenium-server-standalone-2.39.0.jar -role hub
From Windows node terminal:
C:\selenium-server>java -jar selenium-server-standalone-2.39.0.jar -role node -hub http://:4444/grid/register -browser browserName="internet explorer",version=10.0,platform=WINDOWS -Dwebdriver.ie.driver=C:\IEDriverServer.exe
My GebConfig.groovy file where the drivers are instantiated:
ie {
driver = {
DesiredCapabilities capabilities = new DesiredCapabilities().internetExplorer().
new RemoteWebDriver(new URI("http://<IP>:4444/wd/hub"), capabilities)
}
}
My stack trace is as follows:
geb.driver.DriverCreationException: failed to create driver from callback 'script13923985022291935133551$_run_closure2_closure5_closure9#557c6200'
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:35)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:80)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy)
at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:30)
at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:79)
at geb.Configuration.createDriver(Configuration.groovy:354)
at geb.Configuration.getDriver(Configuration.groovy:343)
at geb.Browser.getDriver(Browser.groovy:105)
at geb.Browser.go(Browser.groovy:394)
at geb.Page.to(Page.groovy:184)
at geb.Browser.via(Browser.groovy:475)
at geb.Browser.to(Browser.groovy:434)
at geb.Browser.to(Browser.groovy:412)
at geb.spock.GebSpec.methodMissing(GebSpec.groovy:51)
at com.bloomhealthco.functional.LoginTestSpec.User is able to login as an administrator(LoginTestSpec.groovy:12)
Caused by: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: org.openqa.selenium.remote.RemoteWebDriver(java.net.URI, groovy.util.ConfigObject)
at script13923985022291935133551.run_closure2_closure5_closure9(script13923985022291935133551.groovy:44)
at script13923985022291935133551.run_closure2_closure5_closure9(script13923985022291935133551.groovy)
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:29)
... 14 more
geb.driver.DriverCreationException: failed to create driver from callback 'script13923985022291935133551$_run_closure2_closure5_closure9#557c6200'
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:35)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:80)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy)
at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:30)
at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:79)
at geb.Configuration.createDriver(Configuration.groovy:354)
at geb.Configuration.getDriver(Configuration.groovy:343)
at geb.Browser.getDriver(Browser.groovy:105)
at geb.report.PageSourceReporter.getPageSource(PageSourceReporter.groovy:42)
at geb.report.PageSourceReporter.writePageSource(PageSourceReporter.groovy:38)
at geb.report.PageSourceReporter.writeReport(PageSourceReporter.groovy:29)
at geb.report.CompositeReporter.writeReport(CompositeReporter.groovy:31)
at geb.Browser.report(Browser.groovy:775)
at geb.spock.GebReportingSpec.report(GebReportingSpec.groovy:44)
at geb.spock.GebReportingSpec.cleanup(GebReportingSpec.groovy:39)
Caused by: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: org.openqa.selenium.remote.RemoteWebDriver(java.net.URI, groovy.util.ConfigObject)
at script13923985022291935133551.run_closure2_closure5_closure9(script13923985022291935133551.groovy:44)
at script13923985022291935133551.run_closure2_closure5_closure9(script13923985022291935133551.groovy)
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:29)
... 14 more
geb.driver.DriverCreationException: failed to create driver from callback 'script13923985022291935133551$_run_closure2_closure5_closure9#557c6200'
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:35)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:80)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy)
at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:30)
at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:79)
at geb.Configuration.createDriver(Configuration.groovy:354)
at geb.Configuration.getDriver(Configuration.groovy:343)
at geb.Browser.getDriver(Browser.groovy:105)
at geb.Browser.clearCookies(Browser.groovy:483)
at geb.Browser.clearCookiesQuietly(Browser.groovy:491)
at geb.spock.GebSpec.resetBrowser(GebSpec.groovy:45)
at geb.spock.GebSpec.cleanup(GebSpec.groovy:67)
Caused by: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: org.openqa.selenium.remote.RemoteWebDriver(java.net.URI, groovy.util.ConfigObject)
at script13923985022291935133551.run_closure2_closure5_closure9(script13923985022291935133551.groovy:44)
at script13923985022291935133551.run_closure2_closure5_closure9(script13923985022291935133551.groovy)
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:29)
... 11 more
Additionally the node can be registered with the hub:
ip:4444/grid/console screenshot
I've been searching all day and it seems this should work. Does anyone have any suggestions or know what's wrong?
Thank you in advanced.
From your stacktrace I can see that the real reason for not being able to create the driver is:
Could not find matching constructor for: org.openqa.selenium.remote.RemoteWebDriver(java.net.URI, groovy.util.ConfigObject)
Is the snipped of your GebConfig.groovy exactly the same as you have it in your file? I see that capabilities is defined as an instance of DesiredCapabilities in your snippet so I don't understand why would a config object be passed as the second parameter... I can't see it but maybe you have a typo somewhere? With Groovy config scripts you'll have issues if you mistype something as you will get a new empty ConfigObject instance instead of an error.
The second thing is that the first parameter should be an URL and not a URI if you're after using this constructor.

Selenium Grid does not run Chrome on another computer

I have this problem. When on different computer, I start HUB and NODE and then run my tests where I initialize Google Chrome like this:
Selenium selenium = new DefaultSelenium("localhost", 4444, *googlechrome, "http://www.google.com");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"));
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Everything runs ok on my computer - Chrome comes up and does the script. However, If my friend tries to do exactly the same, she gets this error:
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_29'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:435)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:139)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:94)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:102)
at com.deutscheboerse.test.PerfTests.<init>(PerfTests.java:52)
at com.deutscheboerse.test.EUAStressTest.myTest(EUAStressTest.java:37)
at com.deutscheboerse.test.EUAStressTest.main(EUAStressTest.java:60)
Caused by: org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 4422; received: 3743
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:178)
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:197)
at org.apache.http.impl.io.ContentLengthInputStream.close(ContentLengthInputStream.java:105)
at org.apache.http.conn.BasicManagedEntity.streamClosed(BasicManagedEntity.java:152)
at org.apache.http.conn.EofSensorInputStream.checkClose(EofSensorInputStream.java:237)
at org.apache.http.conn.EofSensorInputStream.close(EofSensorInputStream.java:186)
at org.apache.http.util.EntityUtils.consume(EntityUtils.java:67)
at org.openqa.selenium.remote.HttpCommandExecutor$EntityWithEncoding.<init> HttpCommandExecutor.java:399)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:287)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:415)
... 6 more
So far only difference what I found is, that hers hub is listening on http://10.10.190.134:5555 mine is listening on http://10.131.7.44:5555 but both can access the console on same IP and port. I dont have any clue whats wrong. Everything is appreciated, thanks
** EDIT **
Iried to run it on another computer and I had the same error. Little debugging showed me this message:
11:04:01.899 WARN - Exception: The path to the chromedriver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromedriver/downloads/list
So, prior setting up the Chrome in Selenium Grid, I need to do this:
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "chromedriver.exe");
I tried to do it and stil unable to run the Chrome... Any help is still wanted
EDID2
This is how I exactly set the property:
File file = new File("lib/chromedriver.exe");
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, file.getAbsolutePath());
I am using this approach because I need to run it on more computer and the JAR file can have different locations.
BTW, the warning is found in window with Selenium Grid in role node. I am thinking, if there is any other switcher. So far I am running these commands:
java -jar lib//selenium-server-standalone-2.20.0.jar -role hub
java -jar lib/selenium-server-standalone-2.20.0.jar -role node -hub http://localhost:4444/grid/register -maxSession 12
and then my JAR. The exception is in window with the NODE. Is there any switcher?
After a day searching, I have working solution. Everything is in how do you start the node. So first, do the usual:
java -jar lib/selenium-server-standalone-2.20.0.jar -role hub
Then start the node like this:
java -jar lib/selenium-server-standalone-2.20.0.jar -role webdriver -hub http://localhost:4444/grid/register -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=5 -Dwebdriver.chrome.driver=lib\chromedriver.exe
More specifically: You have to start up the NODE with parameter browser and add -D parameter specifying the full path to the ChromeDriver
My huge thanks goes to John Naegle who answered similar question here on SO regarding the Internet Explorer - see here
That's funny, but webdriver cannot resolve dns, http://localhost:4444/
I edited my host file, uncommented line:
127.0.0.1 localhost
And It's done.

Selenium grid newbie questions

Ok, I have already several testcases written for Webdriver approach. But now I need get the Selenium Grid for possible stress testing of the webapp.
I found this demo but its unable to control the Firefox 11. Then I found out this wiki page which is two level higher than I can understand, but that JAR File is supposedly able to control the Firefox 11.
What I need - some resources how to get the Grid started and how to let it do simple test - like writing "Hello World" into Google search bar and then clicking "Search."
EDIT
This is the error when I am trying to run the grid as node
D:\_dev\selenium-grid-1.0.8\lib>java -jar selenium-server-standalone-2.20.0.jar -role node -hub http://localhost:4444/grid/register
22-Mar-2012 10:33:48 org.openqa.grid.selenium.GridLauncher main
INFO: Launching a selenium grid node
Exception in thread "main" java.lang.NoSuchMethodError: java.lang.String.isEmpty()Z
at org.openqa.grid.common.RegistrationRequest.getRemoteControlConfiguration(RegistrationRequest.java:585)
at org.openqa.grid.internal.utils.SelfRegisteringRemote.startRemoteServer(SelfRegisteringRemote.java:86)
at org.openqa.grid.selenium.GridLauncher.main(GridLauncher.java:72)
And this is output from server which seems ok
D:\_dev\selenium-grid-1.0.8\lib>java -jar selenium-server-standalone-2.20.0.jar -role hub
22-Mar-2012 10:33:33 org.openqa.grid.selenium.GridLauncher main
INFO: Launching a selenium grid server
360 [main] INFO org.seleniumhq.jetty7.server.Server - jetty-7.x.y-SNAPSHOT
422 [main] INFO org.seleniumhq.jetty7.server.handler.ContextHandler - started o.s.j.s.ServletContextHandler{/,null}
438 [main] INFO org.seleniumhq.jetty7.server.AbstractConnector - Started SocketConnector#0.0.0.0:4444
If you are working with windows, you need to add the path to firefox to your PATH environment variable. The reason for this is, that windows then knows what program to start, when you call firefox from command line, for example.
Then you need to donwload the selenium server standalone and then start the hub
java -jar selenium-server-standalone-2.20.0.jar -role hub
and also the client:
java -jar selenium-server-standalone-2.20.0.jar -role node -hub http://localhost:4444/grid/register
Now you need to create a new Java Project in Eclipse, for example like so:
class MyFristTest{
//using the #test annotation tells eclipse
//to use junit (or tells you to import it)
#Test
public void myTest(){
Selenium selenium = new DefaultSelenium(“localhost”, 4444, “*firefox”, “http://www.google.com”);
DesiredCapabilities capability = DesiredCapabilities.firefox();
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
driver.get("http://www.example.com");
driver.findElement(By.linkText("RFC 2606")).click();
driver.findElement(By.linkText("txt")).click();
}
If you now start the JUnit Test, it should magically work.