1. resources I used : C# , Selenium , VS 2017, Jenkins , VM machine (windows 10) , Nunit v3.9, geckoDrive v19, firefox v56/57
2. I can execute firefox / chrome browser cases on local machine
3. I can execute chrome browser cases on VM machine
4. Issue : **I can Not execute firefox cases on VM machine and its throwing below error.**
**Error Message**
OpenQA.Selenium.WebDriverException : Cannot start the driver service on http://localhost:50352/
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
I am adding few code below where issue is throwing issue
Stacktrace
at OpenQA.Selenium.DriverService.Start()
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(String geckoDriverDirectory, FirefoxOptions options, TimeSpan commandTimeout)
at MPAutomation.Driver.Initialize(String browser) in D:\Workspace.Automation\MPproject\MPAutomation\Utility\Driver.cs:line 79
# code on this line : Instance = new FirefoxDriver(service.FirefoxBinaryPath, options, TimeSpan.FromSeconds(10));
at MPAutomation.BaseTest.Init() in D:\Workspace.Automation\MPproject\MPAutomation\Utils\BaseTest.cs:line 54
#code here : LoginPage.GoTo(Settings.BrowserType); # I am passing "Firefox"
--TearDown
at MPAutomation.Driver.Close() in D:\Workspace.Automation\MPproject\MPAutomation\Utility\Driver.cs:line 117
# Instance.Close();
at MPAutomation.BaseTest.Cleanup() in D:\Workspace.Automation\MPproject\MPAutomation\Utils\BaseTest.cs:line 97
---------------------------------------------------------------------
firefox implemnetation looks like this in Driver.cs
- I tried with various version of Firefox too but none is working on VM
else if(browser.Equals(Constant.Firefox)) {
// driver init from here
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(DrivePath);
service.FirefoxBinaryPath = DrivePath;
var profile = new FirefoxProfile();
profile.AcceptUntrustedCertificates = true;
var options = new FirefoxOptions();
options.AcceptInsecureCertificates = true;
options.Profile = profile;
Instance = new FirefoxDriver(service.FirefoxBinaryPath, options, TimeSpan.FromSeconds(10));
Instance.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
Utility.Logger.Write("***** Firefox Browser has been initialized now *********");
}
--------------------------------
5. We have one certificate for firefox and which has already been taken care locally and on VM
6. I am not sure why automation is not able to start firefox on VM
Finally we got the solution of this issue.
We need to set up "sandbox level" for firefox on VM.
profile.setPreference("security.sandbox.content.level", 5);
https://github.com/mozilla/geckodriver/issues/466
https://wiki.mozilla.org/Security/Sandbox
Related
I have created script using TestNG annotation and maven. It runs expected in Eclipse, I also tried to run testng.xml file which looks good. and then I configured Jenkins but now Its not running. Jenkins giving error as below : (FYI : I have successful built in Jenkins previously , how this could broken in one day ???)
Starting ChromeDriver 72.0.3626.69 (3c16f8a135abc0d4da2dff33804db79b849a7c38) on port 48847
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Tests run: 7, Failures: 1, Errors: 0, Skipped: 6, Time elapsed: 4.774 sec <<< FAILURE! - in TestSuite
launchBrowser(com.pages.VisibilityAnnotationDemo) Time elapsed: 4.208 sec <<< FAILURE!
org.openqa.selenium.WebDriverException:
unknown error: Chrome failed to start: crashed
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Program Files (x86)\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=72.0.3626.69 (3c16f8a135abc0d4da2dff33804db79b849a7c38),platform=Windows NT 10.0.19042 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 872 milliseconds
I added below Jenkins config Root POM =
C:\Users....\workspace\VRsessions\pom.xml
Goals and options = clean install
The code I am try to run , Its script to do UI validation.
**public String baseUrl = " URL OF PAGE";
String driverPath = "C:\\Selenium\\chromedriver_win32\\chromedriver.exe";
public WebDriver driver;
JavascriptExecutor js = (JavascriptExecutor) driver;
#BeforeTest
public void launchBrowser() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", driverPath);
driver = new ChromeDriver();
driver.get(baseUrl);
}**
Tests on chrome, as far as I know, must be in headless mode to run on Jenkins. You'll need to set chrome options like this:
import org.openqa.selenium.chrome.ChromeDriver;
...
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
driver = new ChromeDriver(chromeOptions);
To fix this:
Add the the --disable-dev-shm-usage, --headless, --no-sandbox command line option to Chrome. And you also need to pass the ChromeOptions object to new ChromeDriver(options);
Code:
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("disable-infobars");
System.setProperty("webdriver.chrome.driver", driverPath);
driver = new ChromeDriver(options);
driver.get(baseUrl);
Setup is Windows 10 v1903 and Visual Studio 2019 v16.2.2
I've installed the EdgeDriver using the following command:
DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0
I've then created a new .NET Core console app and added the latest Selenium.WebDriver NuGet package (v3.141.0) to it. Then I've added code to Program.cs so that it looks like this:
using OpenQA.Selenium.Edge;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var edgeOptions = new EdgeOptions { AcceptInsecureCertificates = true };
new EdgeDriver(edgeOptions);
}
}
}
When I run the console app I get the following error when executing the new EdgeDriver(edgeOptions); line.
OpenQA.Selenium.WebDriverException
HResult=0x80131500
Message=The specified arguments passed to the command are invalid.
Source=WebDriver
StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at ConsoleApp1.Program.Main(String[] args) in ********\Program.cs:line 10
However if I change the value of AcceptInsecureCertificates from true to false then I get no exception and the browser opens as expected. This feels like a bug but I don't know if it's Selenium or the EdgeDriver that's at fault.
From the Microsoft Edge WebDriver document, we can see that the W3C WebDriver is still not support at present.
You could submit the Feedback at the bottom of the WebDeiver document.
I am using VS2017 on a Win10 (17134.471) machine and I just installed Selenium. I can get Chrome, Firefox, Edge to work but not IE11 (11.471.171340). I believe that I have done all the other suggested updates but continue to get:
There are no more files.
It is not clear as to what needs to be installed I installed using NuGet and the versions are:
Selenium.WebDriver v3.141.0 (14 updates since 3.6.0.0)
Selenium.WebDriver64 v3.11.0.1
Selenium.Webdriver.MicrosoftDriver v17.17134.0
Test Name: IeMethod
Test FullName: utLearn2018.FirstTestClass.IeMethod
Test Source: C:\Users\stephan\Documents\Visual Studio 2017\Projects\utLearn2018\utLearn2018\FirstTestClass.cs : line 44
Test Outcome: Failed
Test Duration: 0:00:22.3336919
Result StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at OpenQA.Selenium.IE.InternetExplorerDriver..ctor(InternetExplorerDriverService service, InternetExplorerOptions options)
at OpenQA.Selenium.IE.InternetExplorerDriver..ctor()
at utLearn2018.FirstTestClass.IeMethod() in C:\Users\stephan\Documents\Visual Studio 2017\Projects\utLearn2018\utLearn2018\FirstTestClass.cs:line 53
Result Message:
Test method utLearn2018.FirstTestClass.IeMethod threw exception:
System.InvalidOperationException: Unexpected error launching Internet Explorer. IELaunchURL() returned HRESULT 80070012 ('There are no more files.') for URL 'http://localhost:50326/' (SessionNotCreated)
My code is as follows:
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.IE;
[TestMethod]
public void IeMethod()
{
InternetExplorerOptions options = new InternetExplorerOptions
{
IntroduceInstabilityByIgnoringProtectedModeSettings = true,
EnableNativeEvents = false,
EnsureCleanSession = true
};
IWebDriver driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl("http://www.google.com");
driver.Manage().Window.Maximize();
driver.Close();
driver.Quit();
}
Some version of IE driver and selenium webdriver are not compatible. Worth trying different versions of IE driver and Selenium webdriver in order to launch the IE browser.
I am trying to setup an automated test environment using
- TestStack.Seleno v0.8.2
- TestStack.BDDfy v4.0.0
- Selenium .NET WebDriver 2.43.0.0
- Chrome v38
- ChromeDriver v2.9
While I am able to establish initial session hand shake between chrome driver and chrome browser, subsequent calls to actual web application via chrome driver are failing with timeout exceptions.
Here is the code to instantiate a SelenoHost object :
var options = new ChromeOptions();
Instance.Run(configure => configure
.WithWebServer(new InternetWebServer(String.Format("http://{0}/portal", IISServerHost)))
.WithRemoteWebDriver(() => BrowserFactory.Chrome(options))
.UsingLoggerFactory(new ConsoleFactory()));
If I debug the above method call, it fails inside SelenoApplication Initialize method :
public void Initialize()
{
_initialised = true;
_logger.Debug("Starting Webserver");
WebServer.Start();
_logger.Debug("Browsing to base URL");
Browser.Navigate().GoToUrl(WebServer.BaseUrl); >>> this line fails inside HttpCommandExecutor.CreateResponse() method
}
Not able to figure out what obvious am i missing out here.
BTW, web application is hosted on IIS 7.5 and is configured for windows authentication.
Launching chrome with 'no-sandbox' resolved the issue.
Here is how the final configuration looks like :
var options = new ChromeOptions();
options.AddArgument("ignore-certificate-errors");
options.AddArgument("no-sandbox");
var driverService = ChromeDriverService.CreateDefaultService();
driverService.EnableVerboseLogging = (ChromeDriverVerboseLogigng == "true");
driverService.LogPath = ChromeDriverLogPath;
_SelenoHostLazy.Value.Run(configure => configure
.WithWebServer(new InternetWebServer(String.Format("http://localhost/portal", IISServerHost)))
.WithRemoteWebDriver(() => new ChromeDriver(driverService, options))
.UsingLoggerFactory(new ConsoleFactory()));
The IEDriverServer is throwing a OpenQA.Selenium.WebDriverException when I try a simple navigation to a page. This is working for Firefox.
It is "Unexpected error" and if I read further along it appears to be a 404 page not found.
I have already disabled protected mode for all zones and had also made IntroduceInstabilityByIgnoringProtectedModeSettings = true on the InternetExplorerOptions object.
How does one get IE working in this case?
Edit
Here is the stacktrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response
errorResponse) at
OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String
driverCommandToExecute, Dictionary`2 parameters) at
OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities
desiredCapabilities) at
OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor
commandExecutor, ICapabilities desiredCapabilities) at
OpenQA.Selenium.IE.InternetExplorerDriver..ctor(InternetExplorerDriverService
service, InternetExplorerOptions options, TimeSpan commandTimeout)
at
OpenQA.Selenium.IE.InternetExplorerDriver..ctor(InternetExplorerDriverService
service, InternetExplorerOptions options) at
CUWebinars.Selenium.Core.Ie.IeTestDriver..ctor() in
e:\TTS\BankWebinars\CUWebinars.Selenium.Core\Ie\IeTestDriver.cs:line
21 at CUWebinars.WebUi.Tests.Ie.IeBaseTest.Setup() in
e:\TTS\BankWebinars\CUWebinars.WebUi.Tests\Ie\IeBaseTest.cs:line 13
Edit 2
The following is in the constructor of the IeTestDriver (custom class)
const string ieTestDriverLocation = #"E:\";
var internetExplorerDriverService = InternetExplorerDriverService.CreateDefaultService(ieTestDriverLocation);
var internetExplorerOptions = new InternetExplorerOptions();
internetExplorerDriverService.Port = 333; // this is the port for the driver, not the webpage
port = "5556"; // in base class
webDriver = new InternetExplorerDriver(internetExplorerDriverService, internetExplorerOptions); // crashes here
webDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
webDriver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(10));
The port 333 specified for the InternetExplorerDriverService falls within the well-known-port-numbers range:
On most systems, a well-known port number can only be used by a system
(root) process or by a program run by a privileged user.
Allow the driver service to select its own port by not specifying one explicitly, or provide an available port.
Double clicking IEDriverServer.exe will give you a Listening on port <number> message to see what it automatically picks up as available.