I'm running into an issue that seems to be related to webdriver/nunit.
On the initial running my first test [Setup] and [Teardown] work. When the system tries to run my next test, which requires a [Setup] it doesn't seem as though the WebDriver is called.
[SetUp]
//This has to be done for all tests. It is the setup I say!
public void Setup()
{
LaunchBrowser();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(45));
}
[TearDown]
//This has to be done for all tests. It is the teardown I say!
public void TearItDown()
{
driver.Dispose();
}
If I comment out the [Teardown], all my tests run no problem.
LaunchBrowser()
public static IWebDriver driver = new InternetExplorerDriver();
public string landingPage = "http://www.smartdrive.net";
public void LaunchBrowser()
{
driver.Navigate().GoToUrl(landingPage);
}
I have tried on the last test to add a driver.Dispose(); figuring I could just close the session once all tests run, but it doesn't seem to do the trick.
error I receive with [Teardown] in place
Result Message:
OpenQA.Selenium.WebDriverException : Unexpected error. System.Net.WebException: Unable to connect to the remote server --->
System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:51089
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
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.FindElement(String mechanism, String value)
at OpenQA.Selenium.By.FindElement(ISearchContext context)
at UnitTestProject1.Browser_Landing.getLandingPlacement() in c:\Users\erikag\Desktop\AutomationTests\VS_NetSeleniumTest\UnitTestProject1\UnitTestProject1\Browser_Landing.cs:line 30
at UnitTestProject1.ServiceConsoleTest.PlacementChk() in c:\Users\erikag\Desktop\AutomationTests\VS_NetSeleniumTest\UnitTestProject1\UnitTestProject1\TestSuite_LandLog.cs:line 46
I did read somewhere that the issue was correlated to the webdriver having issues relaunching after the the [Teardown], but I can't seem to figure out how to work around this.
You are disposing the driver after every run but not instantiating before each run. So driver won't work as expected. Instantiate the driver inside LaunchBrowser() method and re-run the tests
Just more info Dispose() resets the diver and, thus the instance is not valid anymore with the code block you posted. See this
And, best practice is probably using Quit instead of Dispose because Quit() calls Dispose and does some more clean up so you don't have to use Dispose separately.
And, with the change the LaunchBrowser() method should look like the following:
public IWebDriver Driver;
public string landingPage = "http://www.smartdrive.net";
public void LaunchBrowser()
{
driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl(landingPage);
}
Related
I am using pretty old chromedriver 2.38.0.1 and cannot use any newer version since Chrome wouldn't work on it.
So when I launch a test on chromedriver 2.39.0 - 80.0.3987.1600-beta Chrome is started but it doesn't return a control. It crashes on
driver = new ChromeDriver();
Got next message in console:
Starting ChromeDriver 76.0.3809.126 (d80a294506b4c9d18015e755cee48f953ddc3f2f-refs/branch-heads/3809#{#1024}) on port 56951
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
DevTools listening on ws://127.0.0.1:63198/devtools/browser/96d16462-dfb4-48d0-b4f7-a9c1be000b50
[23236:20720:0905/154153.867:ERROR:ssl_client_socket_impl.cc(946)] handshake failed; returned -1, SSL error code 1, net_error -100
[15164:21256:0905/154153.867:ERROR:connection_factory_impl.cc(413)] Failed to connect to MCS endpoint with error -100
[15164:21256:0905/154217.733:ERROR:connection_handler_impl.cc(399)] Received message of invalid type 84
Tried it on C# and Java and in both cases have the same issue.
I have next options but don't think that I may somehow cause the problem:
private static ChromeOptions GetChromeOptions()
{
String userProfile = Config.TestInputDirectory + "ChromeProfile";
var userProfile = "ChromeProfile";
options.AddArguments("user-data-dir=" + userProfile);
options.AddAdditionalCapability("useAutomationExtension", false);
options.AddExcludedArgument("enable-automation");
options.AddArguments("--incognito");
options.AddArguments("--disable-dev-shm-usage");
options.AddArguments("--no-sandbox");
options.AddArguments("start-maximized");
options.AddArguments("--disable-gpu");
return options;
}
Google Chome version is 76.0.3809.132 (Official Build) (32-bit).
Note: chrome is controlled by administrator so I cannot download it manually from the official website and install.
Any suggestions what may cause it and how to fix it?
Update 1:
Added Result StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
--- End of inner exception stack trace ---
at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
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.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor()
at UnitTestProject1.UnitTest1.TestMethod1() in C:\Users\.....\UnitTest1.cs:line 12
Result Message:
Test method UnitTestProject1.UnitTest1.TestMethod1 threw exception:
OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:54932/session timed out after 60 seconds. ---> System.Net.WebException: The request was aborted: The operation has timed out.
Update 2:
Starting ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945#{#614}) on port 55361
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[12716:12284:0207/124619.539:ERROR:configuration_policy_handler_list.cc(90)] Unknown policy: EnableCommonNameFallbackForLocalAnchors
[12716:12284:0207/124619.540:ERROR:configuration_policy_handler_list.cc(90)] Unknown policy: EnableSha1ForLocalAnchors
[12716:12284:0207/124619.541:ERROR:configuration_policy_handler_list.cc(90)] Unknown policy: WelcomePageOnOSUpgradeEnabled
[12716:12284:0207/124620.242:ERROR:configuration_policy_handler_list.cc(90)] Unknown policy: EnableCommonNameFallbackForLocalAnchors
[12716:12284:0207/124620.244:ERROR:configuration_policy_handler_list.cc(90)] Unknown policy: EnableSha1ForLocalAnchors
[12716:12284:0207/124620.244:ERROR:configuration_policy_handler_list.cc(90)] Unknown policy: WelcomePageOnOSUpgradeEnabled
DevTools listening on ws://127.0.0.1:55372/devtools/browser/f0c55ef0-77be-436b-a60f-ee210dfeadf3
Unhandled Exception: OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:55361/session timed out after 60 seconds. ---> System.Net.WebException: The request was aborted: The operation has timed out.
at System.Net.HttpWebRequest.GetResponse()
at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
--- End of inner exception stack trace ---
at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
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.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options)
at ConsoleApp1.Program.PrepareDriver() in C:\Users\...\source\repos\ConsoleApp1\ConsoleApp1\Program.cs:line 22
at ConsoleApp1.Program.Main(String[] args) in C:\Users\...\source\repos\ConsoleApp1\ConsoleApp1\Program.cs:line 11
Press any key to continue . . .
I have setup a selenium grid with port 4444 for hub and node with port 5555. When I try to access console of the hub by http://localhost:4444/wd/hub/console I am getting the below logs.
When i tried to access the session http://localhost:4444/wd/hub/session of my grid getting below errors.
I am using C#.net for my test and from my test when I try to initilaize the remotedriver instance, I am getting error
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) in D:\SeleniumCode\selenium\dotnet\src\webdriver\Remote\RemoteWebDriver.cs:line 1384
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) in D:\SeleniumCode\selenium\dotnet\src\webdriver\Remote\RemoteWebDriver.cs:line 1187
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities) in D:\SeleniumCode\selenium\dotnet\src\webdriver\Remote\RemoteWebDriver.cs:line 1114
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities) in D:\SeleniumCode\selenium\dotnet\src\webdriver\Remote\RemoteWebDriver.cs:line 141
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan commandTimeout) in D:\SeleniumCode\selenium\dotnet\src\webdriver\Remote\RemoteWebDriver.cs:line 128
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(Uri remoteAddress, ICapabilities desiredCapabilities) in D:\SeleniumCode\selenium\dotnet\src\webdriver\Remote\RemoteWebDriver.cs:line 117
Below is the code.
` var driverContext = new WebDriverContext();
DesiredCapabilities capability = DesiredCapabilities.Chrome();
capability.Platform = new Platform(PlatformType.Windows);
try
{
driverContext.Driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capability);
driverContext.Driver.Navigate().GoToUrl(url);
context = driverContext;
}
catch(Exception ex)
{
}
return driverContext;`
There are three issues that have been mentioned in this post.
Grid console url problem.
You are hitting an invalid Grid console URL. The correct URL is http://localhost:4444/grid/console.
How to get the session details for a particular session in Grid.
For you to be able to access the details of a session, you should be hitting the URL http://localhost:4444/grid/api/testsession?session=%s where %s represents the session id that you obtain from RemoteWebDriver. SessionId
Encountering an issue when trying to instantiate RemoteWebDriver.
W.r.t the error that you are getting when you are trying to instantiate a new RemoteWebDriver instance, I can't seem to find anything that stands out (I am Java guy so I can't read C# full fledgely, but looking at the code snippet nothing stands out).
The exception however suggests
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) in D:\SeleniumCode\selenium\dotnet\src\webdriver\Remote\RemoteWebDriver.cs:line 1384
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) in D:\SeleniumCode\selenium\dotnet\src\webdriver\Remote\RemoteWebDriver.cs:line 1187
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities) in D:\SeleniumCode\selenium\dotnet\src\webdriver\Remote\RemoteWebDriver.cs:line 1114
that you may have an issue with the ChromeDriver binary not being available in the PATH variable. Please check to see if its available in your path and if it can be spun off by running chromedriver from a command prompt ? Also you might want to cross check its presence in the PATH variable by running echo %PATH% and then scanning the output to see if it includes the directory in which chromedriver exists.
I am using selenium and chromedriver for testing. While running my code on window server 2012, the task manager is showing the chromedriver.exe process is running but after 60 second.
I am getting the following exception:
System.InvalidOperationException: unknown error: cannot find Chrome
binary (Driver info: chromedriver=2.12.301325
(962dea43ddd90e7e4224a03fa3c36a421281abb7),platform=Windows NT 6.2
x86_64) 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.Chrome.ChromeDriver..ctor(ChromeOptions options) at
OpenQA.Selenium.Chrome.ChromeDriver..ctor()
Following is the my code segment where the exception is thrown:
The chromedriver.exe is inside C:\inetpub\vhosts\mywebsitename.com\httpdocs\bin
Code:
driver = new ChromeDriver(#"C:\inetpub\vhosts\mywebsitename.com\httpdocs");
driver.Url = "https://www.google.co.in/";
Can anyone suggest me , where is the problem, B'coz chromedriver.exe running process is their in task bar when the program execution starts.
Here is the working java code to launch chrome and open the url entered :
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "Path_to_Chrome.exe\\chromedriver.exe");
driver= new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://facebook.com/");
driver.close();
}
I hope this will work
I am trying to integrate SonarQube MSBuild runner with TFS 2013 and I am using SonarQube 5.2 version and MSBuild.SonarQube.Runner-1.0.2 with all the required plug-ins for LDAP, .NET and C#. I get this error when I run the TFS Build:
Unhandled Exception: System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
at System.Net.WebClient.DownloadString(Uri address)
at System.Net.WebClient.DownloadString(String address)
at SonarQube.TeamBuild.PreProcessor.WebClientDownloader.Download(String url)
at SonarQube.TeamBuild.PreProcessor.SonarWebService.GetProperties(String projectKey, ILogger logger)
at SonarQube.TeamBuild.PreProcessor.PropertiesFetcher.FetchProperties(SonarWebService ws, String sonarProjectKey, ILogger logger)
at SonarQube.TeamBuild.PreProcessor.TeamBuildPreProcessor.FetchArgumentsAndRulesets(ProcessedArgs args, String configDir, ILogger logger, IDictionary`2& serverSettings)
at SonarQube.TeamBuild.PreProcessor.TeamBuildPreProcessor.DoExecute(ProcessedArgs args, ILogger logger)
at SonarQube.TeamBuild.PreProcessor.TeamBuildPreProcessor.Execute(String[] args, ILogger logger)
at SonarQube.TeamBuild.PreProcessor.Program.Main(String[] args)
Exception Message: TF270015: 'MSBuild.SonarQube.Runner.exe' returned an unexpected exit code. Expected '0'; actual '-532462766'. See the build logs for more details. (type UnexpectedExitCodeException)Exception Stack Trace: at System.Activities.Statements.Throw.Execute(CodeActivityContext context) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
Only technical users are supported for authentication from MSBuild.SonarQube.Runner.exe or SonarQube Runner against SonarQube 5.2 with LDAP plugin 1.5.1(and Windows Authentication mode enabled).
I m trying to do automation testing using "Selenium Remote Webdriver" but getting an exception when try to connect with remote server.
The exception is:
Unexpected error. System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:4444
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\HttpCommandExecutor.cs:line 109
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 836
The code I have written is:
DesiredCapabilities capabilities = DesiredCapabilities.Firefox();
capabilities.Platform = new Platform(PlatformType.Vista);
capabilities.SetCapability("api_key", "REPLACE_API_KEY");
capabilities.SetCapability("api_secret", "REPLACE_API_SECRET");
var remoteAddress = new Uri("http://122.176.112.91:4444/wd/hub");
// ... but only if it supports javascript
capabilities.IsJavaScriptEnabled = true;
// Get a handle to the driver. This will throw an exception
// if a matching driver cannot be located
IWebDriver driver = new RemoteWebDriver(remoteAddress, capabilities);
driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));
// Query the driver to find out more information
ICapabilities actualCapabilities = ((RemoteWebDriver)driver).Capabilities;
Please help me to sort out this prolem.
Thanks in advance.
The stack trace indicates the local machine is actively refusing any connections. Double-check that Firefox is permitted on all ports by the firewalls.
Unfortunately, I've encountered this problem even when the firewall is open:
C# + VisualStudio + Multiple WebDriver instances = SocketExceptions