我在Java中使用selenium脚本,我需要每隔一小时自动运行它而不进行干预。如何做?

时间:2022-01-28 04:18:05

I want to run my Java selenium script every one hour.I want to do it without Human intervention.How to do it?

我想每隔一小时运行一次我的Java selenium脚本。我想在没有人工干预的情况下完成它。怎么做?

Can i do it by keeping my piece of code in cloud or any online IDE which runs it every one hour? Please help in this case.

我可以通过将我的代码保存在云端或每隔一小时运行它的任何在线IDE中来实现吗?在这种情况下请帮忙。

I have seen some people suggesting Windows Task scheduler,but the file should run even my computer is shutdown.

我见过有人建议Windows任务调度程序,但该文件应该运行,即使我的电脑关机。

4 个解决方案

#1


1  

Windows scheduled task. https://msdn.microsoft.com/en-us/library/windows/desktop/aa383614(v=vs.85).aspx

Windows预定任务。 https://msdn.microsoft.com/en-us/library/windows/desktop/aa383614(v=vs.85).aspx

Cron job https://www.digitalocean.com/community/tutorials/how-to-schedule-routine-tasks-with-cron-and-anacron-on-a-vps

Cron职位https://www.digitalocean.com/community/tutorials/how-to-schedule-routine-tasks-with-cron-and-anacron-on-a-vps

I would use something like Jenkins, or AWS to run your job (on a schedule).

我会使用Jenkins或AWS之类的东西来按计划运行你的工作。

#2


0  

  1. You can create tests packed as an executable the easiest way may be to run a CRON job or a Windows scheduled task.
  2. 您可以创建作为可执行文件打包的测试,这是运行CRON作业或Windows计划任务的最简单方法。

Or

  1. If you have Hudson (or another continuous integration system like jenkin ) can be use for it and is almost certainly better long term strategies.
  2. 如果你有Hudson(或像jenkin这样的其他持续集成系统)可以使用它,几乎肯定是更好的长期策略。

#3


0  

However this question is quite broad, I can give you a general approach with a suggestion. That you need is to persist the application where is the script, method or whatsoever included and call it every 60 minutes.

不过这个问题相当广泛,我可以给你一个建议的一般方法。您需要的是将应用程序持久保存在脚本,方法或其中包含的内容中,并且每隔60分钟调用一次。

In general, I'd suggest you create a web service and deploy it on Azure's Tomcat servlet container. You need a web page available online, where you can periodically call with AJAX the Selenium method mapped to the exact URL.

一般来说,我建议您创建一个Web服务并将其部署在Azure的Tomcat servlet容器上。您需要一个在线可用的网页,您可以定期使用AJAX调用映射到确切URL的Selenium方法。

The disadvantage may be the complexity of the client-side and server-side concept if you have the lack of experience. However, you can monitor the activity and the results for your own and scale the web service.

如果您缺乏经验,缺点可能是客户端和服务器端概念的复杂性。但是,您可以监视自己的活动和结果,并扩展Web服务。

#4


0  

You can use any only CI environments for this task. For example free and easy to configure is travis-ci it has integration with github and lot of documentation for how to run it.

您可以将任何CI环境用于此任务。例如,免费且易于配置的是travis-ci它与github的集成以及如何运行它的大量文档。

#1


1  

Windows scheduled task. https://msdn.microsoft.com/en-us/library/windows/desktop/aa383614(v=vs.85).aspx

Windows预定任务。 https://msdn.microsoft.com/en-us/library/windows/desktop/aa383614(v=vs.85).aspx

Cron job https://www.digitalocean.com/community/tutorials/how-to-schedule-routine-tasks-with-cron-and-anacron-on-a-vps

Cron职位https://www.digitalocean.com/community/tutorials/how-to-schedule-routine-tasks-with-cron-and-anacron-on-a-vps

I would use something like Jenkins, or AWS to run your job (on a schedule).

我会使用Jenkins或AWS之类的东西来按计划运行你的工作。

#2


0  

  1. You can create tests packed as an executable the easiest way may be to run a CRON job or a Windows scheduled task.
  2. 您可以创建作为可执行文件打包的测试,这是运行CRON作业或Windows计划任务的最简单方法。

Or

  1. If you have Hudson (or another continuous integration system like jenkin ) can be use for it and is almost certainly better long term strategies.
  2. 如果你有Hudson(或像jenkin这样的其他持续集成系统)可以使用它,几乎肯定是更好的长期策略。

#3


0  

However this question is quite broad, I can give you a general approach with a suggestion. That you need is to persist the application where is the script, method or whatsoever included and call it every 60 minutes.

不过这个问题相当广泛,我可以给你一个建议的一般方法。您需要的是将应用程序持久保存在脚本,方法或其中包含的内容中,并且每隔60分钟调用一次。

In general, I'd suggest you create a web service and deploy it on Azure's Tomcat servlet container. You need a web page available online, where you can periodically call with AJAX the Selenium method mapped to the exact URL.

一般来说,我建议您创建一个Web服务并将其部署在Azure的Tomcat servlet容器上。您需要一个在线可用的网页,您可以定期使用AJAX调用映射到确切URL的Selenium方法。

The disadvantage may be the complexity of the client-side and server-side concept if you have the lack of experience. However, you can monitor the activity and the results for your own and scale the web service.

如果您缺乏经验,缺点可能是客户端和服务器端概念的复杂性。但是,您可以监视自己的活动和结果,并扩展Web服务。

#4


0  

You can use any only CI environments for this task. For example free and easy to configure is travis-ci it has integration with github and lot of documentation for how to run it.

您可以将任何CI环境用于此任务。例如,免费且易于配置的是travis-ci它与github的集成以及如何运行它的大量文档。