Can we run Selenium WebDriver Test case with IIS, instead of Visual Studio Development server - asp.net

I am working with Selenium 2 WebDriver. Instead of UnitTest project, i initiate it from website because of following reasons:
It should automatically run every 24 hours. I have written some scheduling code using System.Threading.
Provide some UI to customer to run it intermediately when they require.
At every run an email would be sent as a part of test result.
My target site is: http://www.vroomvroomvroom.com.au
I have created a Class which has all the Selenium Code. I call that Class using System.Threading upon page load of default.aspx.
It works fine when i run default.aspx from visual studio by pressing F5 OR Ctrl+F5 i.e. with Visual Studio development server e.g. http://localhost:3251/default.aspx.
But, when i try to run it directly from IIS, with default port (80) e.g. http://localhost/seleniumTest/default.aspx, then it fails with following observation/error:
It runs the Selenium code to an extend, but doesn't show the broswer.
It fails after some steps with No response from server for url http://localhost:7094/hub/session/4bbe4b0c-aeee-4fa3-8bc0-aae47c6869af/element
It is possible what i am trying to achieve.
FYI: Let me know if further details are required.

I have managed to find the solution myself.
Basically, RemoteWebDriver has to be used instead of FirefoxDriver.
Steps:
Change the initialization of FirefoxDriver to RemoteWebDriver as:
Change from
IWebDriver driver = new FirefoxDriver();
To
DesiredCapabilities capability = DesiredCapabilities.Firefox();
Uri url = new Uri("http://REMOTE_IP:4545/wd/hub");
IWebDriver driver = new RemoteWebDriver(url, capability);
2. Download Selenium Standalone server and initiate it via command prompt using ~
java -jar E:\Software\selenium-server-standalone-2.24.1.jar -interactive -port 4545
This approach has 2 benefits:
One could use the local IIS for running the test.
Test could be run remotely. Refer Selenium RC documentation. One could see the screenshots remotely using
REMOTE_IP:4545/wd/hub/static/resource/hub.html
I am thinking to modify the code of hub.html and client.js file used within it to provide a better Remote feel.
I hope this can be useful for others as well.
FYI:
IP address REMOTE_IP could be changed to any realtime IP address OR localhost. Use the above mentioned port while initiating the page request.
Start/Stop code of Standalone Server could be fitted inside the test, so that it is automatically started/stopped via batch file.
Keep the server running by not closing the command prompt.

Related

How to troubleshoot failed API calls to .NET project running over localhost?

I have an API in a .NET project that I'm running with Visual Studio Mac (8.4.3). I run it in release mode, and it opens a browser window with localhost:5000. The browser window says "ok". However, when I try to hit endpoints in that API, it fails very quickly. When I ran this API (ie. same code) from another server and accessed it via proxy, it ran fine. For example, when I ran it on a server whose IP was 162.250.198.98 and proxied into it, I would hit an endpoint like 162.250.198.98:3000/api/user and it would work, but now when I try to run localhost:5000/api/user, either from my app or from Postman, it fails almost instantaneously. When running it in Postman, I tried what it suggested by turning off 'SSL certificate verification' in Settings, but no change.
Can anyone advise me on how to approach troubleshooting this?
Wait, so You are saying that while trying to call API on 162.250.198.98:3000/api/user You are fine but while trying to do the same thing on localhost:5000/api/user You are getting an error? Would it might be possible You have Your API configured to receive calls at 3000? :)?
No, but really - please chech it out, maybe it is that simple, I'm couting on it :).
You can change/check it in Visual Studio: main project > Properties > Debug > App URL.

"Selenium server standalone" jar vs "selenium java" jar

I am bit confused here..
"selenium-server-standalone" jar contains all the library files to run script then why do we need to use "selenium-java" jars?
I read somewhere that its used for Language Binding.. if it is true, then please help me to understand the meaning of Language binding as well.
Thanks.
In the previous version of Selenium, which is Selenium RC (Remote Control), it is mandatory that you need to run selenium-server-standalone.jar jar file, which acts like a server. Selenium RC will then use this server to establish a communication channel between browser and the code. Also, this jar file contains all the library functions to be used in our code.
But in later version of Selenium, which is Selenium WebDriver, there is no need to run this jar file, as the WebDriver api will directly communicate with the browser's native language. So, this jar file is replaced with selenium-java.jar jar files
Hope this helps.
It is mainly use in the Selenium Grid. As we use different OS and browsers with different machines, we need to run it same time for various reason. In selenium Grid, we use the machine Hub and Node(You can go through selenium grid docs for more), so for running the selenium in different machines with the main machine, we need server standalone.
WebDriver and the Selenium-Server
You may, or may not, need the Selenium Server, depending on how you intend to use Selenium-WebDriver. If your browser and tests will all run on the same machine, and your tests only use the WebDriver API, then you do not need to run the Selenium-Server; WebDriver will run the browser directly.
There are some reasons though to use the Selenium-Server with Selenium-WebDriver.
You are using Selenium-Grid to distribute your tests over multiple machines or virtual machines (VMs).
You want to connect to a remote machine that has a particular browser version that is not on your current machine.
You are not using the Java bindings (i.e. Python, C#, or Ruby) and would like to use HtmlUnit Driver
http://www.seleniumhq.org/docs/03_webdriver.jsp#how-does-webdriver-drive-the-browser-compared-to-selenium-rc

Running java based webdriver scripts in unix server

I have written webdriver+TestNG scripts in windows using java. Now there is an upcoming requirement to run the same scripts in UNIX server without much of code modification. I have heard about running tests in headless browser, but I dont know about this much. I searched a lot but there is no clear and simple response to start looking into this.
Is it possible to just change the driver instance to htmlunitdriver and run the same in unix environment? How could I create the tests as a package and move to unix environment for running the scripts?
You can run your existing script by making few changes in driver instance creation. Suppose you are using Firefox driver for your test, then you can run your script in headless mode using virtual display Xvfb (Xvfb is an X server that can run on machines with no display hardware and no physical input devices).
Below are the steps to run your tests in headless mode:
Install Xvfb
Start the Xvfb by executing this command Xvfb :99 -screen 0 1024x768x24 & Xvfb Manual
Then create a Firefox driver instance that uses virtual display started in step 2 as below:
FirefoxBinary fb = new FirefoxBinary();
fb.setEnvironmentProperty("DISPLAY", ":99");
WebDriver driver = new FirefoxDriver(fb,null);
Now your script will run in headless mode. You may need to change few other things like path of your test data or any other references that uses windows file system (like C:\)

How to get a second browser running on a Selenium2 Grid Hub

I managed to get a Selenium Grid Hub running in my code (using a Groovy/Gradle build system), and I loaded configuration from a .json config file and when I run my tests it only runs a single thread. I configured my Grid server to have a max of 2 sessions. How do I get my unit test (or the grid) to actually start a second browser? I looked everywhere on the Selenium site and on Google and everyone fails to mention how to do it, as if it is something that everyone already knows. Am I missing something here?
Here is where I have my config files for my Hub and Node :
https://github.com/djangofan/WebDriverTestingTemplate/tree/master/root
You are looking for DesiredCapabilities.
In java you would write something like this:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
RemoteWebDriver driver = new RemoteWebDriver(yourGridUrl, capabilities);
This would start the chrome browser on your grid.

Determining the port a Visual Studio Web App runs on

I've been using the macro from this blog entry for attaching the Visual Studio debugger to an already running instance of the Web Application I'm currently working on. However, if I have more than one instance of the Visual Studio web server running it's pot luck which one it'll attach to.
Is there a way to determine what port is configured in the Web project so I can modify the macro to filter its choice of process to that one?
Further Info
I'm aware that you can set the port number to a static one - I've done just that from the get-go, what I'm trying to determine is how to programatically determine the defined port-number so I can modify the macro (in the linked blog entry) and ensure it connects to the right instance of the Visual Studio web server.
The way I have things running is I have two (or more) instances of Visual Studio running, each of which contains a Solution, which contains a web project and one or more other projects - typically an Installer project), so when I trigger the macro from a given instance of Visual Studio, I want to find the Web Project within that instances loaded solution and determine the port it's running against.
This code will get you a list of all ports for the projects in the current solution:
Sub GetWebProjectPorts()
Dim ports As String
For Each prj As Project In DTE.Solution.Projects
For Each p As EnvDTE.Property In prj.Properties
If p.Name.Contains("DevelopmentServerPort") Then
If Not String.IsNullOrEmpty(ports) Then
ports += ","
End If
ports += p.Value.ToString()
End If
Next
Next
MsgBox(ports)
End Sub
If that can help you, I have found a link that might actually to the trick.
However, it require DllImport call and a lot of fun.
You can take a look at that article there: http://bytes.com/forum/thread574901.html
Quotes from the actual site:
By calling into iphlpapi.dll using
PInvoke interop. Google around for
GetExtendedTcpTable and iphlpapi.dll,
I'm sure you will find some existing
stuff.
Willy.
And one last:
Here are some API-Methods for my
purposes:
GetTcpTable()
AllocateAndGetTcpExTableFromStack()
GetExtendedTcpTable()
I wrote a small programm that is able
to show me all Processes with the
belonging TCP-Ports (with
AllocateAndGetTcpExTableFromStack())
running under Windows XP.
Now my problem is, that under Windows
2000 I can't use
AllocateAndGetTcpExTableFromStack() or
GetExtendedTcpTable() so I'm only able
to use GetTcpTable() to list all
TCP-Ports but without the belonging
processes.
Did somebody have the same problem or
is there another way (.Net or WMI
etc.) to solve my problem?
Thanks in advance,
Werner
If you go to the properties for your web project and look under the "Web" tab, you can specify which port the project will always start up on. Then you can click "Enable Edit and Continue" so you don't have to stop debugging and restart continuously.

Resources