use of org.openqa.selenium.Dimension in project Asqatasun by Asqatasun.
the class FirefoxDriverFactory method make.
/**
*
* @param config
* @return A FirefoxDriver.
*/
@Override
public RemoteWebDriver make(HashMap<String, String> config) {
FirefoxBinary ffBinary = new FirefoxBinary();
if (System.getProperty(DISPLAY_PROPERTY) != null) {
ffBinary.setEnvironmentProperty(DISPLAY_PROPERTY.toUpperCase(), System.getProperty(DISPLAY_PROPERTY));
} else if (System.getenv(DISPLAY_PROPERTY.toUpperCase()) != null) {
ffBinary.setEnvironmentProperty(DISPLAY_PROPERTY.toUpperCase(), System.getenv(DISPLAY_PROPERTY.toUpperCase()));
}
RemoteWebDriver remoteWebDriver = new FirefoxDriver(ffBinary, firefoxProfile);
if (screenHeight != -1 && screenWidth != -1) {
remoteWebDriver.manage().window().setSize(new Dimension(screenWidth, screenHeight));
}
return remoteWebDriver;
}
use of org.openqa.selenium.Dimension 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);
profile.setEnableNativeEvents(true);
}
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
setFirefoxProxyIfAvailable(capabilities);
if (this.browserPath != null) {
capabilities.setCapability(FirefoxDriver.BINARY, this.browserPath);
}
if (this.remoteSeleniumURL != null) {
webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), capabilities);
} else {
webDriver = new FirefoxDriver(capabilities);
}
} else if (browserType == BrowserType.InternetExplorer) {
if (this.remoteSeleniumURL != null) {
webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), DesiredCapabilities.internetExplorer());
} else {
webDriver = new org.openqa.selenium.ie.InternetExplorerDriver();
}
} else if (browserType == BrowserType.Edge) {
if (this.remoteSeleniumURL != null) {
webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), DesiredCapabilities.edge());
} else {
webDriver = new org.openqa.selenium.edge.EdgeDriver();
}
} 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("Openning 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.Dimension in project ghostdriver by detro.
the class WindowSizingAndPositioningTest method manipulateWindowSize.
@Test
public void manipulateWindowSize() {
WebDriver d = getDriver();
d.get("http://www.google.com");
assertTrue(d.manage().window().getSize().width > 100);
assertTrue(d.manage().window().getSize().height > 100);
d.manage().window().setSize(new Dimension(1024, 768));
assertEquals(d.manage().window().getSize().width, 1024);
assertEquals(d.manage().window().getSize().height, 768);
}
use of org.openqa.selenium.Dimension in project sonarqube by SonarSource.
the class SeleneseRunner method runOn.
void runOn(Selenese selenese, Orchestrator orchestrator) {
this.variables = new HashMap<>();
this.baseUrl = orchestrator.getServer().getUrl();
this.driver = Browser.FIREFOX.getDriverForThread();
driver.manage().deleteAllCookies();
driver.manage().window().setSize(new Dimension(1280, 1024));
for (File file : selenese.getHtmlTests()) {
System.out.println();
System.out.println("============ " + file.getName() + " ============");
Document doc = parse(file);
for (Element table : doc.getElementsByTag("table")) {
for (Element tbody : table.getElementsByTag("tbody")) {
for (Element tr : tbody.getElementsByTag("tr")) {
String action = tr.child(0).text();
String param1 = tr.child(1).text();
String param2 = tr.child(2).text();
try {
action(action, param1, param2);
} catch (AssertionError e) {
analyzeLog(driver);
throw e;
}
}
}
}
}
}
use of org.openqa.selenium.Dimension in project ats-framework by Axway.
the class MobileElement method scrollTo.
/**
* Scroll to element (at the center of the screen)
*
* @return this mobile element which allows chained actions
*/
@SuppressWarnings("unchecked")
@PublicAtsApi
public T scrollTo() {
try {
if (MobileElementFinder.getElementContext(this).toUpperCase().startsWith("WEBVIEW")) {
// in WEBVIEWs the target element exists, while in the NATIVE context it doesn't until we scroll to it
new MobileElementState(this).waitToBecomeExisting();
Dimension screenDimensions = ((MobileDriver) getUiDriver()).getScreenDimensions();
WebElement element = MobileElementFinder.findElement(appiumDriver, this);
// window.scrollTo(0, element.getLocation().y); --> will scroll the element to top-left
int scrollToY = 0;
int screenCenter = screenDimensions.getHeight() / 2 + element.getSize().height / 2;
if (element.getLocation().y < screenCenter) {
// the element is located after the screen center if we scroll to (0, element.getLocation().y)
// because it is near the bottom of the application => we can't center it, but it is OK on that position
scrollToY = element.getLocation().y;
} else {
scrollToY = element.getLocation().y - screenCenter;
}
((JavascriptExecutor) appiumDriver).executeScript("window.scrollTo(0," + scrollToY + ")");
} else {
if (getElementProperty("name") != null) {
// only works for NATIVE context
appiumDriver.scrollTo(getElementProperty("name"));
}
}
return (T) this;
} catch (Exception e) {
throw new MobileOperationException(this, "scrollTo", e);
}
}
Aggregations