如何使用Selenium Grid在节点上运行某些命令以及在本地运行系统命令 [英] How to use Selenium Grid to run some commands on the node and system commands locally

查看:294
本文介绍了如何使用Selenium Grid在节点上运行某些命令以及在本地运行系统命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解决一个问题,我希望我可以使用Selenium Grid做到这一点,但我不确定是否有可能.这是我的问题...我正在使用Selenium WebDriver开发测试用例,我需要在Windows计算机上运行测试,而AUT在Linux服务器上运行.我有几种只能在Linux上运行的工具,我希望能够在Windows机器上运行某些命令/测试,并在Linux服务器上运行其他命令/测试.例如

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. 测试开始-> Firefox启动(Windows计算机)
  2. 登录到站点(Windows计算机)
  3. 在Linux服务器中运行命令
  4. 在Windows框中返回正在运行的命令/测试.

或者,我可以弄清楚如何从Windows计算机上远程运行这些命令,但是我不希望这样做.

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

推荐答案

开箱即用,您不能使用硒在本地计算机上运行命令. Selenium/Webdriver是浏览器测试工具,只能与浏览器进行交互.

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.

根据您的评论更新答案
两种方式的共同点(我想您已经知道) 在您的Java代码中,您应该具有将执行步骤1和2的webdriver/selenium命令的代码.您的Java代码中还应包含执行步骤3的linux命令的逻辑/代码.步骤4应该再次是您的webdriver命令.
该测试代码应从linux服务器运行,以便在Linux框中执行Java命令.

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.

在Windows计算机中启动硒服务器.将Java测试指向此计算机上运行的硒服务器.如果Windows计算机IP为10.0.0.1,则应将webdriver对象初始化为

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());

这会将您所有的webdriver命令发送到在端口4444上运行10.0.0.1的硒服务器.然后,您的测试将在Windows计算机中执行.为此,您的linux服务器和Windows计算机应位于同一网络中.

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.

与上面的所有操作相同,但是除了提供Windows计算机的ip/dns名称外,还应提供集线器计算机的ip/dns名称.您还应该将Windows计算机注册为该中心的RC.

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.

这篇关于如何使用Selenium Grid在节点上运行某些命令以及在本地运行系统命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆