use of org.openqa.selenium.remote.DesiredCapabilities in project java.webdriver by sayems.
the class PhantomJSBrowser method getDesiredCapabilities.
@Override
public DesiredCapabilities getDesiredCapabilities(Proxy proxySettings) {
DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
final List<String> cliArguments = new ArrayList<>();
cliArguments.add("--web-security=false");
cliArguments.add("--ssl-protocol=any");
cliArguments.add("--ignore-ssl-errors=true");
capabilities.setCapability("phantomjs.cli.args", applyPhantomJSProxySettings(cliArguments, proxySettings));
capabilities.setCapability("takesScreenshot", true);
capabilities.setCapability("screenResolution", "1280x1024");
return capabilities;
}
use of org.openqa.selenium.remote.DesiredCapabilities in project java.webdriver by sayems.
the class FirefoxBrowser method getDesiredCapabilities.
@Override
public DesiredCapabilities getDesiredCapabilities(Proxy proxySettings) {
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(new File("libs/firebug-2.0.16-fx.xpi"));
profile.addExtension(new File("libs/firefinder_for_firebug-1.4-fx.xpi"));
profile.addExtension(new File("libs/firepath-0.9.7.1-fx.xpi"));
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
capabilities.setCapability("screenResolution", "1280x1024");
capabilities.setCapability("marionette", true);
return addProxySettings(capabilities, proxySettings);
}
use of org.openqa.selenium.remote.DesiredCapabilities in project java.webdriver by sayems.
the class SafariBrowser method getDesiredCapabilities.
/*
* Since Selenium 2.45.0, in order to use SafariDriver,
* you need to manually install the SafariDriver browser extension.
*
* The prebuilt SafariDriver extension can be downloaded from here:
* http://selenium-release.storage.googleapis.com/index.html?path=2.48/
* You'll need latest version of SafariDriver.safariextz(SafariDriver.safariextz)
* Download it, double-click it, and click Trust when prompted.
*
* if you're going to run Safari on a remote node (or set of nodes),
* you'll need to install and enable the SafariDriver browser extension on each of them.
*
*/
@Override
public DesiredCapabilities getDesiredCapabilities(Proxy proxySettings) {
DesiredCapabilities capabilities = DesiredCapabilities.safari();
capabilities.setCapability("safari.cleanSession", true);
capabilities.setCapability("screenResolution", "1280x1024");
return addProxySettings(capabilities, proxySettings);
}
use of org.openqa.selenium.remote.DesiredCapabilities in project ats-framework by Axway.
the class AbstractRealBrowserDriver method start.
@Override
@PublicAtsApi
public void start() {
try {
log.info("Starting selenium browser with " + this.getClass().getSimpleName());
if (browserType == BrowserType.FireFox) {
com.axway.ats.uiengine.FirefoxDriver firefoxDriver = new com.axway.ats.uiengine.FirefoxDriver(url, browserPath, remoteSeleniumURL);
FirefoxProfile profile = null;
if (firefoxDriver.getProfileName() != null) {
profile = new ProfilesIni().getProfile(firefoxDriver.getProfileName());
if (profile == null) {
throw new SeleniumOperationException("Firefox profile '" + firefoxDriver.getProfileName() + "' doesn't exist");
}
} else if (firefoxDriver.getProfileDirectory() != null) {
File profileDirectory = new File(firefoxDriver.getProfileDirectory());
profile = new FirefoxProfile(profileDirectory);
} else {
profile = new FirefoxProfile();
String downloadDir = UiEngineConfigurator.getInstance().getBrowserDownloadDir();
// for default browser. Now will FIX this behavior
if (downloadDir.endsWith("/") || downloadDir.endsWith("\\")) {
downloadDir = downloadDir.substring(0, downloadDir.length() - 1);
}
// Following options are described in http://kb.mozillazine.org/Firefox_:_FAQs_:_About:config_Entries
profile.setPreference("browser.download.dir", downloadDir);
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", UiEngineConfigurator.getInstance().getBrowserDownloadMimeTypes());
// set to "Always Activate"
profile.setPreference("plugin.state.java", 2);
// set to "Always Activate"
profile.setPreference("plugin.state.flash", 2);
profile.setAcceptUntrustedCertificates(true);
}
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
setFirefoxProxyIfAvailable(capabilities);
if (this.browserPath != null) {
capabilities.setCapability(FirefoxDriver.BINARY, this.browserPath);
}
FirefoxOptions options = UiEngineConfigurator.getInstance().getFirefoxDriverOptions();
if (options == null) {
options = new FirefoxOptions();
}
capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);
if (this.remoteSeleniumURL != null) {
webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), capabilities);
} else {
webDriver = new FirefoxDriver(capabilities);
}
} else if (browserType == BrowserType.InternetExplorer) {
InternetExplorerOptions options = UiEngineConfigurator.getInstance().getInternetExplorerDriverOptions();
if (options == null) {
options = new InternetExplorerOptions(DesiredCapabilities.internetExplorer());
}
if (this.remoteSeleniumURL != null) {
webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), options);
} else {
webDriver = new org.openqa.selenium.ie.InternetExplorerDriver(options);
}
} else if (browserType == BrowserType.Edge) {
EdgeOptions options = UiEngineConfigurator.getInstance().getEdgeDriverOptions();
if (options == null) {
options = new EdgeOptions().merge(DesiredCapabilities.edge());
}
if (this.remoteSeleniumURL != null) {
webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), options);
} else {
webDriver = new org.openqa.selenium.edge.EdgeDriver(options);
}
} else if (browserType == BrowserType.Chrome) {
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
// apply Chrome options
ChromeOptions options = UiEngineConfigurator.getInstance().getChromeDriverOptions();
if (options == null) {
options = new ChromeOptions();
}
/* set browser download dir for Chrome Browser */
String downloadDir = UiEngineConfigurator.getInstance().getBrowserDownloadDir();
HashMap<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
prefs.put("download.default_directory", downloadDir);
options.setExperimentalOption("prefs", prefs);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
if (this.remoteSeleniumURL != null) {
webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), capabilities);
} else {
webDriver = new org.openqa.selenium.chrome.ChromeDriver(capabilities);
}
} else if (browserType == BrowserType.Safari) {
if (this.remoteSeleniumURL != null) {
webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), DesiredCapabilities.safari());
} else {
webDriver = new org.openqa.selenium.safari.SafariDriver();
}
} else if (browserType == BrowserType.PhantomJS) {
DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
capabilities.setJavascriptEnabled(true);
capabilities.setCapability("acceptSslCerts", true);
capabilities.setCapability("browserConnectionEnabled", true);
capabilities.setCapability("takesScreenshot", true);
// See: https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage#settings-object
if (System.getProperty(PhantomJsDriver.SETTINGS_PROPERTY) != null) {
Map<String, String> settings = extractPhantomJSCapabilityValues(System.getProperty(PhantomJsDriver.SETTINGS_PROPERTY));
for (Entry<String, String> capability : settings.entrySet()) {
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX + capability.getKey(), capability.getValue());
}
}
// See: https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage#wiki-webpage-customHeaders
if (System.getProperty(PhantomJsDriver.CUSTOM_HEADERS_PROPERTY) != null) {
Map<String, String> customHeaders = extractPhantomJSCapabilityValues(System.getProperty(PhantomJsDriver.CUSTOM_HEADERS_PROPERTY));
for (Entry<String, String> header : customHeaders.entrySet()) {
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + header.getKey(), header.getValue());
}
}
if (this.browserPath != null) {
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, this.browserPath);
System.setProperty(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, // required from the create screenshot method
this.browserPath);
}
// See: https://github.com/ariya/phantomjs/wiki/API-Reference#command-line-options
List<String> cliArgsCapabilities = new ArrayList<String>();
cliArgsCapabilities.add("--web-security=false");
cliArgsCapabilities.add("--ignore-ssl-errors=true");
if (System.getProperty(PhantomJsDriver.SSL_PROTOCOL_PROPERTY) != null) {
cliArgsCapabilities.add("--ssl-protocol=" + System.getProperty(PhantomJsDriver.SSL_PROTOCOL_PROPERTY));
} else {
cliArgsCapabilities.add("--ssl-protocol=any");
}
if (System.getProperty(PhantomJsDriver.HTTP_ONLY_COOKIES_PROPERTY) != null) {
cliArgsCapabilities.add("--cookies-file=" + PhantomJsDriver.cookiesFile);
}
// cliArgsCapabilities.add( "--local-to-remote-url-access=true" );
setPhantomJSProxyIfAvailable(cliArgsCapabilities);
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCapabilities);
if (this.remoteSeleniumURL != null) {
webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), capabilities);
} else {
webDriver = new org.openqa.selenium.phantomjs.PhantomJSDriver(capabilities);
}
}
log.info("Opening URL: " + url);
webDriver.get(url);
if (this instanceof com.axway.ats.uiengine.PhantomJsDriver) {
webDriver.manage().window().setSize(new Dimension(1280, 1024));
} else if (!(this instanceof com.axway.ats.uiengine.EdgeDriver)) {
webDriver.manage().window().maximize();
}
int browserActionTimeout = UiEngineConfigurator.getInstance().getBrowserActionTimeout();
if (browserActionTimeout > 0) {
webDriver.manage().timeouts().setScriptTimeout(browserActionTimeout, TimeUnit.SECONDS);
}
if (!(this instanceof com.axway.ats.uiengine.EdgeDriver)) {
webDriver.manage().timeouts().pageLoadTimeout(browserActionTimeout, TimeUnit.SECONDS);
}
// waiting for the "body" element to be loaded
waitForPageLoaded(webDriver, UiEngineConfigurator.getInstance().getWaitPageToLoadTimeout());
} catch (Exception e) {
throw new SeleniumOperationException("Error starting Selenium", e);
}
}
use of org.openqa.selenium.remote.DesiredCapabilities in project ats-framework by Axway.
the class MobileDriver method start.
/**
* Start session to device and load the application <br>
* @param appPath filesystem path to the application - absolute or relative to the Appium server current dir
* <pre>
* <b>iOS</b>: absolute path to simulator-compiled .app file or the bundle_id of the desired target on device
* <b>Android</b>: absolute path to .apk file
* </pre>
*/
@PublicAtsApi
public void start(String appPath) {
log.info("Starting mobile testing session to device: " + getDeviceDescription());
URL url = null;
String platformName = null;
try {
url = new URL("http://" + this.host + ":" + this.port + "/wd/hub");
// http://appium.io/slate/en/master/?java#appium-server-capabilities
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
if (isAndroidAgent) {
if (this.adbLocation == null) {
// try to set Android home and adb location from the ANDROID_HOME environment variable
readAndroidHomeFromEnvironment();
if (this.adbLocation == null) {
throw new MobileOperationException("You must specify a valid Android home location or define " + ANDROID_HOME_ENV_VAR + " environment variable." + " The ADB executable must be located in a 'platform-tools/' subfolder");
}
}
platformName = "Android";
} else {
desiredCapabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);
platformName = "iOS";
}
desiredCapabilities.setCapability("platformName", platformName);
desiredCapabilities.setCapability("deviceName", deviceName);
desiredCapabilities.setCapability("platformVersion", this.platformVersion);
if (!StringUtils.isNullOrEmpty(this.udid)) {
desiredCapabilities.setCapability("udid", this.udid);
}
desiredCapabilities.setCapability(MobileCapabilityType.APP, /*"app" */
appPath);
desiredCapabilities.setCapability("autoLaunch", true);
desiredCapabilities.setCapability("newCommandTimeout", 30 * 60);
desiredCapabilities.setCapability("noReset", // don’t reset settings and app state before this session
true);
// sometimes environment has performance problems
// in ms
desiredCapabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500_000);
if (isAndroidAgent) {
driver = new AndroidDriver<WebElement>(url, desiredCapabilities);
} else {
driver = new IOSDriver<WebElement>(url, desiredCapabilities);
}
driver.setLogLevel(Level.ALL);
// the following timeout only works for NATIVE context, but we will handle it in MobileElementState.
// Also there is a problem when != 0. In some reason, for iOS only(maybe), this timeout acts as session timeout ?!?
driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS);
// driver.manage().timeouts().pageLoadTimeout( 30000, TimeUnit.MILLISECONDS ); // UnsupportedCommandException
// driver.manage().timeouts().setScriptTimeout( 10000, TimeUnit.MILLISECONDS ); // WebDriverException: Not yet implemented
driver.context(NATIVE_CONTEXT);
// must be called in NATIVE context
this.screenDimensions = driver.manage().window().getSize();
mobileEngine = new MobileEngine(this, this.mobileDeviceUtils);
// log.info("Application file at " + appPath + " is started and initialized");
} catch (Exception e) {
throw new MobileOperationException("Error starting connection to " + platformName + " device and application " + "under test. Check if there is connection to the device and the Appium " + "server at " + url + " is running.", e);
}
}
Aggregations