use of org.openqa.selenium.chrome.ChromeDriver in project selenium_java by sergueik.
the class ChromeAndFirefoxTest method setupTest.
@Before
public void setupTest() {
chrome = new ChromeDriver();
firefox = new FirefoxDriver();
}
use of org.openqa.selenium.chrome.ChromeDriver in project selenium_java by sergueik.
the class SuperCalculatorTest method setUp.
@Before
public void setUp() throws Exception {
// change according to platformm
System.setProperty("webdriver.chrome.driver", osName.toLowerCase().startsWith("windows") ? new File("c:/java/selenium/chromedriver.exe").getAbsolutePath() : resolveEnvVars(chromeDriverPath));
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
if (isMobile) {
Map<String, String> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceName", "Google Nexus 5");
Map<String, Object> chromeOptions = new HashMap<>();
chromeOptions.put("mobileEmulation", mobileEmulation);
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
seleniumDriver = new ChromeDriver(capabilities);
// set ignoreSynchronization to true to handle page sync ourselves
// instead of using waitForAngular call in JProtractor
ngDriver = new NgWebDriver(seleniumDriver, true);
} else {
/*
* DesiredCapabilities capabilities = new
* DesiredCapabilities("firefox", "", Platform.ANY); FirefoxProfile
* profile = new ProfilesIni().getProfile("default");
* profile.setEnableNativeEvents(false);
* capabilities.setCapability("firefox_profile", profile);
* seleniumDriver = new FirefoxDriver(capabilities);
*/
seleniumDriver = new ChromeDriver(capabilities);
ngDriver = new NgWebDriver(seleniumDriver);
}
ngDriver.get(baseUrl);
ngDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
superCalculatorPage = new SuperCalculatorPage();
JPageFactory.initElements(ngDriver, channel, superCalculatorPage);
}
use of org.openqa.selenium.chrome.ChromeDriver in project selenium_java by sergueik.
the class TodoListTest method setUp.
@Before
public void setUp() throws Exception {
// change according to platformm
System.setProperty("webdriver.chrome.driver", osName.toLowerCase().startsWith("windows") ? new File("c:/java/selenium/chromedriver.exe").getAbsolutePath() : resolveEnvVars(chromeDriverPath));
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
if (isMobile) {
Map<String, String> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceName", "Google Nexus 5");
Map<String, Object> chromeOptions = new HashMap<>();
chromeOptions.put("mobileEmulation", mobileEmulation);
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
seleniumDriver = new ChromeDriver(capabilities);
// set ignoreSynchronization to true to handle page sync ourselves
// instead of using waitForAngular call in JProtractor
ngDriver = new NgWebDriver(seleniumDriver, true);
} else {
/*
* DesiredCapabilities capabilities = new
* DesiredCapabilities("firefox", "", Platform.ANY); FirefoxProfile
* profile = new ProfilesIni().getProfile("default");
* profile.setEnableNativeEvents(false);
* capabilities.setCapability("firefox_profile", profile);
* seleniumDriver = new FirefoxDriver(capabilities);
*/
seleniumDriver = new ChromeDriver(capabilities);
ngDriver = new NgWebDriver(seleniumDriver);
}
ngDriver.get(baseUrl);
ngDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
page = new TodoListPage();
page.setDriver(ngDriver);
JPageFactory.initElements(ngDriver, channel, page);
}
use of org.openqa.selenium.chrome.ChromeDriver in project selenium_java by sergueik.
the class FlowPaneEx method setUpSeleniumDriver.
public void setUpSeleniumDriver() {
// Create a new instance of a driver
System.setProperty("webdriver.chrome.driver", (new File("c:/java/selenium/chromedriver.exe")).getAbsolutePath());
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
driver = new ChromeDriver(capabilities);
// Navigate to the right place
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.google.ca/");
}
use of org.openqa.selenium.chrome.ChromeDriver in project selenium_java by sergueik.
the class CommonFunctions method getSeleniumDriver.
@SuppressWarnings("deprecation")
public static WebDriver getSeleniumDriver() throws IOException {
checkEnvironment();
if (isDestopTesting) {
// For desktop browser testing, run a Selenium node and Selenium hub on
// port 4444
// For Vagrant box browser testing have localhost port 4444 forwarded to
// the hub 4444
// Alternatively make the test class launch the browser
osName = System.getProperty("os.name");
if (browser.equals("chrome")) {
System.setProperty("webdriver.chrome.driver", new File((chromeDriverPath == null) ? osName.toLowerCase().startsWith("windows") ? "C:\\java\\selenium\\chromedriver.exe" : "/tmp/chromedriver" : chromeDriverPath).getAbsolutePath());
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
Map<String, Object> chromePrefs = new HashMap<>();
chromePrefs.put("profile.default_content_settings.popups", 0);
String downloadFilepath = System.getProperty("user.dir") + System.getProperty("file.separator") + "target" + System.getProperty("file.separator");
chromePrefs.put("download.default_directory", downloadFilepath);
chromePrefs.put("enableNetwork", "true");
options.setExperimentalOption("prefs", chromePrefs);
options.addArguments("allow-running-insecure-content");
options.addArguments("allow-insecure-localhost");
options.addArguments("enable-local-file-accesses");
options.addArguments("disable-notifications");
// options.addArguments("start-maximized");
options.addArguments("browser.download.folderList=2");
options.addArguments("--browser.helperApps.neverAsk.saveToDisk=image/jpg,text/csv,text/xml,application/xml,application/vnd.ms-excel,application/x-excel,application/x-msexcel,application/excel,application/pdf");
options.addArguments("browser.download.dir=" + downloadFilepath);
// options.addArguments("user-data-dir=/path/to/your/custom/profile");
capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
seleniumDriver = new ChromeDriver(capabilities);
} else if (browser.equals("firefox")) {
// alternatively one can add Geckodriver to system path
System.setProperty("webdriver.gecko.driver", "c:/java/selenium/geckodriver.exe");
// https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
// use legacy FirefoxDriver
capabilities.setCapability("marionette", false);
// http://www.programcreek.com/java-api-examples/index.php?api=org.openqa.selenium.firefox.FirefoxProfile
capabilities.setCapability("locationContextEnabled", false);
capabilities.setCapability("acceptSslCerts", true);
capabilities.setCapability("elementScrollBehavior", 1);
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(true);
// no longer supported as of Selenium 3.8.x
// profile.setEnableNativeEvents(false);
System.out.println(System.getProperty("user.dir"));
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
try {
// java.lang.ClassCastException:
// org.openqa.selenium.remote.service.DriverCommandExecutor cannot be
// cast to
// org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor
seleniumDriver = new FirefoxDriver(capabilities);
} catch (WebDriverException e) {
e.printStackTrace();
throw new RuntimeException("Cannot initialize Firefox driver");
}
}
} else {
DesiredCapabilities capabilities = new DesiredCapabilities("phantomjs", "", Platform.ANY);
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] { "--web-security=false", "--ssl-protocol=any", "--ignore-ssl-errors=true", "--local-to-remote-url-access=true", // prevent local file test XMLHttpRequest Exception 101
"--webdriver-loglevel=INFO" // set to DEBUG for a really verbose console output
});
seleniumDriver = new PhantomJSDriver(capabilities);
}
return seleniumDriver;
}
Aggregations