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
Related
I just got back into selenium testing and I'm using the basics:
initialized on top is
public static WebDriver driver=null;
and then depending on what is set in a properties file, it loads either the chromedriver or edgedriver.
System.setProperty("webdriver.edge.driver", System.getProperty("user.dir")+"//BrowserDrivers//msedgedriver.exe");
driver = new EdgeDriver();
and for chrome:
System.out.println(System.getProperty("user.dir")+"//BrowserDrivers//chromedriver.exe");
driver = new ChromeDriver();
it works for the most part, except it keeps opening two browser pages at once? which eventually leads to a disconnect because it uses the second page opened, then when it tries to close the page (ie, driver.quit()) to start the next test case, it successfully closes the page it ran the first test but because of the first page that was opened, it throws this error:
WARNING: Process refused to die after 10 seconds, and couldn't taskkill it
java.lang.RuntimeException: Couldn't detect pid
I am using the most updated and stable versions of both webdrivers and selenium4.5, and webdrivermanager5.3
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.
I have the following setup:
A Selenium server hub running at "http://localhost:hubPortNum" (a service with the Jar file selenium-server-standalone-3.141.5.jar with parameter -role hub).
A Selenium Node at running "http://localhost:nodePortNum' (the service with Jar file with parameters: -Dwebdriver.chrome.driver=ChromeWebdriverPath -role node -port :nodePortNum).
I checked the URL for the hub and node instances to be sure they are working.
Whenever I try to create Remote Webdriver via Python script:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
desiredCapabilities = DesiredCapabilities.CHROME.copy()
chromeOptionsRemote = webdriver.ChromeOptions()
chromeOptionsRemote.add_argument("--start-maximized")
chromeOptionsRemote.add_argument("--disable-session-crashed-bubble")
initRemoteDriver = webdriver.Remote(options=chromeOptionsRemote, command_executor='http://127.0.0.1:<nodePortNum>/wd/hub', desired_capabilities=desiredCapabilities)
print(initRemoteDriver.current_url)
The last line does print the current URL(which is "data:,"), that means Webdriver is created.
But the browser does not open on my local machine, that is it is running in the background and I don't know how to make it visible although it has worked in the past.
The troubleshooting steps I have made:
Reinstall latest selenium python package.
Re-Download latest Selenium server jar file.
Updating chrome.
adding chromeOptionsRemote.add_argument("--no-sandbox")
Making sure local Webdriver does open:
That is the line:
self.localDriver = webdriver.Chrome(options=chromeOptionsLocal,
desired_capabilities=desiredCapabilities)
does open the browser locally(the Chromedriver is in the path).
After I made these troubleshooting steps, I have tried the same configuration on a remote server and got the same result(browser not visible), so I think this is probably by design.
what configuration should I create for the browser to be visible?
Any help would be appreciated.
I was running the jar file by Always-Up: https://www.coretechnologies.com/products/AlwaysUp/
The problem was related to session 0 isolation: https://stackoverflow.com/a/26752251/2710840
in order to not run the application under session 0, I have enabled the Autologon feature:
defined the user under the application run as my user:
and executed the application from the context menu with the option to: "restart in this session"
I have test cases which i have written in robot framework. I have written one library for robot framework but it all for selenium. I am using firefox browser. This test cases are working fine if i am running through command line.
If I start test cases using jenkins this error will show. I am using shell command to start robot framework.
NoSuchElementException: Message: Unable to locate element: {"method":"link text","selector":"Config Box"}
Stacktrace:
at FirefoxDriver.prototype.findElementInternal_ (file:///tmp/tmpkRQ7Lc/extensions/fxdriver#googlecode.com/components/driver-component.js:10770)
at FirefoxDriver.prototype.findElement (file:///tmp/tmpkRQ7Lc/extensions/fxdriver#googlecode.com/components/driver-component.js:10779)
at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmpkRQ7Lc/extensions/fxdriver#googlecode.com/components/command-processor.js:12661)
at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmpkRQ7Lc/extensions/fxdriver#googlecode.com/components/command-processor.js:12666)
at DelayedCommand.prototype.execute/< (file:///tmp/tmpkRQ7Lc/extensions/fxdriver#googlecode.com/components/command-processor.js:12608)
When running tests with Jenkins there are different timings on when the elements are available. Try to use keywords of Wait For ... or Sleep.
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.