Selenium - Windows Auth Box Issue - c#

This is an odd one I need some help with. We have an automation project with a windows auth box. We were passing in the user/pass in the url string but we started to notice some issues. I wanted to setup AutoIT and see if this fixed the issue we were seeing but the url we go to is an internal ip:port. When I goto the url ex. 123.34.56.78:1111 the browser (chrome) opens but then fails with:
OpenQA.Selenium.WebDriverException: 'The HTTP request to the remote WebDriver server for URL http://localhost:7233/session/be85ee0483da9772b136488bed19c43b/url timed out after 180 seconds.'
It appears that webdriver is waiting for something to complete and I can't get to the next step.
I have tried the below but each one loads the page and then throws the error.
_webDriver.Navigate().GoToUrl(url);
_webDriver.Url = url;
Any ideas?

Related

Postman can query lcoal API, identical request send from android emulator can't

I've seen some similar issues, but nothing here seems to match my problem exactly.
I'm running a version of my API (C#) locally to test some updates. Its hooked up to a local SQL database.
When I run a query to get a token, postman works as expected. However, when I boot up my android emulator (xamarin) and run the same query, the requests times out with error code 0 almost instantly. I've set it to not time out at all. Another strange thing is that when I set the breakpoints in the local API, postman triggers those breakpoints, but the android app doesn't.
This is odd because both postman and the android app can query the live version of the API in the servers.
I've heard this might be a CORS issue?
Steps to reproduce the issue:
Start up the local API which opens up a webpage to a local port.
Test the port is working by sending a request with postman. The request I tried was requesting a token.
Use postman to generate restsharp code, and run that code from inside the xamarin android project.
The error I get is always status code 0.
Code:
The following code was generated via postman after a successful request.
var client = new RestClient("http://localhost:53884/token");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddHeader("Cookie", ".AspNet.Cookies=7u9...JRrb");
request.AddParameter("username", "redacted");
request.AddParameter("password", "redacted2");
request.AddParameter("grant_type", "password");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
I can't share the API code due to IP, but it works for the app when running on the servers, and both locally and live for postman.
I have solved my issue, so I'll relay the steps I took.
This is assuming that you are running an API locally, and that you want be able to access the localhost with your android emulator. For the record, my android emulator is running my xamarin app, but it should work for any app.
Install Conveyer (I followed these instructions)
Close Visual studio.
Allow Conveyer to install
Open Visual Studio again
When prompted about the firewall, let Conveyer automatically set your posts
Open your API solution
Right click on your API project and select "Set as start up project"
The text next to the green run arrow at the top should change. Mine changed to "IIS Express (Microsoft Edge)". I believe you can change this in the web config file.
Press the green arrow. This should do a few things. Firstly, it should open up a browser at a localhost address. For me it was http://localhost:53884/ . Don't be concerned if you get an error like "Server Error in '/' Application." Although I assume if you had the exact same problem as me, yours also worked in postman, so you've gotten this far.
At the bottom of visual studio the will be a tab called "Conveyer by Keyoti". Click on it to reveal the URLs. Copy the http Remote URL address.
Now open your xamarin app and wherever you were setting your API address (where you had local host), replace that address with the Remove URL address.
Run your xamarin app, it should be able to access the API now.
I will say, I haven't got the https Remove URL working yet. I get the error: Error: SecureChannelFailure (Authentication failed because the remote party has closed the transport stream.) . My API allows both HTTP and HTTPS requests, so HTTP works for me, but if I get HTTPS working, I'll add an edit with how I did it.

Can't log in to site under Selenium WebDriver

I am having a strange issue where I am unable to log into a site under test with the Selenium WebDriver, but am not having any issues logging in when running the project under test in Visual Studio, or in our QA environment.
I have broken the test down to the most simplistic example, where it allows me to manually enter the username, password, and click the login button while it waits for verification that it has moved on to the next screen (waits for an element on that page).
All that happens when running under Selenium is a page refresh.
The test:
driver.Navigate().GoToUrl(this._baseURL + "Account/Index");
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
wait.Until(drv => drv.FindElement(By.Id("element-on-next-page")));
The login button calls the jQuery $.ajax method to POST data to a service, and is correctly going into the success() method. The service returns a redirect URL.
This, in turn, attempts to redirect, which works when working with the site manually, but simply re-loads the login page when under a Selenium test:
window.location.replace(location.origin + result.RedirectTo);
I have verified that the result.RedirectTo is valid when the test is running (it is the page it should be redirecting to for successful login).
Tested with Chrome 71.0.3578.98, Firefox 64.0.2 and IE 11.472.17134.0. It works fine manually in all three.
I am unsure why this behavior is acting differently under automation.
UPDATE: The page it is attempting to redirect to has an [Authorize()] attribute on the controller. Removing this attribute allows the test to pass. The attribute only causes Selenium tests to fail, not manual testing.
have to try to perform login steps manually on the chrome browser launched by Selenium?
I am not sure but sometimes google redirects to authorization page or verify your identity page just to ensure you are not using automation scripts for creating multiple emails signup or scraping any website data.
Just try to run the same scenario manually on the browser launched by selenium.

The requested url was rejected

I am working on a simulation site using selenium .
I launched on a server to start testing it,
after a will the targeted url is giving this error message while it is navigated to by chrome
The requested URL was rejected. Please consult with your administrator.
Your support ID is: 8410459054496748680
I tried to navigate to this site as a user and cleaned my browsing history and cache
and it keeps giving me this error
You are block by a firewall ASM.
The data you are trying to pass are detected as threats and your request is denied. You need to resolve this with you Network engineer by providing him the ID.
NOTE: Cookies cleanup might also work sometimes!

Launching Browser in end user machine

We have an internal ASp.NET MVC application which receives requests from an external system.The request looks something like this:
http://test.com/abc/showinfo/12345678990
Controller Action
[Route]
public ActionResult Showinfo(string somenumber)
{
if (somenumber.Contains("1234"))
// Launch Chrome Browser
else
// Launch IE Browser
}
I tried with Process.Start(url ), its works fine in my localbox but fails in Dev server.
Is it possible to Launch a browser in end user system? if yes then please let me know the steps.
Is it possible to Launch a browser in end user system?
Yes.
You can use PsExec to do it. But do note that if you impersonate credentials, it will send the password over the network in plain text.
psexec \\marklap c:\thebrowserpath\thebrowser.exe
References:
http://windowsitpro.com/powershell/common-ways-run-programs-remote-computers
http://ss64.com/nt/psexec.html
System.Diagnostics.Process.Start("iexplore.exe", "http://google.com");
You can replace http://google.com with your custom url
I don't know if it is possible with your solution, but I think it would be more sensible to open a browser on the client as reaction to an answer from your service, i.e. the following workflow
The client sends a request to your server
Your server processes the request and constructs and answer. This answer contains the URL and the desired browser
The server sends the answer back to the client
The client receives the answer and checks for the URL and the desired browser
The client starts the desired browser with the URL
Depending on the client system (is it some sort of custom application/service?) opening the a new browser could be quite simple (Process.Start() or similar). If the whole thing runs in a browser, it could also be just opening a new tab (if it's the same browser). Opening an alternative browser may be tricky, but could be possible for instance in Chrome with Native Messaging (https://developer.chrome.com/extensions/nativeMessaging)

WebClient request timeout

I'm trying to return some html from a url via the WebClient class:
Response.Write(new System.Net.WebClient().DownloadString("http://www.partnersite.com/html/"));
Whenever this code runs I get a timeout.
The request was aborted: The operation has timed out.
If I browse directly to "http://www.partnersite.com/html/" I get an immediate response.
The timeout only seems to happen with this particular website, if I make a request to another site eg.
WebClient().DownloadString("http://www.google.com"));
I'm instantly returned the html.
Is this simply a case of something going on at the partner site which means it's not responding? Or is there something else I can try before making that call?
Thanks.
Is the site accessible from Internet Explorer?
If not and if the site is in the same network, check whether you have bypassed the proxy for the site from the Internet Explorer options.

Categories

Resources