Selenium IE 11 test on Jenkins Master Server Using nunit3-console.exe - c#

I have a Selenium IE 11 test written in C# that runs perfectly when run locally in Debug or Release. this code is deployed to a Win 10 box with Jenkins (NO SLAVES). The Jenkins "Build" is configured to build the code, copy the test.dll to a folder and then call nunit3-console.exe to run the test. the Jenkins Service is also configured with a Domain User Account as a Service Logon Account.
I can logon to the win 10 box as the (Jenkins) domain user, and open a cmd window and run the following with no problem at all
C:\Program Files (x86)\Jenkins\workspace\Prod Login>"C:\Program Files
(x86)\NUnit.org\nunit-console\nunit3-console.exe" C:\Prod
Login\Tests\bin\Debug\Tests.dll
but if you try to "Build" the solution via Jenkins Web UI, it has a problem during the Nunit test finding some elements after it does a few clicks and a submit.
I know the IE configuration is rock solid like I said the test runs fine in a command window when logged in as the (Jenkins) Domain account
here is the error I get:
Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException :
Assert.Fail failed. ProcessError* By.XPath:
//input[#placeholder='Username'], Following element not found:
By.XPath: //input[#placeholder='Username'], Timed out after 75
seconds;
again I know its not the locator, it works with By.Id or By.Xpath in the command window, AND my Chrome, and Firefox test with the SAME code base just a different WebDriver all work.
I can't help but think it has something to do with the Identity that's being used by Jenkins and or Nunit
any help is greatly appreciated!!!
** UPDATE
I just tried to configure a Jenkins "Slave" with the service account
running as the Jenkins Domain user, no luck still...

I am unable to post just a comment, but I have a debug suggestion. I know what you are saying with "the selector works fine", so I am not suggesting that the selector is wrong in any way. However, I do suggest having the test spew the page source just before the failing command. Driver.PageSource. And post it somewhere you can get to it.
That way, you can identify that the driver definitely sees the elements in the DOM that it has available to it.
This will help eliminate a whole slew of potential problems. There is always the possibility that the driver is simply not seeing the html that these selectors would point to, even though we can see it with our own two eyes.

Related

Unable to Pass Selenium tests within Azure Pipeline

I am trying to build out UI test cases in our CI/CD build pipeline within Azure Devops and I can't seem to workaround a basic use case where we route to one of our internal web pages landing screen, and verify a Div with a Selector exists.
[Theory]
[InlineData("Chrome")]
public void TestFindElementByID(string browser)
{
var driver = SetupDriver(browser);
try
{
driver.Navigate().GoToUrl(TestConfig.WebURL);
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement element = wait.Until(ExpectedConditions.ElementIsVisible(By.Id("mainRepDiv")));
//Thread.Sleep(2500);
//IWebElement element = driver.FindElement(By.Id("mainRepDiv"));
Assert.True(element != null);
}
catch (Exception ex)
{
}
finally
{
driver.Quit();
}
}
In my web page, I have a basic div that I just want to see that it exists once the chromedriver navigates to the URL.
Element To Check
And here is a log of the Azure Pipeline failing on this test.
Pipeline Log
I do have an additional test that just asserts that the Browser is able to go to the URL, and the URL is in fact what I routed to, and that test passes.
driver.Navigate().GoToUrl(TestConfig.URL);
Assert.True(driver != null);
Assert.True(driver.Url.ToLower() == TestConfig.URL.ToLower());
There also some layers that likely are making this more difficult such as
The Azure Pipeline is running off a Self-hosted agent.
This self hosted agent is also the same server that is running the application were trying to test against.
There is OS level Security that shows up if you route to it normally, however as the Windows Server that is running the application would have a valid credential to the browser, it should bypass this dialog.
So things I have tried so far:
Various ways of actually selecting the Element incase that was off, such as By ID that is shown, or by XPath as well.
Using the Thread.Sleep() or the WebDriver Wait commands to determine if it was a page load.
Implementing AutoIT Process that will run in the event there is in fact an OS popup that displays, so I can prefill the Admin Username/Password credentials incase it actually is not getting there.
Running the unit test locally on my client PC, publishing the code to the Server, running the code from the application server directly and verifying it works there as well.
So I'm a bit at a loss what to check on regarding the Azure Pipeline build itself and why the ChromeDriver is unable to pass this test.
Finally - if this is also helpful, here is a screenshot of the YML file pertaining to the Tasks.
- task: VSTest#2
displayName: "Run UI Tests"
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\Project.Test.UI.dll
!**\*TestAdapter.dll
!**\obj\**
searchFolder: '$(System.DefaultWorkingDirectory)'
uiTests: true
Unable to Pass Selenium tests within Azure Pipeline
Please make sure your private agent run as an interactive process.
According to the document Interactive vs. service:
You can run your self-hosted agent as either a service or an
interactive process. After you've configured the agent, we recommend
you first try it in interactive mode to make sure it works. Then, for
production use, we recommend you run the agent in one of the following
modes so that it reliably remains in a running state.
As an interactive process with auto-logon enabled. In some cases, you might need to run the agent interactively for production use -
such as to run UI tests. When the agent is configured to run in this
mode, the screen saver is also disabled. Some domain policies may
prevent you from enabling auto-logon or disabling the screen saver. In
such cases, you may need to seek an exemption from the domain policy,
or run the agent on a workgroup computer where the domain policies do
not apply.
So, if your agent not run as interactive mode, please configure a another agent in interactive mode to test this issue.

Recurring ERR_CONNECTION_RESET in C# implementation of Selenium ChromeDriver

I've been battling the following error over the past few weeks trying to run UI tests with Selenium (Chrome 92):
WebDriverException unknown error: net::ERR_CONNECTION_RESET. (Session info: chrome=92.0.4515.107)
This occurs most often trying to locate HTML elements using XPath.
Originally, I added a retry loop which checks if the WebDriverException is thrown three times, and if so, recycle the IWebDriver and try again (via IWebDriver.Quit() and IWebDriver.Dispose(). This does not fix the problem, nor does having my application restart after exceeding the retry limit. Thus, I'm starting to think this is a problem at the system-level (Windows Server 2016). Even a reboot does not always fix the issue - when it starts to fail, it just totally freezes and I end up having to completely rebuild the environment.
I'm using the Selenium WebDriver NuGet v92.0.4515.4300; I realize this isn't in total parity with the version listed above, but having the exact same versions does not fix the problem.
I know 'unknown error' is vague. Does anyone have suggestions for what could be causing the problem?
Thanks in advance.
EDIT: Posting browser arguments here, rather than cramming them into a comment. I forgot to mention, there is an instance of Fiddler which we run as a proxy on the local system and use in conjunction with some tests. It's started and ended with the testing application.
The following are injected as options when creating the Chrome instance:
--user-data-dir=C:\temp\{uniquedir}
options.AddUserProfilePreference("credentials_enable_service", false);
options.AddUserProfilePreference("profile.password_manager_enabled", false);
And these are added as command-line arguments through Selenium:
--lang=en-GB
--ignore-certificate-errors
--no-experiments
--disable-translate
--disable-plugins
--enable-logging
--no-sandbox
--dns-prefetch-disable
--disable-gpu
--disable-field-trial-config
(We are doing some security-related detections, hence the disabling of certificate errors.)
You mentioned that you use Fiddler, if the issue is reproducible only when it is started, you can try to regenerate the HTTPS certificates
The issue can be due to the application itself. If the error is shown when you are not using Selenium/ChromeDriver you can ask your developers/devops to check the IIS settings or follow one of the suggestions below.
Check your Internet options from computer Settings->Network&Internet->Proxy. On my computer "Automatically detect Settings" is enabled.
You can also try to delete the Chrome browser cache.
Flush the DNS (ipconfig /flushdns)
It could be some rule (firewall, internal DNS record) configured for the network where is your Windows Server.
Check if the issue is reproducible in incognito mode (without any browser extensions enabled). You can pass --incognito argument when starting the driver.
Issue could be caused by a certificate or SSL/TLS problem.

TF.exe and TfSecurity.exe authentication on AzureDevOps

I have a piece of legacy c# code (console application) that runs as a nightly batch and fires off TF.exe and TFSSecurity.exe commands at AzureDevOps.
The commands are built by the c# code and then executed by means of launching PowerShell and executing them.
All have worked fine until now, but lately, it started failing for tf30063 authentication errors.
TF30063: You are not authorized to access https://dev.azure.com/
As part of my troubleshooting I have picked a few of these commands that are being built and executed them in an interactive PowerShell session.
tf permission /recursive $/<tfs_project_name>/ /collection:https://dev.azure.com/<organization_name>/
TFSSecurity /imx adm: /collection:https://dev.azure.com/<organization_name>/
It produces the same result - TF30063: You are not authorized to access https://dev.azure.com/.
The logged-on user (where the commands are run) is able to access this AzureDevOps URL via a browser.
Digging a bit deeper I ran the command: tf settings connections help which returned the following output:
Server Url : https://<organization_name>.visualstudio.com/
User :
I was actually expecting the passed URL here: https://dev.azure.com/
Not sure how this URL got there, or how to get it out - but, be that as it may, the empty user field arouses some suspicion.
I am really trying to figure out what the authentication flow/procedure is when executing these commands (TF and TFSSecurity) in Powershell.
I have been prompted for authentication by an AzureDevOps dialog once, but where do these provided credentials stored? And for how long?
I have been snooping around the Windows credentials in the Credential Manager, here I found some bits and pieces - but nothing conclusive.
Question:
Does anybody perhaps know how these 2 applications (tf.exe and TfSecurity.exe) handles authentication and storing of credentials?
System specs:
OS: Windows Server 2016
Powershell Version: 5.1.14393.3053
Location (version) of the tf.exe and TfSecurity.exe
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\
Team Explorer>
The cached credentials that tf.exe referenced might get corrupted. We donot know what caused this issue, nor can we give a certain method to fix this. You have to try below possible solutions to narrow down the fix.
1,
Using the browser from within your Visual Studio, View->Other Windows->Web Browser and navigate to the https://dev.azure.com/. Then check if it is logged in the wrong account, log out and relog in if wrong account is logged in.
2,
Running the following command from the Developer Command Prompt for VS:
tf workspaces /collection:https://dev.azure.com/<organization_name>
3,
Go to Team Explorer > Manage Connections (Little Plug next to Home button) > Right Clicked on Project > Connect. Then reenter in your credentials.
4, To clear all the caches
Close all Visual Studio instances, delete %LOCALAPPDATA%.IdentityService as you did.
Clear TFS caches %LOCALAPPDATA%\Microsoft\Team Foundation\7.0\Cache
Clear all the browser caches especially for the stored password
5, Run Visual Studio as another user:
cd C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE
runas /netonly /user: devenv.exe
Enter the user possword, then Team Explorer > Manage Connections
If none of the obove method fixes this issue. Please check here and here for more possible solutions.
You can also report a problem to Micrsoft Develop community(Report a problem > Azure Devops) if above issue persist.
For Server Url : https://.visualstudio.com/. It is the old version dev.azure.com domain name. The official document says it can be used as usual.
Update:
TF30063 error for TFSSecurity
The cached credentials for TFSSecurity is stored in the registry. You can delete it.
HKEY_CURRENT_USER\Software\Microsoft\VSCommon\14.0\ClientServices\TokenStorage\VisualStudio\VssApp
After you deleted the cached credentials in above registry. It will prompt you to re-enter the credential when you run tfssecurity.exe command again.

Coded UI Cross browser firefox does not work

I have an issue with codedUI. I have recorded step in Internet explorer. Step are lunching a website, login to the website and more... I tehn installed CodedUITestCrossBrowser following the instruction i could find http://blogs.msdn.com/b/visualstudioalm/archive/2012/10/30/introducing-cross-browser-testing-with-coded-ui-tests.aspx
I run the test in each browser. for IE and chrome the test work but with Firefox, it will not lunch the URL. The page open but nothing is done. My test will then give me this error.
Test method QaAutomatisation.Reseller.DristributorCreation threw exception:
Microsoft.VisualStudio.TestTools.UITest.Extension.UITestException: Failed to start up socket within 45000
at Microsoft.VisualStudio.TestTools.UITest.Extension.CrossBrowser.Utility.MapAndReThrow(Exception exception)
at Microsoft.VisualStudio.TestTools.UITest.Extension.CrossBrowser.CrossBrowserService.Launch(Uri uri)
at Microsoft.VisualStudio.TestTools.UITest.Extension.CrossBrowser.CrossBrowserFactory.Launch(Uri uri)
at Microsoft.VisualStudio.TestTools.UITesting.BrowserWindow.LaunchPrivate(Uri uri)
at Microsoft.VisualStudio.TestTools.UITesting.BrowserWindow.<>c_DisplayClass3d.b_3c()
at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod(Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)
at Microsoft.VisualStudio.TestTools.UITesting.BrowserWindow.Launch(Uri uri)
at QaAutomatisation.UINewTabWindowsInterneWindow.LaunchUrl(Uri url) in UIMap.Designer.cs: line 425
at QaAutomatisation.UIMap.LoginAdminCP() in UIMap.Designer.cs: line 71
at QaAutomatisation.Reseller.DristributorCreation() in Reseller.cs: line 44
//The code that have been generated is
// Go to web page 'http://master.controlpanel3.test.mail.dev.sherweb.com/' using new browser instance
this.UINewTabWindowsInterneWindow.LaunchUrl(new System.Uri(this.LoginAdminCPParams.UINewTabWindowsInterneWindowUrl));
// Type 'xyz' in 'Username' text box
uIUsernameEdit.Text = this.LoginAdminCPParams.UIUsernameEditText;
public void LaunchUrl(System.Uri url)
{
this.CopyFrom(BrowserWindow.Launch(url));
}
I am using visual studio premium 2012 with update 2, Selenium 2.32.1 and the crossbrowser extension.
Hope you have everything
Thanks again for the help !!
I got this error because I had an instance of Firefox running prior to my test executing. Make sure all of your Firefox browser windows are closed before running your coded UI test in Firefox.

Windows service not running. Error 1053

I m trying to run my windows service but it is giving error 1053: "timed out"
The error 1053 should pop up in case the start up method fails to respond in 30 seconds but in this case the OnStart method is not even reached. I tried debugging it but it is not helping as i don't even reach the actual code and the error message pops up before that. Can any one help in this case?
I had a similar issue when I was trying to install a service at remote desktop and erring
Error 1053: The service did not respond to the start or control request in a timely fashion
I was able to fix this issue by installing the targeted dotnet framework
(sometime remote servers on lower framework and we build the service using latest framework).
So my finding is that in these cases you need to check few things:
install proper dependencies
all dlls are with targeted framework
Main static method present in servivce.cs
I'm new to Windows Services development and Faced Same Issue
I tried everything that was given in this link this link and
in this link but still I was not able to fix issue!
Then I tried some other small things on my own and I found 2 things in my solution
Startup Object Not Set in solution properties
for this, right click -> windowsServiceProject -> click properties -> in there will be left menu in it click on ->Application ->Check "Startup Object" -> If its "empty" ? then click and select project/Service Name.Program (in my case the main method is in program.cs so..)
and if it's selected and is ok then... there can be an error in your code see point number 2
Error In Our Service Code
For this try to simply run the project with Pressing "Start".
If there are any exception or error Like: null pointer or, there were some wrong or missing path or anything that generates exception on running because of developer's mistake then it will show a thrown error and you will able to solve it EG:enter image description here
or if the code is ok then it will show like this:
a dialog box "Windows Service can not be debugged you have to install it
first then and then it will be able to run" (if this dialog shows it's ok normal behaviour if showing any exception then fix that thing and rebuild you will be able to start the service)

Categories