Can't connect to opera and edge webdriver through hub.
My procedure:
start hub in cmd:
java -jar C:\path\to\selenium-server-standalone-3.7.1.jar -role hub
start node in cmd:
java -Dwebdriver.opera.driver=C:\path\to\operadriver.exe -
Dwebdriver.edge.driver=C:\path\to\MicrosoftWebDriver.exe -jar
C:\path\to\selenium-server-standalone-
3.7.1.jar -role node -hub http://mylocalhost:4444/grid/register
-browser "browserName=opera,maxInstances=5,platform=Windows" -
browser "browserName=edge,maxInstances=5,platform=Windows"
And run this test for Opera:
WebDriver driver;
String nodeURL;
nodeURL = "http://mylocalhost:5555/wd/hub";
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("opera");
capabilities.setPlatform(Platform.WINDOWS);
driver = new RemoteWebDriver(new URL(nodeURL), capabilities);
driver.get("https://www.google.ru/");
And for Edge:
WebDriver driver;
String nodeURL;
nodeURL = "http://mylocalhost:5555/wd/hub";
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("opera");
capabilities.setPlatform(Platform.WINDOWS);
driver = new RemoteWebDriver(new URL(nodeURL), capabilities);
driver.get("https://www.google.ru/");
This is cause exception for Opera:
org.openqa.selenium.WebDriverException: unknown error: cannot find Opera binary
And exception for Edge:
org.openqa.selenium.SessionNotCreatedException: Unable to create new service: ChromeDriverService
I know that this code work fine for Chrome and firefox. Anyone know how to apply this for Opera ana Edge?
Related
I want to open ChromeDriver with extension AdBlock in incognito.
I try with
ChromeOptions co = new ChromeOptions();
co.addArguments("--load-extension=...\\adblock");
This work if I open ChromeDriver without incognito, but in Incognito don't work. How can make AdBlock to work in incognito.
Try this:
ChromeOptions co = new ChromeOptions();
co.addExtensions(new File("/path/to/extension.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
Source: https://www.blazemeter.com/blog/6-easy-steps-testing-your-chrome-extension-selenium
Below driver works fine when i remove headless option but when i include it the test fails. Using chromedriver version 2.36.540470
public WebDriver createDriver() {
System.setProperty("webdriver.chrome.driver", "C:\\Dev\\tools\\chromedriver.exe");
final ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("useAutomationExtension", false);
chromeOptions.addArguments("window-size=1900x1200");
chromeOptions.addArguments("--disable-gpu");
chromeOptions.addArguments("--headless");
final WebDriver driver = new ChromeDriver(chromeOptions);
return driver;
}
Turns out chromedriver running headless does not deal with ssl certificates very well (current open issue with them). Switching to gecko driver fixed the issue.
Here is my chrome driver code:-
String driverPath = driverFile.getAbsolutePath();
System.setProperty("webdriver.chrome.driver", driverPath);
Callable<ChromeDriver> startChromedriver = new Callable<ChromeDriver>() {
public ChromeDriver call() {
ChromeOptions Chromeoptions = new ChromeOptions();
Chromeoptions.addArguments("--startMaximized");
caps.setCapability("newCommandTimeout", 300);
caps.setCapability(ChromeOptions.CAPABILITY, Chromeoptions);
return new ChromeDriver(caps);
}
};
I have started the following in terminal:-
Xvfb -ac :99 -screen 0 1280x1024x16 &
export DISPLAY=:99
and then started my Junit test in Intellij
How do I run junit test in java using chrome driver on ubuntu machine?
For Firefox, I have tried and its working.
apt-get update
sudo apt-get install xvfb
sudo apt-get install -y xorg xvfb dbus-x11 xfonts-100dpi xfonts-75dpi xfonts-cyrillic
sudo Xvfb :2 -ac
export DISPLAY=:2
Setup in firefox
// Setup firefox binary to start in Xvfb
String Xport = System.getProperty(
"lmportal.xvfb.id", ":2");
final File firefoxPath = new File(System.getProperty(
"lmportal.deploy.firefox.path", "/usr/bin/firefox"));
FirefoxBinary firefoxBinary = new FirefoxBinary(firefoxPath);
firefoxBinary.setEnvironmentProperty("DISPLAY", Xport);
// Start Firefox driver
WebDriver driver = new FirefoxDriver(firefoxBinary, null);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://google.com/");
System.out.println("page source" + driver.getCurrentUrl());
Since Chrome 59 you don't even need Xvfb.
Download Chrome driver here : https://chromedriver.storage.googleapis.com/index.html?path=2.38/
Or on macOS :
brew install chromedriver
Then add a recent version of Selenium in your pom.xml/graddle:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.8.1</version>
</dependency>
Of course you will need a Chrome version > 59
And here comes the Java part:
String chromeDriverPath = "/Path/To/Chromedriver" ;
System.setProperty("webdriver.chrome.driver", chromeDriverPath);
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless", "--disable-gpu", "--window-size=1920,1200","--ignore-certificate-errors");
WebDriver driver = new ChromeDriver(options);
I wrote a blog post with detailed instruction here :
https://ksah.in/introduction-to-chrome-headless/
use redwoodHQ server and agent for Linux .then BrOwse to server to drive agent .
As you can find at cannot stop Chrome from updating from 43 to 44 I am having problem with chrome 44, as RobW suggested (in comments) i got a stand alone chrome.exe which has the version that I need, but now I do not know how to connect it to my test application which is written by Selenium & JAVA.
You need to point the "binary" to your standalone Chrome using ChromeOptions:
ChromeOptions options = new ChromeOptions()
options.setBinary(new File("/path/to/chrome"));
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
It is just a curiosity that how can I run firefox driver on different port like IE and Chrome driver.This driver have option like
ChromeDriverService service=new ChromeDriverService.Builder().usingPort(7000).
usingDriverExecutable(new File("")).build();
though the firefox driver have the option like that
System.setProperty("webdriver.firefox.port","7046");
or
DesiredCapabilities cap=new DesiredCapabilities();
cap.setCapability("webdriver_firefox_port",7046);
but it can not run firefox driver on this port I am using 2.41 Selenium Webdriver and firefox 31
Can anyone explain why and how can I run firefox driver in specified port.
Well, not sure, but this should work
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile profile = allProfiles.getProfile("WebDriver");
profile.setPreference(FirefoxProfile.PORT_PREFERENCE, 7046)
WebDriver driver = new FirefoxDriver(profile);