Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
667 views
in Technique[技术] by (71.8m points)

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

I am working with Selenium 2 WebDriver. Instead of UnitTest project, i initiate it from website because of following reasons:

  1. It should automatically run every 24 hours. I have written some scheduling code using System.Threading.
  2. Provide some UI to customer to run it intermediately when they require.
  3. 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:

  1. It runs the Selenium code to an extend, but doesn't show the broswer.
  2. 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have managed to find the solution myself.

Basically, RemoteWebDriver has to be used instead of FirefoxDriver. Steps:

  1. 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:

  1. One could use the local IIS for running the test.
  2. 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:

  1. IP address REMOTE_IP could be changed to any realtime IP address OR localhost. Use the above mentioned port while initiating the page request.
  2. Start/Stop code of Standalone Server could be fitted inside the test, so that it is automatically started/stopped via batch file.
  3. Keep the server running by not closing the command prompt.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...