0

我正在尝试使用带有 Webjobs 的 Azure WebApps 来测试应用程序。在本地,它工作得很好。但是当我构建到云时,就会出现上面列出的问题。

显然该文件已找到,但它一直等待直到超时。

有谁知道如何解决这个问题?我正在使用 C# Selenium WebDriver。

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Diagnostics;
using System.IO;

namespace Ololu_WebJob
{
    class Program
    {
        static void Main()
        {
            IWebDriver driver = new ChromeDriver();
            driver.Url = "my_url";

            Console.WriteLine(driver.Title);

            driver.Quit();
        }
    }
}

/*
    LOG:
    [02/10/2019 12:27:51 > 7f9c27: SYS INFO] Status changed to Initializing
    [02/10/2019 12:27:51 > 7f9c27: SYS INFO] Job directory change detected: Job file 'Ololu_WebJob.exe' timestamp differs between source and working directories.
    [02/10/2019 12:27:53 > 7f9c27: SYS INFO] Run script 'chromedriver.exe' with script host - 'WindowsScriptHost'
    [02/10/2019 12:27:53 > 7f9c27: SYS INFO] Status changed to Running
    [02/10/2019 12:27:53 > 7f9c27: INFO] Starting ChromeDriver 2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1) on port 9515
    [02/10/2019 12:27:53 > 7f9c27: INFO] Only local connections are allowed.
    [02/10/2019 12:27:53 > 7f9c27: INFO] Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
    [02/10/2019 12:31:55 > 7f9c27: ERR ] Command 'cmd /c ""chromedriv ...' was aborted due to no output nor CPU activity for 121 seconds. You can increase the SCM_COMMAND_IDLE_TIMEOUT app setting (or WEBJOBS_IDLE_TIMEOUT if this is a WebJob) if needed.
    cmd /c ""chromedriver.exe""
    [02/10/2019 12:31:55 > 7f9c27: SYS INFO] Status changed to Failed
    [02/10/2019 12:31:55 > 7f9c27: SYS ERR ] System.AggregateException: One or more errors occurred. ---> Kudu.Core.Infrastructure.CommandLineException: Command 'cmd /c ""chromedriv ...' was aborted due to no output nor CPU activity for 121 seconds. You can increase the SCM_COMMAND_IDLE_TIMEOUT app setting (or WEBJOBS_IDLE_TIMEOUT if this is a WebJob) if needed.
    cmd /c ""chromedriver.exe""
       at Kudu.Core.Infrastructure.IdleManager.WaitForExit(IProcess process) in C:\Kudu Files\Private\src\master\Kudu.Core\Infrastructure\IdleManager.cs:line 45
       at Kudu.Core.Infrastructure.ProcessExtensions.<Start>d__12.MoveNext() in C:\Kudu Files\Private\src\master\Kudu.Core\Infrastructure\ProcessExtensions.cs:line 212
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Kudu.Core.Infrastructure.Executable.<ExecuteAsync>d__31.MoveNext() in C:\Kudu Files\Private\src\master\Kudu.Core\Infrastructure\Executable.cs:line 255
       --- End of inner exception stack trace ---
       at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
       at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
       at System.Threading.Tasks.Task`1.get_Result()
       at Kudu.Core.Infrastructure.Executable.ExecuteInternal(ITracer tracer, Func`2 onWriteOutput, Func`2 onWriteError, Encoding encoding, String arguments, Object[] args) in C:\Kudu Files\Private\src\master\Kudu.Core\Infrastructure\Executable.cs:line 216
       at Kudu.Core.Infrastructure.Executable.ExecuteReturnExitCode(ITracer tracer, Action`1 onWriteOutput, Action`1 onWriteError, String arguments, Object[] args) in C:\Kudu Files\Private\src\master\Kudu.Core\Infrastructure\Executable.cs:line 165
       at Kudu.Core.Jobs.BaseJobRunner.RunJobInstance(JobBase job, IJobLogger logger, String runId, String trigger, ITracer tracer, Int32 port) in C:\Kudu Files\Private\src\master\Kudu.Core\Jobs\BaseJobRunner.cs:line 272
    ---> (Inner Exception #0) ExitCode: -1, Output: Command 'cmd /c ""chromedriv ...' was aborted due to no output nor CPU activity for 121 seconds. You can increase the SCM_COMMAND_IDLE_TIMEOUT app setting (or WEBJOBS_IDLE_TIMEOUT if this is a WebJob) if needed., Error: Command 'cmd /c ""chromedriv ...' was aborted due to no output nor CPU activity for 121 seconds. You can increase the SCM_COMMAND_IDLE_TIMEOUT app setting (or WEBJOBS_IDLE_TIMEOUT if this is a WebJob) if needed., Kudu.Core.Infrastructure.CommandLineException: Command 'cmd /c ""chromedriv ...' was aborted due to no output nor CPU activity for 121 seconds. You can increase the SCM_COMMAND_IDLE_TIMEOUT app setting (or WEBJOBS_IDLE_TIMEOUT if this is a WebJob) if needed.
    cmd /c ""chromedriver.exe""
       at Kudu.Core.Infrastructure.IdleManager.WaitForExit(IProcess process) in C:\Kudu Files\Private\src\master\Kudu.Core\Infrastructure\IdleManager.cs:line 45
       at Kudu.Core.Infrastructure.ProcessExtensions.<Start>d__12.MoveNext() in C:\Kudu Files\Private\src\master\Kudu.Core\Infrastructure\ProcessExtensions.cs:line 212
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Kudu.Core.Infrastructure.Executable.<ExecuteAsync>d__31.MoveNext() in C:\Kudu Files\Private\src\master\Kudu.Core\Infrastructure\Executable.cs:line 255<---

*/
4

1 回答 1

0

根据我的经验,如果没有在 Azure WebApp 上安装 Chrome 或 Chromium 实例,您不能直接使用 selenium 和 chromedriver,正如 ChromeDriver Setup的要求所述。

  • 确保 Chromium/Google Chrome 安装在可识别的位置

ChromeDriver 希望您将 Chrome 安装在您平台的默认位置。您还可以通过设置特殊功能来强制 ChromeDriver 使用自定义位置。

但是,由于 Azure WebApp 沙盒的一些限制,其中包括Win32k.sys (User32/GDI32) RestrictionsLocal Address Requests,即使您将 Chrome 或 Chromium 的可移植分发版上传到 Azure WebApp 并配置了环境变量,您也无法通过 chromedriver 在没有 GDI 支持的情况下启动 Chrome 或 Chromium。

尽管您的错误信息没有指出 C# 代码中问题的真正原因,但我在 Azure WebApp 上的 Python 中得到了错误信息,如下所示。

在此处输入图像描述

因此一种解决方法是直接在 Azure VM 上使用 selenium 和 chromedriver。或者考虑您的方案,您可以在 Azure VMchromedriver上的默认端口9515上启动并配置 VM NSG 角色以允许端口 9515 的入站,然后使用类OpenQA.Selenium.Remote.RemoteWebDriver连接 Azure WebJob 中的远程 webdriver。

这是RemoteWebDriver来自C# (CSharp) OpenQA.Selenium.Remote RemoteWebDriver.FindElement 示例的示例代码

IWebDriver webDriver = new RemoteWebDriver(new Uri("http://<vm host ip>:9515"), DesiredCapabilities.Chrome());
于 2019-02-11T09:37:49.063 回答