Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
1 view
in DevOps and Agile by (19.7k points)

We are using Selenium with Java to automate our Web application. We have working code to run automated test scripts on the Windows operating system for the three browsers (IE, Chrome, Firefox - Latest version).

We have got the requirement to run automated test scripts on MAC operating system - Safari browser.

Environment Details:

MAC OS version : macOS Sierra version 10.12.5

Safari browser version : 10.1.1(12603.2.4)

Selenium standalone server version : 3.4.0

Java version : 1.8.0_112

Connected MAC VM with the VNC viewer (Sysadmin team provided MAC VM for our testing).

While executing test scripts on MAC, the below code is not maximizing the Safari browser, which is working fine for other browsers(IE, Chrome, and Firefox) on Windows. Due to this, we are unable to locate some of the controls on application.

driver.manage().window().maximize();

We are not getting any exception, code is executing but not performing any action.

Please help to overcome the Safari browser to maximize the issue on MAC.

Really I thought my issue got resolved with this solution, tried code to maximize Safari browser, but getting an exception.

Code:

SafariOptions options = new SafariOptions();

options.setUseCleanSession(true);

driver = new SafariDriver(options);

JavascriptExecutor jse = (JavascriptExecutor)driver;

String screenWidth = jse.executeScript("return screen.availWidth").toString();

String screenHeight = jse.executeScript("return screen.availHeight").toString();

int intScreenWidth = Integer.parseInt(screenWidth);

int intScreenHeight = Integer.parseInt(screenHeight);

org.openqa.selenium.Dimension d = new org.openqa.selenium.Dimension(intScreenWidth, intScreenHeight);

driver.manage().window().setSize(d);

Exception:

Aug 07, 2017 3:11:53 PM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: OSS Exception in thread "main" org.openqa.selenium.NoSuchWindowException: A request to use a window could not be satisfied because the window could not be found. (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 27 milliseconds Build info: version: '3.4.0', revision: '5234b32', time: '2017-03-10 09:04:52 -0800' System info: host: 'Mac.local', ip: 'fe80:0:0:0:4c6:11dc:3f91:11f8%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_121' Driver info: org.openqa.selenium.safari.SafariDriver Capabilities [{applicationCacheEnabled=true, rotatable=false, databaseEnabled=true, handlesAlerts=true, version=12603.3.8, cleanSession=true, platform=MAC, nativeEvents=true, locationContextEnabled=false, webStorageEnabled=true, browserName=safari, javascriptEnabled=true, platformName=macOS, cssSelectorsEnabled=true}] Session ID: BA265536-18D3-490E-B6DB-40D8BBF25937 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:638) at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteWindow.setSize(RemoteWebDriver.java:860) at Sample.Safari.main(Safari.java:20)

1 Answer

0 votes
by (62.9k points)

Safari browser maximize issue got resolved after upgrading Safari version to 11.0(12604.1.35)

And the working code is

driver.manage().window().maximize();

Related questions

Browse Categories

...