I try to use selenium(latest version, chrome version 58) with org.openqa.selenium.chrome.ChromeDriver
. This class has documentation which appears in eclipse. It includes simple test:
import java.io.File;
import java.io.IOException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import junit.framework.TestCase;
@RunWith(JUnit4.class)
public class ChromeTest extends TestCase {
private static ChromeDriverService service;
private WebDriver driver;
@BeforeClass
public static void createAndStartService() {
service = new ChromeDriverService.Builder()
.usingDriverExecutable(new File("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"))
.usingAnyFreePort().build();
try {
service.start();
} catch (IOException e) {
System.out.println("service didn't start");
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@AfterClass
public static void createAndStopService() {
service.stop();
}
@Before
public void createDriver() {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--disable-gpu");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
driver = new RemoteWebDriver(service.getUrl(), capabilities);
}
@After
public void quitDriver() {
driver.quit();
}
@Test
public void testGoogleSearch() {
driver.get("http://www.google.com");
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("webdriver");
// searchBox.quit();
assertEquals("webdriver - Google Search", driver.getTitle());
}
}
When I run it, new google chrome window appears on desktop. And in eclipse console I see:
ERROR:child_thread_impl.cc(762)] Request for unknown Channel-associated interface: ui::mojom::GpuMain
I tried to solve it by using :
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--disable-gpu");
But it didn't help. I still have the same error.
After I did debug I see that this error message appears on console when native method java.lang.Thread.start0()
is called. Inside java.lang.Thread.start
method there is call to native start0()
.
What is wrong with my comp(windows 7)?
How to solve this ?
Thank you!
Solved it.
I misunderstood method
usingDriverExecutable
ofChromeDriverService.Builder()
. This method expects path tochromedriver.exe
file but I set path tochrome.exe
. Correct code is:You can also set it with
webdriver.chrome.driver
system property:To download latest
chromedriver.exe
go to https://sites.google.com/a/chromium.org/chromedriver/downloads. From this page they send you to https://chromedriver.storage.googleapis.com/index.html?path=2.29/.