Selenium navigate().to() stuck without error - selenium

I am running tests using TestNG, chromium and Selenium, in Java, on two machines:
my own laptop
a Mac Mini I do not have physical access to, that I connect via SSH, that has the same identical project structure as the project on my laptop.
Both machines operate behind the same corporate proxy.
The issue I am having is the following:
while the tests run smoothly on my machine, when I execute the command to start them on the Mac Mini, the execution stops when telling the Selenium WebDriver to navigate to any specified url using driver.navigate().to(url) or driver.get(url); causing the program to freeze without throwing any exception, essentially remaining on hold.
The code resembles the following:
in the #BeforeClass beforeClass() driver is initialized with an instance of ChromeDriver using ChromeOptions. Among other settings, I add the following arguments to the ChromeOptions like such chromeOptions.addArguments(options): where options is things like --disable-web-security, --allow-running-insecure-content, --allow-insecure-localhost and most importantly: --proxy-server=address:port (e.g. --proxy-server=172.26.44.146:3128).
in the #BeforeMethod beforeMethod() after checking that the driver is not null and that the URL url is a valid one, I execute something similar to the stylized following code:
try {
log.debug("Navigating to: " + url);
driver.navigate().to(url);
log.debug("Navigated to url: " + driver.getCurrentUrl());
} catch (Exception e) {
log.error("Unable to navigate at page: " + url.toString());
throw e;
}
As I said, when running the test on the Mac Mini via SSH using the command line in a similar fashion to: java -cp WORKSPACE org.testng.TestNG testng.xml the code stops executing and freezes at log.debug("Navigating to: " + url); essentially not producing other output and forcing me to manually stop the execution of the test.
As additional information, tests are run using chromium version 72.0.3609.0.
The ChromeOptions also receive the following proxy setting (like such: chromeOptions.setProxy(p);) where p is a Proxy with
p.setProxyType(ProxyType.MANUAL);
p.setAutodetect(false);
I suspect an issue with the proxy (and am doubtful I have correctly preconfigured the program), but, quite frankly, I am puzzled by the fact that the same script runs locally on my machine and is unable to run locally on the Mac Mini when the tests are launched via SSH.

Related

C# : Cannot run selenium tests in parallel while using a Chrome profile

I am trying to run tests in parallel , however I am not able to. It triggers only one failing the other. I am using Chrome profiling option ("user-data-dir") to launch Chrome. If I disable this option, the tests run just fine in parallel. Can somebody tell me what I could be missing?
The argument that I have added is
public string ChromeProfilePath= "C:\Users\myuser\AppData\Local\Google\Chrome\User Data";
ChromeOptions options = new ChromeOptions();
options.AddArgument(string.Format("user-data-dir={0}", ChromeProfilePath));
ChromeDriver driver = new ChromeDriver(options);
It invokes the driver session with the current chrome profile successfully when a test is run but fails when run in parallel (invokes one instance, test it and fails the rest).
The error I receives for the failed one is
OpenQA.Selenium.WebDriverException : unknown error: failed to write prefs file
Note: I am using NUnit as test framework, C# and Selenium

Jenkins + Selenium WebDriver + MSTest issue

I have created a test method in Visual Studio 2010 Ultimate that checks for the existance of two text boxes. I instantiate "InternetExplorerDriver" in the AssemblyInitialize() method and have setup Jenkins (on Windows 7) to run the MSTest method using the MSTestRunner plugin. The test seem to pass but I'm not seeing the DOS command window that I see when the "InternetExplorerDriver" instantiates and also I'm not seeing the Internet Explorer browser from loading the web page at all even though the test has passed. I also call the Quit() method on the webdriver in AssemblyCleanup. I'm running Jenkins service as my own NT account on my local box as running the service as "Local System Account" has issues. Here's my code snippet:
InternetExplorerOptions ieOptions = new InternetExplorerOptions();
ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
webDriver = new InternetExplorerDriver(ieDriverDirectory, ieOptions);
The ieDriverDirectory has the InternetExplorerServer.exe running in 32bit mode. When I run the same test method from Visual Studio 2010 IDE or from the mstest.exe /testcontainer:, I'm able to see the DOS command window loading with the port number, the browser loading, the test method passing and the browser closing at the end when Quit() is called.

selenium webdriver on virtual machine

I'm working on a virtual machine using Selenium WebDriver. I'm trying to run tests on the machine I work on (again, virtual) and I'm getting a NoClassDefFoundError on the line where I instantiate my driver:
driver = new FirefoxDriver(ffBinary,ffProfile);
So, being on the virtual machine, I did some research and found I could use RemoteWebDriver. After trying this, I still get the same error. Any suggestions? I feel like this should run the same as being on a physical box, but it doesn't. It works perfectly on a physical machine.
Stacktrace:
java.lang.NoClassDefFoundError: com/google/common/io/Resources at org.openqa.selenium.firefox.FirefoxProfile.onlyOverrideThisIfYouKnowWhatYouAreDo‌​ing(FirefoxProfile.java:123)
at org.openqa.selenium.firefox.FirefoxProfile.<init>(FirefoxProfile.java:86)
at org.openqa.selenium.firefox.FirefoxProfile.<init>(FirefoxProfile.java:79)
at line 63 in my class is where it breaks: File profile = new File(PROFILE); //PROFILE = where FF profile is (63) FirefoxProfile ffProfile = new FirefoxProfile(profile)
You need to create the profile at the remoth machin
http://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles

can't find controls in page, but only when running via selenium-server

I have a set of tests that I've developed using the Selenium IDE in Firefox. Tests run fine and all pass. Now I'm trying to port those over to C# and run the tests for IE using MSTest and selenium-server. Here's the sequence of events:
Run all tests on Firefox via Selenium IDE. All tests pass.
Export tests to MSTest (Nunit export, rename some stuff etc.)
Start selenium-server-1.0.3
Run the tests in VS2008. Selenium setup is: selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://localhost/theSite/");; note that I can browse to http://localhost/theSite/ just fine.
4a. Confirm test is launching Firefox. Got result:
17:00:30.290 INFO - Preparing Firefox profile...
17:00:33.842 INFO - Launching Firefox...
First test ( waitForText "Login" in control "ctl00_TopNavBar_LoginStatus1") fails. Can't find the control.
if ("Login" == selenium.GetText("id=ctl00_TopNavBar_LoginStatus1")) break;
or
if ("Login" == selenium.GetText("ctl00_TopNavBar_LoginStatus1")) break;
All other tests fail as well -- same reason. Each test has a waitForText at the top.
Tried running the test in *chrome, *iexploreproxy and *firefox. All fail for the same reason.
Tried dumping a screenshot using selenium.CaptureEntirePageScreenshot("c:\\temp\\screenshots\\seleniumSite.png", "background=#FFFFFF"); and the screenshot is just a white bar.
So, my question is, how do I go about debugging this and figuring out what the real problem is? Clearly the page will render and the tests will pass. It's just when I try those tests in Selenium-RC that it fails so badly. Does the Selenium IDE have some bugs related to exporting tests to C#? (I have noticed one bug).
Are you executing selenium.Start() and selenium.Open()? Do you see the page opened in the browser?
Full initialization should be something similar to:
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://localhost/");
selenium.Start();
selenium.Open("/theSite/");
Important Note! test your IDE tests by starting with an empty page. Also, when using the IDE, if a command only has one parameter put it in the Target field, even if it isn't a control name.

Setup for IE6 (and multiple browsers) in Selenium Grid

I'm having a hard time trying to grasp some concepts on selenium Grid/RC. What I need is to provide specific environments (ie6-on-xp, ie7-on-xp, etc) to the tests. For what I've been reading, the browser line in grid_configuration.yml do not make any reference of what version of MSIE or Firefox I'm running. So I can't get my head around in which form I can tell Grid/RC that I want some specific browsers and the path to run them (how RC knows which exe to run?)
Second, I'd like to run portable versions of those browsers. I've only seen that specified in the tests, and not in the RC's command line to run them. That is the way to do it, per test?
I will answer your question by breaking up the info that you need
What I need is to provide specific
environments (ie6-on-xp, ie7-on-xp,
etc) to the tests.
Well since you can't have multiple IE instances on the same machine, I know there are apps that allow you to do that but in my experience they cause more issues than solving them. Ideally you want different machines to run the tests. By doing this you are also setting up a selenium farm for your devs to use because they can target a test at a specific instance. So setting up Grid as an Infrastructure is a good step.
For what I've been reading, the
browser line in grid_configuration.yml
do not make any reference of what
version of MSIE or Firefox I'm
running. So I can't get my head around
in which form I can tell Grid/RC that
I want some specific browsers and the
path to run them (how RC knows which
exe to run?)
The YAML just lets you know what the grid can handle. When starting up the grid you need to make sure that you pass in similar configurations. Think of Se:GRID like you would Se:RC except you don't care where the RC server is because you speak to a central place that works the rest out for you.
If you need it to run tests against a specific items then you will need to handle this in your test setup. There is a common misconception that all tests will run the same in every single browser. This will happen if you never rely on XPath or CSS selectors in your tests because browsers always handle this slightly differently and the slight differences can lead to flaky tests which should always be avoided.
One way to specify which browser to use for a test is to have a central configuration file. In C# this would be using the app.config that has a collection for each browser and doing
Config
<Firefox>
<addKey browserVersion='3.5.6' OS='WindowsXP'>
</Firefox>
Central Config Class looking inside 1 element
public class BoothElement : ConfigurationElement
{
[ConfigurationProperty("browserVersion", DefaultValue = "", IsKey = true, IsRequired = true)]
public string browserVersion
{
get
{
return ((string)(base["browserVersion"]));
}
set
{
base["browserVersion"] = value;
}
}
Tests
selenium = new DefaultSelenium(HubPort, HubPort, browserVersion, SUTServer);
selenium.Open("/test.htm");
//Rest of the test
In python you could create an Array in a module that you include on all your tests
include.py
hubServer = 'hub'
hubPort = 5555
sut = 'http://serverUnderTest'
firefox = [hubServer,hubPort,"\*chrome",sut]
iexplore = [hubServer,hubPort,"\*iehta",sut]
test.py
sel = selenium(firefox)
sel.open("/test.html")
#rest of the test
When using Selenium Grid try thinking of it more as a test infrastructure help framework and hopefully that will help you a little more.
Second, I'd like to run portable
versions of those browsers. I've only
seen that specified in the tests, and
not in the RC's command line to run
them. That is the way to do it, per
test?
I have never tried to get Selenium to work on mobile browsers and don't think it would work to well, however with Selenium 2 which is currently in alpha there is android support for testing apps.
EDIT FROM COMMENT
- name: "Firefox on OS X"
browser: "*firefox"
- name: "Firefox on Linux"
browser: "*firefox"
- name: "IE on Windows"
browser: "*iehta"
- name: "Safari on OS X"
browser: "*safari"
So say we have the above setup, according to the YAML file we have a number of different *firefox instances. So to call those different ones in our tests our browser setup command would look like
selenium.Start(hubHost, hubPort, "Firefox on Linux", "http://serverUnderTest");
or selenium.Start(hubHost, hubPort, "Firefox on OS X", "http://serverUnderTest");
The hub will translate that into *firefox for you. I prefer having very granular names for my environment instead of the usual *firefox so that if there is a failure its easier to spot where it was and on which specific browser.
Virtual machines can be very handy for setting up "inexpensive" mules in the Selenium Grid farm.