Chrome Driver default resolution - selenium

My front-end developers, changed the layout of the application which I'm testing, therefore some buttons are in slightly different places. I have about 50 automated tests that I will have to improve if the idea I came up with proves to be ineffective. Namely, is it possible to change the size of the pages opened by default via Headless Chrome Driver? Most of my tests are as follows: open the website > log in > click the button on the top bar of the application. The problem is that the buttons have been hidden under the hamburger button, and one of the ways to "see" them is to reduce the resolution of Google Chrome to 80%, so is it possible to program Chrome Driver and/or Geckodriver to open websites and web apps in 80% resolution by default?

There is a way to achieve the browser resolution changes before tests are actually started. Below codes are for java and you can add them to your driver options. You can find your desired resolutions and then you can change the values.
ChromeOption for 1920 x 1080 :
ChromeOptions options = new ChromeOptions();
options.addArguments("--window-size=1920,1080");
Firefox options for 1920 x 1080 :
FirefoxDriver firefoxOptions = new FirefoxDriver();
firefoxOptions.addArguments("-width=1920");
firefoxOptions.addArguments("-height=1080");
You can also change resolution after driver initialization with dimension, here is an example for 1920 x 1080 :
Dimension dimensions = new Dimension(1920,1080);
driver.manage().window().setSize(dimensions);
For Magnification feature of browser you can use below codes :
Magnification + :
driver.findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL,Keys.ADD));
Magnification - :
driver.findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL,Keys.SUBTRACT));

Related

Chrome Headless Selenium documentHeight

I am using Selenium C# to drive a Headless instance of Chrome
((ChromeOptions)_Options).AddArgument("--headless");
((ChromeOptions)_Options).AddArgument("window-size=1920,1080");
I have run into the problem that my javascript is always detecting both
$(document).height()
and
$(window).height()
as being 1080 in height, which is not accurate. The document height should be much taller in some cases. Is there a reason this is not working correctly and/or a work around to solve the issue?
In my troubleshooting, I grabbed the value for this javascript, and discovered that it was also 1080.
Math.max(document.body.scrollHeight, document.body.offsetHeight,
document.documentElement.clientHeight,
document.documentElement.scrollHeight,
document.documentElement.offsetHeight)
This particular page is definitely taller than the screen, and I used the Selenium GetScreenshot() method to take a picture and verify the scrollbar exists and content exists below the visible area.
For clarification, this does work correctly when running the headed version of Chrome. And the javascript in question is being run from JQuery's method:
$(document).ready(function () {

What are valid deviceNames for Chrome emulation testing with selenium webdriver?

What are valid deviceNames for Chrome emulation testing with selenium webdriver?
And also where can i get the device width,height and user agent for the device?
This is the device list:
https://cs.chromium.org/chromium/src/chrome/test/chromedriver/chrome/mobile_device_list.cc
In Java you can get height and width values by this way:
initial_size = driver.manage().window().getSize();
height = initial_size.getHeight();
width = initial_size.getWidth();

How to change already set chrome options while running tests?

While sharing screen from webrtc application, user gets 3 options.
1. Share entire screen
2. Share specific tab
3. Share specific application
I need to automate these TC's. Have found a way to do it individually on different browser driver by setting chrome option like :
options = webdriver.ChromeOptions()
options.add_argument("--auto-select-desktop-capture-source=Entire screen") -- for sharing entire screen.
But is there any way to perform all 3 cases using same driver by editing chrome option run time?

Can a website detect when you are using selenium with geckodriver?

Is it possible to detect instances of firefox browsers that are being controlled by Selenium and geckodriver?
Note there is a corresponding answer for chromedriver, but I'd like to know whether this is possible for firefox/geckodriver.
Yes you can detect geckodriver controlled selenium with a simple check in JavaScript
var runningSelenium = !("showModalDialog" in window);
As others have pointed out, there are a variety of different ways that a site can fingerprint and detect that you are running a browser that has been automated by selenium. Luckily though, some of the detection mechanisms are remarkably simple and just look for a bunch of environmental defaults, such as the screen size etc.
For example, when using Selenium for testing the app OAUTH sign-up sequences for Dropbox etc, the CAPTCHA stage can be avoided by just setting the screen to a non-default value (and offsetting the browser window to simulate a taskbar):
##headless = Headless.new( dimensions: '1600x1200x24' )
##headless.start
browser = Watir::Browser.new :firefox
width = browser.execute_script( 'return screen.width;' )
height = browser.execute_script( 'return screen.height;' ) - 95
browser.driver.manage.window.resize_to( width, height )
browser.driver.manage.window.move_to( 0,0 )

Setting Device Width for Remote Webdriver in Selenium

I am using Selenium grid 40 with Firefox remote driver that runs in windows 7. I also use C# API. I was wondering how to Set Device width on headless Firefox browser. The device width is less than ipads max width and this causes it to pick up ipad specific css that is defined like below:
#media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) {
/* For portrait layouts only */
}
#media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape) {
/* For landscape layouts only */
}
I have already changed window size using:
driver.Manage().Window.Size = new System.Drawing.Size(1290,900)
But it still picks up those css directives.
Other information: My grid node is virtual machine that nobody actually logs into. I remotely run the selenium grid, and that might be the reason why device width is small. it might default to smallest resolution for windows. If there is way to change that it might help me, but I am not aware of it.
Update: I tried to set all instances of DefaultSettings.XResolution, DefaultSettings.YResolution and DefaultSettings.BitsPerPel in registry to 1290, 900 and 16 through a powershell script and restart the computer but it didn't work.
I don't know how to set the device width using selenium, but I figured out how to set it using the remote frame buffer. For me this was Xvbf. I pass in the screen resolution when I start the service.
Below is an example of an Xvfb service with a resolution of 1024x768 with a depth of 24.
https://gist.github.com/dloman/931d65cbb79b00593ac3dd5d0cdf37d9
My experience is limited to using the Python implementation of Selenium so this may not work for you, but there you can use driver.set_window_size(width, height) before performing the driver.get() action that will load the desired page.
The key is the order in which you perform these actions: you want to tell selenium to change the dimensions of the browser before you load the page, because otherwise you are simulating the same behaviour as resizing a browser window after the initial page load. As you may know, when resizing a browser window, a page reload is needed for some 'responsive' features to be activated.