Handling Screen Resolution In Synthetics

In the post “Follow up questions from Synthetics Webinar 10-27-15”, Shane Delight makes the following reference:

Q:Can you configure the webdriver to simulate running on a mobile device for responsive websites?

A: Yes, you can simulate it by setting the User agent to a mobile agent and the screen size to an appropriate resolution. This is still just chrome passing the user agent and screen size but it should display your responsive site.

Okay, the user agent part is easy:

$browser.addHeader(‘User-Agent’,‘Mozilla/5.0 (Linux; U; Android 2.3.3; Nexus S Build/GRI20) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1’);
$browser.get(…)

But what about the screen resolution. It would seem the following command might work but it does not.

window.resizeTo(412,732);

How do you influence/set the screen resolution in a script?

Hi @Chris.Davis - You cannot set the screen resolution, but you can set the browser dimensions by using:

$browser.manage().window().setSize()

1 Like

Thanks. That worked.

2 Likes

Hey @Chris.Davis - thanks for posting your first questions! Glad the omnipresent (and omnitient?) @stefan_garnham got that squared away for you. Please let us know if there is anything else we can do for you!

@hross this no longer seems to be working. It throws an error:
Script execution failed: WebDriverError: unknown error: failed to change window state to normal, current state is maximized (Session info: chrome=72.0.3626.121)

In selenium JAVA I can set it with

Map<String, String> mobileEmulation = new HashMap<>(); mobileEmulation.put("deviceName", "iPhone 6/7/8 Plus");

	`ChromeOptions chromeOptions = new ChromeOptions();
	chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);` 

Can we do something similar in new relics since we are using Chrome ?

Hi, @christopher.barreto: It works in Selenium because you are setting the option before the browser window is created. The problem in Synthetics is that the browser is created before your script runs; by the time your script runs, it is too late to set the window size.

The workaround is here:

2 Likes

Awesome, TY! it seems like a lot of work to set screen size… Is there a way to save methods within new relic ? Like create a Utilities project to just call ?

1 Like

You might try this:

2 Likes

The workaround really does help. But I tried to comment the resize step in the recorded script and it still did work. So may try to run xour script without resizing before taking the length of implementing the work around.

1 Like