How to use Selenium Grid to run some commands on the node and system commands locally

北城余情 提交于 2019-12-12 01:16:02

问题


I'm trying to solve a problem and I was hoping I could do it with Selenium Grid but I'm not entirely sure that it's possible. Here's my problem...I'm developing test cases using Selenium WebDriver and I need my tests to run on a Windows machine however the AUT runs on a Linux server. I have several tools that only run on Linux and I would like to be able to run some commands/tests on the Windows machine and others in the Linux server. For instance

  1. Test Starts -> Firefox launches (Windows machine)
  2. Login to site (Windows machine)
  3. Run command in Linux server
  4. Return running commands/tests on the Windows box.

Alternatively I could figure out how to run those commands remotely from a Windows machine but I'm not looking forward to doing that.


回答1:


Out of the box, you cannot use selenium to run commands on your local machine. Selenium/Webdriver is a browser testing tool and can interact only with browser.

Updated Answer based on your comments
Common part to both ways (which I think you already know) In your java code you should have the code for webdriver/selenium commands that will do step 1 and 2. Your java code should also the contain the logic/code to execute the linux commands as step 3. Step 4 should again be your webdriver command.
This test code should run from the linux server so that the java command execution will happen in the linux box.

Now the only pending part is the execution of test in remote machine.

Method 1 without using grid

Start the selenium server in the windows machine. Point your java tests to the selenium server running in this machine. If your windows machine IP is 10.0.0.1, you should initialize the webdriver object as

WebDriver wd =  new RemoteWebDriver(new URL("http://10.0.0.1:4444/wd/hub"),DesiredCapabilities.Firefox());

This will send all your webdriver commands to the selenium server running in 10.0.0.1 on port 4444. Your tests will then get executed in the windows machine. For this to work, your linux server and windows machine should be in same network.

Method 2 using grid.

Its all the same as above, but instead of giving the ip/dns name of windows machine, you should give the ip/dns name of the hub machine. You should also have windows machine registered as an RC to that hub.



来源:https://stackoverflow.com/questions/14331178/how-to-use-selenium-grid-to-run-some-commands-on-the-node-and-system-commands-lo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!