简体   繁体   English

计划Selenium Webdriver(C#)测试

[英]Scheduling Selenium Webdriver (C#) tests

In my test project I would like to schedule unattended run of Regression tests a couple of times a week using Selenium Webdriver with C#. 在我的测试项目中,我希望使用C#的Selenium Webdriver安排每周几次无人值守的回归测试运行。 I know this could be achieved with Jenkins or similar tools, but wondering is there any way to do it without a CI/CD tool. 我知道可以使用Jenkins或类似工具来实现,但是想知道如果没有CI / CD工具,有没有办法做到这一点。 I could not get any conclusive info on whether this could be achieved just by some inbuilt/native capability within selenium or the tool stack I am using (as noted below) -- 我无法获得任何确定性的信息来确定是否可以通过硒或我正在使用的工具堆栈中的某些内置/本机功能来实现(如下所述)-

  • Selenium Webdriver on C# C#上的Selenium Webdriver
  • Visual Studio 2015 Professional Visual Studio 2015专业版
  • NUnit test framework NUnit测试框架

There isn't any built-in support for scheduling a run in your tool stack, but it would be quite simple to roll your own basic scheduled run. 在您的工具堆栈中没有任何内置的计划运行支持,但是滚动您自己的基本计划运行非常简单。

The ingredients would be 成分将是

  1. the command line to execute your tests 用于执行测试的命令行
  2. a scheduled task 预定任务

More specifically: 进一步来说:

Create an nunit command to run your tests - this may need to be crafted based on specifics for your project, but a very basic one would be 创建一个nunit命令来运行您的测试-这可能需要根据项目的具体情况来设计,但是最基本的命令是

nunit3-console testsfile.dll

More details here: https://github.com/nunit/docs/wiki/Console-Command-Line 此处有更多详细信息: https : //github.com/nunit/docs/wiki/Console-Command-Line

Next, create the scheduled task 接下来,创建计划任务

  1. open Task Scheduler 打开任务计划程序
  2. Under Actions, click Create a Basic Task 在“操作”下,单击“创建基本任务”
  3. Provide a descriptive name 提供描述性名称
  4. Choose a timeframe (if you want multiple times a week, choose daily here) 选择一个时间范围(如果您想每周多次,请在此处每天选择)
  5. Choose the starting date and time, and how often to recur 选择开始日期和时间,以及多久重复一次
  6. Choose Start a Program as the type of action 选择“启动程序”作为操作类型
  7. The program to run is nunit3-console.exe, the arguments would be testsfile.dll or whatever arguments you need. 要运行的程序是nunit3-console.exe,参数将是testsfile.dll或所需的任何参数。 Start In is where the dll lives dll所在的位置是Start In
  8. Click Finish. 单击完成。

Now it will run on the schedule you provided, or you can launch it whenever you want by viewing it in the Task Scheduler Library and selecting Run 现在它将按您提供的计划运行,或者您可以随时在任务计划程序库中查看它并选择运行来启动它。

If you really want to write your own scheduler, you could create a Windows Service; 如果您确实想编写自己的调度程序,则可以创建Windows服务。 which Visual Studio comes with a template for. Visual Studio附带了模板。 From there, you can use a Timer or background Thread to initiate or perform your automated tests. 从那里,您可以使用计时器或后台线程来启动或执行自动测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM