Selenium - Using Windows Task Scheduler vs. command line

陌路散爱 提交于 2020-01-02 05:29:09

问题


I have a batch file that kicks off my Selenium script (written in Java), which uses the IEDriverServer. When I run that batch file from the command line, the script works as expected. However, when I use the Windows Task Scheduler to run the exact same batch file, the script times out during a WebDriverWait until statement:

(new WebDriverWait(driver, JAVASCRIPT_TIMEOUT_SECONDS)).until(new ExpectedCondition<Boolean>() {
    public Boolean apply(WebDriver d) {
        return d.getTitle().equals(BROWSE_PAGE_TITLE);
    }
});

I found this Stack Overflow post:

Selenium runs as scheduled task on Windows Server

which suggests that setting the job to "Run whether the user is logged in or not" can fix the problem, but I already have the job set that way.

I have tried both the 32-bit and 64-bit versions of the IEDriverServer.

It is also worth noting that the sendKeys method is taking about 5 seconds per keystroke when using the Task Scheduler, but not when running the batch file directly.

How can I get Selenium to behave the same way using the Task Scheduler as it does when running from the command line?

Additional Info:

  • Windows Server 2008 R2
  • IEDriverServer version 2.42.0
  • Selenium Java version 2.42.2

回答1:


Here is a suggestion, Create an executable jar file (Right click on your project and export as Executable Jar) and try to run that directly instead. I never faced any performance issues with this.

Also, make sure your internet connection is stable, You can use Network tab for those settings before your task runs.

Here is a short description of how to achieve this:

  1. Create a new Task
  2. Set the Schedule
  3. In General Tab, using "Run whether the user is logged in or not" will be great.
  4. Go to Actions, Click on New and Use setting somewhat like this :

  1. In Conditions edit the Power options (You can also select Network settings if you want)

  1. Also, do consider updating the settings as well

Save the task, Right click on task and Run it to check if it works fine.

Hope this is of some help :)



来源:https://stackoverflow.com/questions/24920325/selenium-using-windows-task-scheduler-vs-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!