每 15 分钟将 Selenium 脚本自动化为 运行?
Automate Selenium scripts to run every 15 mins?
我已经使用 Selenium Webdriver 编写了一个脚本。只是想知道是否有办法让这个脚本 运行 每 15 分钟?
就像我安排 1 小时一样,脚本应该 运行 每 15 分钟,在 1 小时结束时它应该 post 结果为 excel sheet.有人可以帮我解决这个问题吗?
Crontab 是完成这项工作的最佳选择。使用 crontab 每 15 分钟编写一个 selenium 脚本和 运行。每 15 分钟参考此 link 至 运行。
How would I get a cron job to run every 30 minutes?
Jenkins 或 Hudson 将是主持此活动的理想人选。
由于您是初学者,所以我尝试为您提供一个非常简单的解决方案,但效率可能不是很高。
static Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
// Your database code here
if(i==4){
timer.cancel();
timer.purge();
}
try {
execute();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
i++;
}
}, 0, 1*1000);
在代码中,1*1000 表示你想要在多少秒后执行你的代码。
execute() -- 将使您的代码成为 运行
i :- 次数,你想重复你的测试
在你的情况下
我=4
timeRate 应该是:- 15*60*1000
我已经使用 Selenium Webdriver 编写了一个脚本。只是想知道是否有办法让这个脚本 运行 每 15 分钟?
就像我安排 1 小时一样,脚本应该 运行 每 15 分钟,在 1 小时结束时它应该 post 结果为 excel sheet.有人可以帮我解决这个问题吗?
Crontab 是完成这项工作的最佳选择。使用 crontab 每 15 分钟编写一个 selenium 脚本和 运行。每 15 分钟参考此 link 至 运行。
How would I get a cron job to run every 30 minutes?
Jenkins 或 Hudson 将是主持此活动的理想人选。
由于您是初学者,所以我尝试为您提供一个非常简单的解决方案,但效率可能不是很高。
static Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
// Your database code here
if(i==4){
timer.cancel();
timer.purge();
}
try {
execute();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
i++;
}
}, 0, 1*1000);
在代码中,1*1000 表示你想要在多少秒后执行你的代码。 execute() -- 将使您的代码成为 运行 i :- 次数,你想重复你的测试 在你的情况下 我=4 timeRate 应该是:- 15*60*1000