Using Selenium 2 RemoteWebDriver with ChromeDriver - java

I searched for an answer to my question here and on the web but couldn't find anything that was helpful to me. Hopefully this isn't too dumb of a question.
I'm trying to get Selenium 2 to work using various browsers. I am using a Mac as a hub and a node and a Windows pc as a node. My problem is with Chrome. I want to initiate the Java code on the Mac and have the Selenium tests run on the Windows pc. To get Chrome to run on localhost I have the following code:
System.setProperty("webdriver.chrome.driver", "Users/xxxxx/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
This opens up Chrome on the hub/node Mac. How do I get it to open up on the Windows PC? Can I pass anything into the ChromeDriver() class?
I've tried using RemoteWebDriver, and have the following:
System.setProperty("webdriver.chrome.driver", "/Users/xxxxx/chromedriver");
DesiredCapabilities cap = DesiredCapabilities.chrome();
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:9515/wd/hub), cap);
driver.get("http://www.google.com");
The code compiles and executes, but Chrome never comes up. I don't get any errors. Note that I'm initiating the RemoteWebDriver on localhost and Chrome still doesn't work. Nothing changes if I change the URL to the IP of the Windows PC. I'm either doing something wrong with the RemoteWebDriver or I need to pass parameters to ChromeDriver. Please help.

Found the answer after a bit more searching. Turns out that the URL of the remotewebdriver needed to be only localhost:9515 without /wd/hub. Also, if running on another machine, make sure to start up chromedriver on that machine and point webdriver.chrome.driver to the location of chromedriver.

Related

Run selenium with cache on centos/linux

I'm able to run selenium on non GUI centos/linux machine in headless mode.
I have been trying to run it with cache enable by passing below chromeoptions arguments.
chromeOptions.addArguments("user-data-dir=~/.config/google-chrome");
It has started fine and identified elements till login page(which is first page) and couldn't identify any locators after that.
Is it the right approach to run cache enabled selenium run?
It's not that super clear when you mention about executing your tests with cache enabled. However, adding the argument user-data-dir is the canonical way to use a specific Chrome Profile.
You can find a couple of detailed discussions in:
How to open a Chrome Profile through Python
How to use Chrome Profile in Selenium Webdriver Python 3
Adding those options helps me to prevent crashes and errors on a linux remote machine
ChromeOptions options = new ChromeOptions();
options.addArguments(
"--disable-gpu",
"--headless",
"--window-size=1920,1200",
"--ignore-certificate-errors",
"--disable-extensions",
"--no-sandbox",
"--disable-dev-shm-usage",
"--hide-scrollbars",
"--allow-running-insecure-content",
"--disable-infobars",
"--ignore-certificate-errors");
Webdriver driver = new ChromeDriver(options);

How to implement the selenium on public browser

WebDriver driver=new FirefoxDriver();
It automatically open the Private firefox browser. Is there any option to open normal browser instead of Private browser.
Not without some serious work on your end. When you create a new WebDriver instance, a firefox instance is started that uses no user profiles. It's like a fresh installation. WebDriver installs a profile on this clean browser instance and installs an extension that runs a little micro web server that listens for instructions from your java program. This little server is what enables two way communication between the browser's javascript environment and your remote java program.
The relationship between the running instance of this firefox web server extension and the WebDriver instance running in your java program is a tightly controlled partnership. It's not part of their criteria to allow you to do what you're asking, so you would have to venture far outside the boundaries of what they support.
You can directly invoke the browser without giving setProperty in firefox for selenium versions <3.0
Firefox in Selenium 3
System.setProperty("webdriver.gecko.driver","path of the driver");
WebDriver driver = new FirefoxDriver();
Replace webdriver.gecko.driver with webdriver.firefox.marionette if above doesn't work.
Chrome browser
System.setProperty("webdriver.chrome.driver", "path of the driver");
WebDriver driver=new ChromeDriver();
IE browser
System.setProperty("webdriver.ie.driver","path of the driver");
WebDriver driver=new InternetExplorerDriver();
Headless Browser
WebDriver driver = new HtmlUnitDriver();

When i run selenium webdriver code Firefox webdriver not starting through given webaddress

When i tried to start on Firefox web driver its not starting its showing firefox default page
WebDriver dr = new FirefoxDriver();
dr.get("https://www.google.co.in/");
dr.manage().window().maximize();
its not starting its showing firefox default page
Below i attach output image screenshot
https://www.mozilla.org/en-US/firefox/43.0.4/firstrun/learnmore/
Firefox is one of the most compatible browsers with selemium, and at the same time, is one of the least compatible.
I say this because if you do not have the correct version of the selenium library to go with the version of firefox you are running, or vice-versa, it will always fail.
I would start by attempting to switch to a different version of Firefox. Selenium version 2.48.0 supports Firefox versions 24-41, so if your firefox version does not fit within that range, it is more than likely the problem.
I faced the same issue. The solution to this problem is to update the selenium version. When the page u mentioned i.e https://www.mozilla.org/en-US/firefox/43.0.4/firstrun/learnmore/ opens on firefox launch go to Options -> Addons -> Extensions. You will be able to see the Error there. I got "Forefox Webdriver could not be loaded and is disabled".
This was on Firefox 43 with selenium 2.44. Updating to selenium 2.51 rectified the issue.
Sorry, I cannot comment yet but I would like to help. I got the similar issue when I used selenium webdriver integrated in my python script. The problem was with credentials (particularly with the SSL protocols while declaring a new webdriver object). The code I used looked as the following:
driver = webdriver.PhantomJS(executable_path = "/opt/local/bin/phantomjs", service_args=['--ignore-ssl-errors=true'])
As you can see I use a key that ignores ssl errors. This solved my issue, so I am not sure what platform you use to write the code but hope you can find the similar call for the object.
I found the way how people handle untrusted certificates here. Particularly, for FireFox:
//It creates firefox profile
FirefoxProfile profile=new FirefoxProfile();
// This will set the true value
profile.setAcceptUntrustedCertificates(true);
// This will open firefox browser using above created profile
WebDriver driver=new FirefoxDriver();
driver.get("pass the url as per your requirement");
Hope it helps you!
Best.
-Petr.
Try this.. This will resolve the issue..
FirefoxProfile fpi = new FirefoxProfile();
fpi.setPreference("browser.startup.homepage_override.mstone", "ignore");
fpi.setPreference("startup.homepage_welcome_url.additional", "about:blank");
wd = new FirefoxDriver(fpi);
wd.get("http://www.google.com");
if you want to over-ride the properties of firefox, then,
1.first to find the list of browser properties, type "about:config" in the address url
2.use, setPreference method to set/assign the values..

RemoteWebDriver IE Clicking Links doesn't work

I am using the RemoteWebDriver and trying to execute a couple of UI tests on a remote machine under Internet Explorer:
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), DesiredCapabilities.internetExplorer());`
driver.get("http://bing.com");
driver.findElement(By.id("sb_form_q")).sendKeys("Cheese");
driver.findElement(By.id("sb_form_go")).click();
Using the following code works in FireFox and Chrome but not in IE. IF I run a plain web driver on my local machine it works fine. Does anyone know why this is the case or if there is a work around?
I am using Selenium-Server-Standalone-2.8.0 and the Selenium-Java-2.8.0 client drivers.
Thanks in advance.
I had problems with clicking using RemoteWebDriver and IE capabilities. I solved it by using sendKeys(Keys.ENTER) for links/buttons and sendKeys(Keys.SPACE) for radio buttons/checkboxes.
try with submit() instead of click() it should work.

Can't test a remote HTML/CSS/JS/Java website with Cucumber + Selenium Webdriver + Chrome + Capybara

I'm trying to test with Cucumber + Selenium + Capybara a remote HTML/CSS/JS website which uses a Java .
The website works fine on the Chrome browser, but when I launch my test, the Chrome browser is launched on the website, but the Java applet is not loaded at all.
Looks like the Chrome browser environment launched by Webdriver does not load any third party chrome plugins like Java.
Is there any way to circumvent this ?
Thanks in advance, best regards
Geoffroy
You can load a custom profile with the following code:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--user-data-dir=/path/to/profile/directory"));
WebDriver driver = new ChromeDriver(capabilities);
See the selenium chrome documentation: http://code.google.com/p/selenium/wiki/ChromeDriver
You can maybe try Selenium Remote Control instead of Webdriver. I haven't personally tried Selenium RC with third party tools, but it could an option to try while you're looking for alternatives.

Categories

Resources