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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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:Softwareselenium-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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0