Java 如何创建调度程序以每晚 12.00 运行我的脚本-Selenium WebDriver

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21744795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 10:27:07  来源:igfitidea点击:

How to create scheduler to run my script every night at 12.00- Selenium WebDriver

javatestng

提问by testing

  • Currently working on Selenium WebDriverand using Java. I have a project called*Test*.
  • In that Project i have many Java Programs such as Login.java, Testing1.javaetc.,.
  • The scenario is i want to run all my scripts daily morning at 12.00 a.m. Is there any possibility to create a scheduler to run my scripts automatically.
  • 目前正在研究Selenium WebDriver并使用Java。我有一个名为* Test*的项目。
  • 在该项目中,我有许多 Java 程序,例如Login.javaTesting1.java等。
  • 场景是我想每天早上 12 点运行我的所有脚本 是否有可能创建一个调度程序来自动运行我的脚本。

采纳答案by Sumitbit2005

Create an testng.xmlfile say name as testsuite.xml.

创建一个testng.xml文件,名称为testsuite.xml

Now follow below 2 steps:

现在按照以下 2 个步骤操作:

Step 1: Create an batch file for scheduler:

步骤 1:为调度程序创建批处理文件:

use below code - modify it and paste in notepad. save the notepad in working directory as"run.bat"

使用下面的代码 - 修改它并粘贴到记事本中。将记事本保存在工作目录中为“ run.bat

set ProjectPath=C:\Selenium\Selenium_tests\DemoProject 
echo %ProjectPath%
set classpath=%ProjectPath%\bin;%ProjectPath%\Lib\*
echo %classpath%
java org.testng.TestNG %ProjectPath%\testsuite.xml
  • a) First line is for setting project path .

  • b) second line is for verifying that path is set or not.

  • c) third line is for setting classpath - lib folder contain all the jar file added to project build path

  • d) fourth line is for verifying whether classpath is set or not

  • e) fifth line is for executing xml file having details of all test.

  • a) 第一行用于设置项目路径。

  • b) 第二行用于验证路径是否设置。

  • c) 第三行用于设置类路径 - lib 文件夹包含添加到项目构建路径的所有 jar 文件

  • d) 第四行用于验证是否设置了类路径

  • e) 第五行用于执行包含所有测试详细信息的 xml 文件。

Step 2:

第 2 步

  • Go to control panel.

  • Administrative tool.

  • Task scheduler and create a task which will trigger run.bat file at the time you want.

  • 进入控制面板。

  • 管理工具。

  • 任务调度程序并创建一个任务,该任务将在您想要的时间触发 run.bat 文件。

It will work.

它会起作用。

回答by user2775185

check with quartz scheduler.. http://quartz-scheduler.org/

检查石英调度程序.. http://quartz-scheduler.org/

回答by Christoph Zabinski

I am currently working on a similar project where I have to check different web applications for their availability every ~5 minutes and report any errors via mail. I am also using TestNG ans the WebDriver together. I solved my "scheduling problem" by using the TimerTask class.

我目前正在从事一个类似的项目,我必须每大约 5 分钟检查一次不同的 Web 应用程序的可用性,并通过邮件报告任何错误。我也一起使用 TestNG 和 WebDriver。我通过使用 TimerTask 类解决了我的“调度问题”。

Here's a short code example: (Find more code examples here)

这是一个简短的代码示例:(在此处查找更多代码示例)

import java.util.Timer;
import java.util.TimerTask;

public class KeepMeAwake {

 *
 * @param args
 */
public static void main(String[] args) {

    TimerTask action = new TimerTask() {
        public void run() {
            Beep b = Beep.getInstance();
            b.beep();
        }
    };

    Timer caretaker = new Timer();
    caretaker.schedule(action, 1000, 5000);
    }
}

Since it implements Runnable, you can run multiple threads with it.

由于它实现了 Runnable,您可以使用它运行多个线程。

Hope that helps. If you have questions how to integrate it with your TestNG set up, just shoot.

希望有帮助。如果您对如何将其与您的 TestNG 设置集成有疑问,请直接拍摄。

回答by Tarit Ray

Follow the above steps and in windows scheduler do the steps :

按照上述步骤并在 Windows 调度程序中执行以下步骤:

Creating .bat file steps

创建 .bat 文件步骤

Task Scheduler in Windows> Create new Task>

Windows 中的任务计划程序>创建新任务>

'Action' settings - "Start in (Optional)" option.

'动作'设置-“开始于(可选)”选项。

Go the task properties --> Action tab --> Edit --> Fill up as below:

转到任务属性--> 操作选项卡--> 编辑--> 填写如下:

  1. Action: Start a program
  2. Program/script: path to your batch script e.g. C:\Users\beruk\bodo.bat
  3. Add arguments (optional): <if necessary - depending on your script>
  4. Start in (optional): Put the full path to your batch script location e.g. C:\Users\beruk\(Do not put quotes around Start In)
  1. 行动:启动一个程序
  2. 程序/脚本:批处理脚本的路径,例如C:\Users\beruk\bodo.bat
  3. 添加参数(可选):<如有必要 - 取决于您的脚本>
  4. 开始(可选):将完整路径放在您的批处理脚本位置,例如C:\Users\beruk\(不要在开始周围加上引号)

Then Click OK

然后点击确定

It works for me. Good Luck!

这个对我有用。祝你好运!