硒网格与黄瓜 [英] selenium grid with cucumber

查看:186
本文介绍了硒网格与黄瓜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图设置selenium网格来实现我的测试的并行执行。

I am trying to setup selenium grid to achieve parallel execution of my tests. First, I'll explain the my current scenario.


  1. 我使用watir webdriver在黄瓜中编写了全功能的测试套件

  2. 我需要在多个环境中执行我的所有测试。

  3. 我为selenium hub和节点创建了一个设置

  4. 可以通过集线器在单个节点上运行我的测试

  1. I have my fully functional test suite written in cucumber with watir webdriver
  2. I need to execute all my tests in multiple environments.
  3. I created a setup for selenium hub and node
  4. I can run my tests on a single node through hub

我的目标是同时在多个vm上运行我的测试。
我缺少一个部分,我需要配置我的测试并行运行。有一些网格设置的例子,因为我使用不同的框架,我不能涉及我的情况。

My goal is to run my tests on multiple vm's simultaneously. I missing a part where I need to configure my tests to run in parallel. there are some examples about grid setup in the web, as I am using different framework I couldn't relate to my scenario.

提前感谢

推荐答案

我能够通过利用Jenkins与Selenium Grid ...为什么选择Jenkins? a)Jenkins是一个构建工具,构建为默认运行并行作业。我利用这种能力来并行地向Selenium Grid发送测试,网格管理从那一点开始的流程。 b)Jenkins是许多开发构建过程的一部分。 Dev的可以调用你的QA jenkins启动测试,因为他们提交/构建。 c)Jenkins提供了一个很好的UI来查看测试的通过/失败(以及发送失败的电子邮件通知)和d)Jenkins有一个伟大的Cucumber报告插件。

I was able to do this by leveraging Jenkins with Selenium Grid... Why Jenkins? a) Jenkins is a build tool and is built to run parallel jobs by default. I leverage that ability to send tests to Selenium Grid in parallel, the Grid manages the flow from that point on. b) Jenkins is part of many development build processes. Dev's could make calls to your QA jenkins to kick off tests as they commit/build. c) Jenkins provides a nice UI to see pass/failures of your tests (as well as sending email notifications of failures) and d) Jenkins has a great Cucumber reporting plugin.

您可以避免Jenkins,但您需要将黄瓜功能并行发送到网格。如果你只是运行黄瓜,它会把工作发送到网格,但是它们会顺序运行。您需要一些东西来启动每个功能的异步。

You could avoid Jenkins, but you'll need to send your cucumber features in parallel to the Grid. If you just run cucumber, it will farm jobs to the grid, but they will run sequentially. You would need something to kick off each feature async.

下面是我的全部设置。 Jenkins基本上是用来开始多个/同时的黄瓜工作。详情如下:

Below is my full set up. Jenkins is basically being used here to start multiple/simultaneous cucumber jobs. the details are below:

我有10个虚拟机。我以VM1为主。它是一个Windows服务器框,所以我把硒网格独立的它上面写了一个批处理文件像这样:

I had 10 VM's. I took VM1 as my primary. It was a windows server box, so I put the selenium grid standalone on it and wrote a batch file like so:

@echo off
"C:\[Add your Java Path Here]\java.exe" -jar "C:\[Add your Selenium Grid Jar Path]\selenium-server-standalone-2.31.0.jar" -role hub

然后使用Windows服务器任务自动运行批处理文件重新启动。

Then used the windows server task to auto run that batch file in case of VM restart.

在每个其他虚拟机上,我通过向VM1(集线器)注册它们使它们成为网格的一部分:

On each of the other VM's I made them part of the grid by registering them with VM1 (hub):

java -jar selenium-server-standalone-2.31.0.jar -role node -hub http://[the server name of your Selenium Hub]:4444/grid/register -browser browserName=chrome,maxInstances=5



Cucumber设置UP



在Cucumber中,我在features / support文件夹中设置了一个env.rb文件。这允许我在测试运行之前指定命令行参数,并且停止时会发生什么。我添加了一个begin语句,设置了使用浏览器的值,以及使用Grid ...

Cucumber Set UP

In Cucumber, I set up a env.rb file in the features/support folder. This allows me to specify command line arguments before the tests run, and what happens when they stop. I added a begin statement that set the a value for using a browser, as well as using the Grid...

在env.rb文件中添加:

In the env.rb file I add:

def browser_name
  (ENV['BROWSER'] ||= ‘firefox’).downcase.to_sym
end

def environment
  (ENV['ENVI'] ||= ‘int’).downcase.to_sym
end



Grid Config



然后我添加:

Grid Config

Then I add:

Before do  |scenario|
  p "Starting #{scenario}"
  if environment == :int
    @browser = Watir::Browser.new(:remote, :url=>"http://[Your Selenium Grid Hub]:4444/wd/hub", :desired_capabilities=> browser_name)
   #Optional: in the case of setting your default start page @browser.goto "http://[your start page of your test site]:8080"
  elsif environment == :local
    @browser = Watir::Browser.new browser_name
    @browser.goto "http://[some other environment]:8080"
  end
end

现在你可以传递一个参数: cucumber feature / login.feature BROWSER = firefox ENV = int ,它会将所有的工作放到Grid HUB - 它应该将它传递给它连接的Grid NODES,与浏览器支持(即发送测试对于login.feature到firefox兼容的节点 - 也许不是所有的节点都有firefox,如果他们都有,那么它会去任何一个。)

Now you could pass a argument like: cucumber feature/login.feature BROWSER=firefox ENV=int and it would farm all the work to the Grid HUB - which should pass it to the Grid NODES it's connected to, with the browser support (i.e send the test for login.feature to a firefox compatible node - maybe not all your nodes have firefox, if they all do, then it will go to any one of them.)

这一点,你每次得到一个工作。那么如何运行多于一个?

At this point, you get one job at a time going through. So how to run more then one?

您将有一个脚本通过相同的浏览器配置文件启动所有功能文件(或sans-Cucumber,您的测试)以使用Grid HUB。如果您使用脚本,它需要异步地进行这些调用 - 所有的功能/测试同时发送到网格,网格管理作业。

You would have a script that kicks off all feature files (or sans-Cucumber, your tests) through that same browser profile to use the Grid HUB. If you use a script it needs to make these calls asynchronously - so all the features/tests are sent to the Grid at the same time and the Grid manages the jobs.

我是如何做到的...

How I did that was with...

Jenkins用于构建/部署代码 - 但在我的例子中,我使用它来触发QA作业。 Jenkins是一个Java JAR,你只是运行... ie java jenkins.jar它在一些端口上启动一个本地UI,你可以开始添加作业。

Jenkins is used for builds/deploys of code - but in my case I use it to trigger QA jobs. Jenkins is a Java JAR, that you just run... i.e. java jenkins.jar It launches a local UI on some port, and you can start adding jobs.

我创建了Jenkins作业,并且有一个父作业运行所有作业 - 将它们发送到网格。 Selenium Grid Hub将管理作业的流程。

I built Jenkins jobs and had a parent job that ran all jobs - sending them to the Grid. The Selenium Grid Hub would then manage the flow of the jobs.

我想要能够启动单独的功能测试,浏览器的个别功能测试,以及所有测试浏览器。

I wanted to be able to kick off individual feature tests, individual feature tests by browser, and all tests by browser. To do that I started with individual jobs for each feature by browser.

在Jenkins中,我创建了 新工作,然后选择自由样式软件组件,然后使用[我的功能名称] [浏览器名称]填写说明,即登录测试通过IE

In Jenkins I created "A New Job" and choose "Free style software component" and then filled out the description with "[my feature name] [browser name]" i.e. Login Tests via IE

在这个Jenkins作业的构建部分,我选择使用BATCH命令。因为它是一个窗口框,我选择Windows批处理命令,并输入如下:

Down in the Build section of this Jenkins job, I choose to use a BATCH Command. Since it's a windows box, I picked Windows Batch command and input something like this:

bundle exec cucumber BROWSER=ie ENVI=int features/login.feature --format json -o login-results/login.json

--format,这是所有使用的Jenkins的Cucumber报告插件。它使得这些看起来好看的图形驱动报告的功能测试通过/失败。你不需要它,它是可选的。

That stuff from --format on, that's all making use of a Cucumber reports plugin for Jenkins. It makes these nice looking graph driven reports on the features tests that passed/failed. You don't need it, it's optional.

如果构建Jenkins作业,它将执行该Windows批处理文件,并执行以下操作:

If you "build" the Jenkins job, it will execute that windows batch file and it does the following:


  • 启动作业

  • 运行cucumber命令以使用特定浏览器(本例中为IE)

  • 该功能文件的所有测试(即login.feature可以有20个测试)

  • 所有测试都通过网格运行,将其关闭到节点

  • Starts the Job
  • Runs a cucumber command to use a specific browser (IE in this case)
  • Runs all the tests of that feature file (i.e. login.feature could have 20 tests)
  • All tests run through the grid, which farms them off to nodes

它还没有并行运行作业。

It's not yet running jobs in parallel though.

现在Jenkins可以通过功能和浏览器启动测试 - 我们现在终于可以并行地工作,我们只需要更多的工作。所以创建一些更多的工作... like:
Jenkins job for registration.feature,和jenkins job for subscription.feature。每个都有它自己的Windows批处理命令像:

Now that Jenkins can kick off the tests by feature and browser, via a Grid - we can now finally run jobs in parallel, we just need more jobs. So create a few more jobs... like: Jenkins job for registration.feature, and jenkins job for subscription.feature. Each will have it's own windows batch command like:

bundle exec cucumber BROWSER=ie ENVI=int features/registration.feature --format json -o registration/registration.json

bundle exec cucumber BROWSER=ff ENVI=int features/registration.feature --format json -o registration/registrationff.json

最后一个是注册测试的重复,只是调用不同的浏览器。

Jenkins默认限制同时作业多少可以运行..我认为它是10.你可以改变在Jenkins配置。

That last one is a duplicate of the registration test, just calling a different browser.
Jenkins by default limits how many simultaneous jobs you can run.. I think it's 10. You can change that in the Jenkins config. I changed mine to 40.

现在,您可以点击您的第一个Jenkins工作:
通过IE登录测试
并点击 BUILD

So now, you can click on your first Jenkins job: Login Test via IE and click BUILD

开始时,请在第二个工作上点击BUILD:
注册测试IE

As it starts, click "BUILD" on your second job: Registration Test via IE

,并且对于其他工作也是如此...

and the same for your other jobs...

Jenkins将开始每个工作并行,养殖他们到网格HUB,发送工作到您的适当的节点!所有并行。 默认情况下,Jenkins将作业限制为5或10个并行作业。你可以改变。

Jenkins will start each job in parallel, farming them to the Grid HUB, which sends the jobs to your appropriate nodes! All in parallel. By default Jenkins limits the jobs to 5 or 10 parallel jobs. You can change that. I modified mine to be 25 to 40, depending on my needs.

Jenkins还会使用pass / fail来更新UI,并且具有失败的详细信息每个作业的日志。你可以看到故障的历史...和另一个Jenkins repo(即dev repo)可以打电话给你的repo自动触发这些测试,因为他们建立。

Jenkins will also update the UI with pass/fail and has details of the failures in the logs of each job. You can see the history of the failures... and another Jenkins repo (i.e. the dev repo) can make rest calls to your repo to auto trigger these test as they build.

而不是手动运行单个作业,您可以构建父作业。在Jenkins中,父作业将是类型相同的作业,自由风格的软件组件。你下到底部,它应该有一个字段

Rather then manually running your individual jobs, you can build a parent job. In Jenkins the parent job would be a NEW Job that is the same type, "Free style software component." You go down to the very bottom and it should have a field called, "Build Other Projects" In that field you can put each project for deploying: Login, Registration, etc.

现在,当您选择自定义时,构建这个父工作,你会看到Jenkins启动所有工作/项目同时启动。基本上,您的整个测试集可以开始一次点击 - 所有被发送到Selenium Grid,然后它将管理流。

Now when you "Build" this parent job, you'll see Jenkins starts all jobs/Projects to kick off at the same time. Basically your entire set of tests could start with one click - all being sent to Selenium Grid, which would then manage the flow.

在Jenkins中,我为我的测试创建选项卡... IE测试,FF测试,Chrome测试等。
在每个选项卡中,我放置适当的功能。

In Jenkins I create tabs for my tests... IE Tests, FF Tests, Chrome Tests, etc. In each tab I put the appropriate features.

然后我创建一个新的父作业以启动类型的所有作业:
所有IE测试
所有FF测试

Then I create a new Parent job to kick off all jobs of a type like: All IE Tests All FF Tests etc.

如果你喜欢,你可以避免使用Cucumber。你只需要一些东西来平行启动工作,对我来说,我使用Jenkins这样做。您可以使用运行异步作业的脚本(启动测试。)

You can probably avoid Cucumber if you like. You just need something to kick off the jobs in parallel, for me I used Jenkins to do that. You could use a script that runs async jobs (kicking off your tests.)

希望发布的内容对您的需求非常有用。

Hopefully something in post is useful to your needs.

我在我的网站上有这个记录,以及Jenkins流程的一些照片...

I have this documented at my site, along with some pictures of the Jenkins flow...

我的设置Cucumber和Selenium网格的教程:
http://sdet.us/selenium-grid-with-watir-and-cucumber-browser-automation/

My tutorial on setting up Cucumber and Selenium Grid: http://sdet.us/selenium-grid-with-watir-and-cucumber-browser-automation/

我的有关使用Jenkins设置Cucumber报告的教程:
http://sdet.us/jenkins -and-cucumber-reports /

My tutorial on setting up Cucumber Reports with Jenkins: http://sdet.us/jenkins-and-cucumber-reports/

这篇关于硒网格与黄瓜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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