We have an open bug in our Automation Testing Framework regarding the resizing limitations of a Chrome Window when it is controlled by Selenium + ChromeDriver and I need help since I can't track down an official answer. As far as I am aware this was not an issue in the past.
We currently use the framework Codeception as the base for our own framework and when we use the action resizeWindow with the dimensions 320x568 it resizes the window to 445x500. Has anyone else ran into this issue with Chrome? It looks like a hardcoded limit at this point. Any advice would be greatly appreciated. Below I've provided a few Tests that I've ran looking for the upper and lower limits of the resizing action.
Test #1
Requested Size: 320x568
Resulting Size: 445x500
Test #2
Requested Size: 5000x5000
Resulting Size: 858x5000
Test 3
Requested Size: 1x1
Resulting Size: 252x500
LINKS
Codeception
Codeception - resizeWindow
Magento Functional Testing Framework
I found an answer to my question in another StackOverflow question.
"Chrome cannot resize horizontally below 400px (OS X) or 218px (Windows)"
Browser doesn't scale below 400px?
Can you please try with selenium dimension import
Import : import org.openqa.selenium.Dimension;
code :
Dimension d = new Dimension(320,568);
driver.manage().window().setSize(d); //Resize current window to the set dimension
Try using firefox. It works great. since chrome's setting changed and it won't work for testing media queries unless you use the dev tools.
Related
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 () {
I have selenium Hub as a service on Cluster Kubernetes and I start testing remotely using selenium side runner. Unfortunately when I try to run a test with terminal (using Ubuntu), I get the following error:
enter image description here
UnsupportedOperationError: pointer movements relative to viewport are
not supported in bridge mode
at executeLegacy (../../../../../usr/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/input.js:1129:17)
at Actions.perform
(../../../../../usr/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/input.js:971:16
if I try to start the tests from selenium ide, everything works well. What can the error depend on?
Can you help me? Thank you in advance.
Best regards
This error message...
UnsupportedOperationError: pointer movements relative to viewport are not supported in bridge mode
at executeLegacy (../../../../../usr/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/input.js:1129:17)
at Actions.perform (../../../../../usr/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/input.js:971:16
...implies that the pointer movement which happens relative to the viewport is not supported while working within a canvas in bridge mode.
As per the documentation in Clause 6 of Class Actions:
For W3C actions, move offsets relative to a WebElement are interpretted relative to the center of an element's first client rect in the viewport. For legacy actions, element offsets are relative to the top-left corner of the element's bounding client rect. When translating actions to the legacy protocol in bridge mode, an extra command must be inserted to translate move offsets from one frame of reference to the other. This extra command conributes to the overall latency issue.
You can find a detailed discussion in Is it possible to programmatically determine whether W3C action commands are used?
This is a known issue with Selenium and is being tracked through Not correctly move pointer to the position inside of element in bridge mode.
ChromeDriver - Implement Actions API
The currently released ChromeDriver 76.0.3809.12 contains the implementation of Actions API.
----------ChromeDriver 76.0.3809.12 (2019-06-07)----------
Supports Chrome version 76
Resolved issue 1897: Implement Actions API [Pri-1]
Link to Issue 1897: Implement Actions API
Switching to ChromeDriver 76.0 will solve your issue.
It could be due to selenium version. I faced the same issue and upgraded selenium version to 4.0.X.
I'm trying to figure out how to hide the border (including the address bar, tabs, title bar... everything that isn't the browser viewport) of my Firefox instance instantiated by Selenium.
If there's some way to have it use a userChrome.css, that would be straightforward enough. I've tried loading a profile folder that included a userChrome.css using this answer as a guide, but it seemed to ignore the styles. I've also looked through Firefox's about:config to see if there's some preference that would hide the frame of the window, but I haven't found anything yet.
Any solution that allows me to hide all or some of these elements when creating the instance with Selenium would be helpful. I know it's silly, but that's how it goes sometimes, you know?
-edit-
I don't think the title bar needs to be hidden. But everything else should be hidden.
-another edit to clarify a few things-
I mentioned kiosk mode in the comments as an example of the sort of thing I'm going for. Kiosk mode isn't exactly what I'm looking for, though. The windows aren't meant to be fullscreen, but they should still lack the elements of a common browser window. Think of it as like an Electron app. Out of the box, Electron lacks an address bar, tabs, etc. That's basically what we have for our app, but it's with regular-old Firefox. Again, whether these elements are displayed or not doesn't typically impact the test, but we want them hidden anyway.
Finally, I a friend of mine tried achieving this goal using a userChrome.css wrapped in a Firefox profile and was able to get Selenium to use the userChrome. So perhaps I need to figure out what I'm doing wrong. The biggest difference between how he did it and how I'm doing it is I must use a remote web driver for testing. But even still, it should be able to load the userChrome.css file. I'll try to update this question with more details as I fiddle with it some more.
-edit-
I think the reason userChrome isn't working when specifying a profile is because of the version(s) of Selenium/Geckodriver/Firefox being used.
The geckodriver version I started with was 0.15. 0.17 behaved exactly the same. 0.18 didn't respect the profile I passed along to it at all and instead had Firefox open the profile selection window (not very useful, but I was able to at least select the correct profile and see the userChrome.css get applied). 0.24 is no different.
Firefox is 52.9.0. Not much I can do about that.
We're using selenium (standalone) server 3.8.1. Switching out for 3.141.59 Didn't change anything.
Unless there's a version combination that will work with Firefox 52, I think the only thing I can do is wait until there's an update.
At last I have figured it out. In order to get Selenium to use my custom profile, I needed to do the following:
FirefoxProfile profile = new FirefoxProfile(new File(path_to_profile));
FirefoxOptions options = new FirefoxOptions().setProfile(profile);
RemoteWebDriver driver = new RemoteWebDriver(options.toCapabilities());
driver.get(url_of_webpage);
Thanks to avinesh09 on Github for the info I needed to solve the problem. It's so simple, but this has to be the only way that I neglected to try to load the profile.
If fullscreen (kiosk) mode is what you ask for (as then all you see is the viewport) it is as simple as:
driver.manage().window().fullscreen();
It is the same user experience as pressing "F11" in your browser.
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 )
I am testing the browser for mobile responsiveness. I changed the browser window size to iPhone 5 which is 320 x 568 using this command
driver.Manage().Window.Size = new Size(320, 568);
When I run the test, the browser opens fine according to the mentioned size without any issue. But it fails to find a hyperlink text which is displayed on the page. I get Element not visible exception when I could actually see the link text on the screen. So, could anyone help me solve this issue or have any ideas that I could try?
Any help would be highly appreciated.
Thanks.
Perhaps it's due to the time delay, that means code executes even before the link appears, So write the following code in your language
Code from Ruby Selenium-binding
wait = Selenium::WebDriver::Wait.new(timeout: 10) # seconds
wait.until { driver.find_element(id: "foo").displayed? }
driver.find_element(id: "foo").click
Try to scroll to the element.
You could use java script to do that.
In Python this can be done via
WebDriver.execute_script("arguments[0].scrollIntoView();", elem)
Some elements of the DOM of the webpage change when you test for mobile responsiveness, so selenium is unable to locate the element that you are specifically trying to target.So, you should try to debug and find the methods where the code is failing to perform the action.Then you should find the locators for those elements in "mobile responsiveness view" and trigger only those methods when you are testing for mobile.