Browser opening, but failing to load localhost page--Selenium, MVC, C# .NET - c#

I am starting to write tests for a project that is in its 8th agile sprint. I was brought on the team about one week ago.
Yesterday my Selenium tests were passing against the git master branch. I was accessing the http localhost address, opening it, running a test, and then closing the browser all from the Selenium code.
My team changed the access (somehow, don't quite understand) and the http localhost address changed. This was yesterday evening. Pulled the new code this morning from git.
I found the new address, and replaced it in my localhost constant. Ran the tests. Now the tests open the browser, no localhost info is entered into the url, test times out, test fails. All I changed was the localhost address.
When I just run start from the Visual Studio ribbon start button, the web app will open two windows in the browser (Firefox default). The team lead says that both windows are needed right now.
I am fairly new to Selenium (1 month and learning) and very new to .NET/Visual Studio/C# (day 4).
Researched the issue, only thing I have found that might make sense is creating an ASP.NET HTTP Module-- And I have read up on it, but don't know if it is THE solution.
If anybody has any other ideas, please let me know.
thx
a
EDIT : CODE
string URL = "http://localhost:54879/"; //unable to connect
....
driver.Navigate().GoToUrl(URL);

Had our local Microsoft guru look at what was happening. Tests run/console connects if I run after selecting start without debugging. I am v. new to Visual Studio, so I guess it was set up wrong in my tray and this makes it run properly.

In my case, the problem was that there was i needed to first run the programme without debuggen ( Debug > Start without Debugging).

Related

C# ASP.NET TempData was working but now it isn't on 2 of 3 computers

I'm working on a .net Core MVVC project devloped in VS Community 2017 and using IIS Express 10 and I'm having issues with TempData not working on two of the 3 computers I develop on. At one point it did work on all three.
I use TempData to store info during redirects and then transfer TempData to ViewData to display on the View page. I had issues with something (I don't remember what it was now) and was getting help from a co-worker and during his troubleshooting a box popped up and said something about SSL and I don't remember what he clicked but since then TempData stopped working. The one thing I think he did do differently than me was along the top in the Debug area, he clicked the IIS Express dropdown and chose the project name option instead. TempData now shows up as null after the redirect. When I open up the project on my home computer, TempData works with no issues. I have a 3rd computer I do some development on and it used to work on that until the SSL box popped up on that as well and it stopped working. I'm guessing that it's redirecting to the page I want but it's making a pit-stop somewhere along the way and the data is lost.
I tried uninstalling and reinstalling both VS and IIS Express with no change. I also tried deleting the .vs folder in the solution with no change. I tried clearing out the websites using the IIS Express command in the command prompt. I also tried it in both Chrome (where it used to work) and Internet Explorer with no change. I've tried running it with debugging and without debugging with no change.
So, TempData no longer works on two computers (both Windows 10 if it matters) and my home computer (Windows 7) works just fine. Anyone have any ideas?
by close look to your question, at first
"a co-worker and during his troubleshooting a box popped up and said
something about SSL and I don't remember what he clicked"
mybe your co-worker enabled ssl on development environment and after run the project you have to trust local IIS certificate.
I think you have to config cookie for using SSL for example <httpCookies requireSSL="true" /> or you can disable SSL for development and every thing gonna be OK.
for sure you can check that in home computer your URL have HTTP and in other two computers the URL starts with HTTPS.
On the other hands I suggest you to compare the web.config structures.
I found the answer finally at https://github.com/aspnet/Mvc/issues/8233
To fix the issue, I modified my Startup.cs file so that app.UseCookiePolicy(); was placed after app.UseMvc();. I don't know why it only affects one of my computers but it fixes the issue.

How to set up reliable parallel browsers environment based on Selenium

I'm having some troubles with building reliable environment for our Selenium based UI tests. We have tried Selenium Grid + latest Firefox (+ 41.x), Latest Chrome as well but they are always some problems with hanging browser and failing tests because of that (or builds). SeleniumDriver is latest as well (nuget 2.49.0).
I can mention also some crazy things like even with all this we still can't make browsers go full screen if test are started from Team City job against Selenium grid:
firefoxDriver.Manage().Window.Maximize();
//Make Firefox fullscreen for TeamCity agent's runs
((IJavaScriptExecutor)firefoxDriver).ExecuteScript(
"window.resizeTo(screen.width, screen.height)");
firefoxDriver.Manage().Window.Position = new Point(0, 0);
firefoxDriver.Manage().Window.Size = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
firefoxDriver.FindElement(By.CssSelector("body")).SendKeys(Keys.F11);
We also tried to run the test locally by installing team city agent on the virtual machine (we use Azure) - still same problem - maybe even worse...
Before each test we start new browser and after it we stop it with:
Driver.Close();
Driver.Dispose();
Driver.Quit();
but still they are some unstopped/hang browsers...
When executed locally from Visual Studio 1 by 1 (not as a suite) everything is OK.
Any suggestions what we might have done wrong?
Is it entirely browser fault? And if yes what we can use? I would like to try PhantomJS (Ghostdriver) but it's kind a outdated and have another set of problems with it. Any other option? IE 11 also have a problem -> Selenium Server error: Unable to get browser which did not quite work for us.
Not to mention some stuffs like 5 dropdowns can be automated but the 6th one is not working in Firefox, but works on Chrome and vice versa.
Also I have a feeling the Azure VM is really slow maybe real machine would help (keep in mind that even on my machine if I run it with team city commands browsers hangs as well).
I'm pretty sure someone else also face all this problems and hopefully have some guidance to share which I think would be helpful to others as well in the road to stable automation environment for Selenium UI tests.
Try to see the change Log under selenium official website, and use the browser and selenium which are compatible to each other. After that you can use the code for setup and login.

Can't access WCF service through browser

I've been following this series of tutorials (https://msdn.microsoft.com/en-us/library/ms734712(v=vs.110).aspx) on getting started with WCF, and it's all been going well up until step 3 (https://msdn.microsoft.com/en-us/library/ms730935(v=vs.110).aspx), specifically up until the bottom, where it says "Open Internet Explorer and browse to the service's debug page at http://localhost:8000/GettingStarted/CalculatorService"
Basically, what this should be doing (I assume, I've never tried this before today) is opening some sort of web interface to this service, where I can edit it.
I've tried using both Chrome and IE, and neither of them can connect. I've tried lots of different IP addresses (localhost, 192.168.1.8, etc.) and they all give back the generic "This webpage is not available".
I'm using Visual Studio 2015 Preview (that MIGHT be the problem, but it shouldn't be...) run as administrator (I've tried running the .exe directly as well) on Windows 8.1, coding in C#. I'm not too experienced in networking things, so I might be missing something obvious... any ideas?
I found the problem. In the main library (the one with the contract and implementation), in App.config, I forgot to change the address that it binds to. Setting this to the desired one (http://localhost:8000/GettingStarted/CalculatorService) seems to work.
HTTP 400 is significant. It means bad request - eg your service isn't receiving input in a way it expected, but it is there. Please update your question. That sounds like a mistake in your WCF config. Try this... Open up a command prompt and run C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat (Path for 2013, update as req'd). Then enter the command wcftestclient. It'll open up a gui that you can connect to the same url you're browsing to. It will attempt to talk to any WCF service listening there.

visual studio development server automatically redirects to default port with machine ip

This is a weird issue I have been facing for a couple of days now. When I run my ASP.Net web app from visual studio 2010, it starts the dev server and opens IE. I can see the correct URL getting formed (ex: http://localhost:53990/index.aspx).
But then it redirects to "http://my-machine-ip". I can see the dev server process (webdev) in task manager. If I browse the above URL in a separate IE instance, manually, I still get the same behavior.
This problem comes in chrome as well, but works properly in Firefox.
Since it was working in FF, I ignored it, but now an increasing number of my colleagues have started facing the exact same issue. Tried searching for a solution on Google and stackoverflow, but couldn't find any.
Has anyone else faced a similar issue? Would be great if I can get any help/pointers with this issue. Please let me know if you need more details.
PS: I am coding in c#, not sure if it matters but thought I should specify it.
I have faced this issue and resolved by following steps:->
Open IE
Go to Internet Option ->Connections
Click on Lan Settings
Uncheck Automatic detect settings check box.
Clear all browser cache/history
Try and browse the site now. You should be able to view your site
Since Chrome uses IE settings, this solution should work for Chrome too.

Can Selenium Detect Which Port your .net Application is deployed to

I recently started using Selenium for a .net project I'm working on.
It seems to work well however obviously you have to supply a URL like http://localhost:55555 or whatever address you are testing your application on.
My problem is that different people's computers in my team visual studio deploys to different port numbers on localhost so every time to get the tests to pass they have to find out what port there computer is deploying to locally and change it in the tests.
Does anyone know of a way I can detect the port number automatically so it doesn't need changed for each persons computer?
Thanks
I don't think you can do this with Selenium, because the port number is set randomly by VS during launch. However, the common solution to your problem is to have everyone use the same test port. This post shows how to do it.

Categories

Resources