Running Selenium via jenkins on VM, screen size - selenium

I have a problem with running Selenium tests on VM.
Tests are written under 1920x1080 resolution everything is OK until I run tests manually. Tests passes. The problem appear when I run tests through Jenkins. It's not a problem in my code.
I dont know why but screen resolution is much lower (1032, 776) - actually it's browser size. And that is the cause why buttons to test are not visible. Tests fails.
Jenkins is opening by "Run slave agent via Java Web Start" and evertyhing works automatically on windows serwer. Old Selenium tests (written under lower resolution) works perfect. So the problem is closely related to screen size.
Thank you in advance.

If you are working on Windows the following should work:
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--window-size=1920,1080");
System.setProperty("webdriver.chrome.driver","\\path\\chromedriver.exe");
driver = new ChromeDriver(options);

Related

"element click intercepted" only on TFS

I have about 130 Selenium UI tests for a web app we're currently developing.
The problem I have is, whenever I run the tests locally through Visual Studio's test explorer (vstest), I have never encountered this error before.
The problem is, some of the tests keep failing due to this message when the tests are run on TFS (using vstest on TFS too). element click intercepted
I'm also 100% sure there is no overlaying element that interferes with the click method as the tests never fail with that message when run locally.
Any idea what could this be?
I had issues where all of my local tests would pass, but I would receive random errors as you mentioned when running the tests through Jenkins or TFS, usually errors indicating that my elements were not clickable, etc. - the issue ended up being the browser size.
I started running my test in headless mode and specified a large browser size. Switching to --headless and setting a browser size ended up solving most of my issues for me:
var headlessOptions = new ChromeOptions();
headlessOptions.AddArgument("--headless");
headlessOptions.AddArguments("--disable-gpu");
headlessOptions.AddArguments("--window-size=1920,1200");
You will have to use --headless for this to work too. I tried to run my tests by ONLY setting window size, but the tests would still fail anyway because the resolution of the virtual machines was not large enough to handle the browser size I had set.
You can resolve this issue by using 2 methods.
1.Running chrome in headless mode
2.Scorlling to the element before clicking or interacting with it
The root cause of this issue is due to the fact that the browser does not load with a browser size as that of browser when tested locally
If you intend to run the test in non headless mode you can use the following code to achieve the result.
IWebElement element= driver.FindElement(By.Id(selector));
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", element);

Selenium IE Webdriver send slowkeys even though changed to 32Bit

I have a serious Problem, and i tried about 20 workarounds which completely failed to work as a solution for me.
MainProblem: I execute a testsuite parallel on 3 different browsers, Chrome, Firefox and IE11. While sendKeys() works perfectly fine on chrome and Firefox, on IE every letter takes about 5 seconds to appear, so a normal login-procedure which takes about 2 sec on chrome takes about 50 on IE...
I work on a mac. On the Mac, i have a WindowsPC (Win10) in a VM via Parallels. On this, i installed JDK, Eclipse, and try to automate a webpage via Selenium+Testng.
IE Version: 11.192.16299.0
I set the security level to low for trusted and local intranet, i removed the save-mode checkbox. I got the well known slow-sendKeys-Problem. But for most of the internet it worked with changing the IEWebdriver from 64-> 32Bit. It simply doesnt make any difference and i struggle here.
I really need help. Please let me know if you need any insight, logs or whatever, i try to provide with everything fast.
Best Greets!
By setting up the following options It should resolve the problem:
System.setProperty("webdriver.ie.driver", "./path/IEDriverServer.exe");
InternetExplorerOptions options = new InternetExplorerOptions();
options.introduceFlakinessByIgnoringSecurityDomains();
options.requireWindowFocus();
WebDriver driver = new InternetExplorerDriver(options);

Firefox Webdriver is extremely slow

We use the selenium webdriver dlls set up to run my automation suite. I encounter this problem when runnning tests in Firefox only. The tests in Firefox run very slow , taking 3-4 minutes to load pages, However, when I run the same test on the same machine using Firefox browser manually I don't encounter this slowness. At times while running automation on Firefox, we also get "Connection was reset" page. Also, the same tests run fine in Chrome and IE.
We use the following environment:
Firefox version 28, 37 (proxy is set to use system settings)
Webdriver (dlls) version 2.45
Windows 7
Earlier we used to run the same set up in Windows XP using Firefox version 14,16, and Webdriver version 2.37, we didn't experience this issue.
We invoke Firefox using the following code :
Proxy proxy = new Proxy();
proxy.Kind = ProxyKind.System;
FirefoxProfile profile = new FirefoxProfile();
profile.SetProxyPreferences(proxy);
RemoteWebDriver dr = new FirefoxDriver(new FirefoxBinary(#"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"), profile, TimeSpan.FromSeconds(120));
dr.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(3));
dr.Manage().Window.Maximize();
dr.Manage().Cookies.DeleteAllCookies();
dr.Navigate().GoToUrl(WebSiteUrl);
remaining tests steps......
Please can someone help me resolve this issue.
Thanks in advance.
This is how I solved the "extremely slow FirefoxDriver" problem:
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService();
service.Host = "::1";
IWebDriver driver = new FirefoxDriver(service);
The above code forces the geckodriver to use the IPv6 protocol, which works many times faster for the interactions with the UI elements.
Probably won't do you any good now, but I had the same problem with Firefox 45 and Webdriver 2.15. Turned the problem was the implicit wait setup. In my case, I had:
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
This one line was taking 190 seconds (yes, more than 3 minutes!) to execute. Removing it cut the startup time to under 8 seconds!

Jenkins with Xvfb and Selenium - Firefox started but nothing executed

I have a problem with Selenium under Jenkins 1.446 together with Xvfb: It looks like firefox is started correctly because I let my failing tests record screenshots. These screenshots all show the same failing page, which in my case is the starting page where the tests should begin. So I gues the selenium WebDriver commands do not arrive. What could be the reason? By the way, the tests are running perfectly on my local machine.
I'm using Firefox 9.0.1 with no specific test profile and no AddOns, Ubuntu 10.04, Senlenium 2.16.1
Log entry: com.thoughtworks.selenium.SeleniumException: Timed out waiting for action to finish
Thanks!
EDIT: Issue seems to be fixed by a system reboot ...
I experienced a very similar issue with FF9.0.1 and Selenium 2.16.1 running through JUnit launched by Maven SureFire plugin run by Jenkins on a WinXP node.
2.17.0 fixed the issue for me. Try updating to the latest Selenium.
Through RDP, I was able to watch the tests running. The tests appeared to be partially blocked by a prompt from Firefox asking about collecting anonymous usage statistics. Manually answering the prompt would allow the test to continue but because Selenium creates a new profile each time by default, the prompt would return on the next browser launch. Running the tests locally with a pre-configured FF profile allowed me to persist that the prompt had been answered. This isn't possible on my XP node because the tests are running as 'System'.
Selenium/WebDriver would normally take care of this for you by marking the prompt as already answered in a temporary FF profile configuration but a bug was causing the value to be set to the wrong value. You can inject a profile configuration to the Selenium FirefoxDriver driver to pragmatically configure stuff like this prompt but the bug appeared to prevent this as well. This has been resolved in Selenium 2.17.0 (http://selenium.googlecode.com/svn/trunk/java/CHANGELOG see 2.17.0 WebDriver bug fixes).

Selenium difference on windows / linux

I have a JUnit test that imports org.openqa.selenium.interactions.Actions.
Specifically, I am using dragAndDrop, outlined here
When I run the Junit test on my local machine (windows), it runs perfectly. However, when the same test is run on a Linux machine, the method does not work. Everything else in the test runs fine but the dragAndDrop method does not work.
A co-worker said that it might have something to do "XVFB" but could not elaborate much.
Any comments appreciated, thanks!
I am assuming you are using Firefox on Linux? Native events are disabled by default for Firefox on Linux. Advanced Actions API need native events. Try enabling them and then check your test on linux like below,
FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents(true);
WebDriver driver = new FirefoxDriver(profile);