jjzjj

c# - BrowserStack:意外错误。需要授权

coder 2024-05-30 原文

我有两个简单的测试,它们将 RemoteWebDriverChromeOptionsEdgeOptions 结合使用。这两个测试都使用通用代码来设置功能,包括 browserstack.userbrowserstack.key 功能。

因为我正在使用 DriverOptions(而不是 DesiredCapabilities),所以我使用了 AddAdditionalCapability(...) 将这些功能添加到驱动程序.

Edge 测试正常,但 Chrome 测试甚至在测试开始之前就失败了;

OpenQA.Selenium.WebDriverException: Unexpected error. Authorization required

在我将我的 Selenium 驱动程序升级到 v3.14(其中 DesiredCapabalities 已被弃用)之前,这些测试之前使用 DesiredCapabalities


更新

我已经降级到 Selenium.WebDriver v3.4。

通过(EdgeOptions)和失败(使用 ChromeOptions)的代码示例:

[TestClass]
public class Simple_GridTest_Chrome
{
    private static IWebDriver driver;

    private string _bsUsername = "<username>";
    private string _bsAccessKey = "<myaccesskey>";

    private string _bsProjectName = "TestProject";
    private string _bsBuildName = "Build-0.0.1";

    private void SetOptions(bool useEdge = false)
    {
        DriverOptions options;

        if (useEdge)
        {
            options = new EdgeOptions(); // this works OK
        } else
        {
            options = new ChromeOptions(); // this fails with OpenQA.Selenium.WebDriverException: Unexpected error. Authorization required
        }

        // the account that is running the test
        options.AddAdditionalCapability("browserstack.user", _bsUsername);
        options.AddAdditionalCapability("browserstack.key", _bsAccessKey);

        options.AddAdditionalCapability("project", _bsProjectName);
        options.AddAdditionalCapability("build", _bsBuildName);

        // gather additional data during the test run (screen shots etc)
        options.AddAdditionalCapability("browserstack.debug", "true");

        driver = new RemoteWebDriver(
          new Uri("https://hub-cloud.browserstack.com/wd/hub/"), options
        );

        //driver = new RemoteWebDriver(
        //  new Uri($"https://{_bsUsername}:{_bsAccessKey}@hub-cloud.browserstack.com/wd/hub/"), options
        //);
    }

    [ClassInitialize()]
    public static void MyClassInitialise(TestContext context)
    {
    }

    [TestMethod]
    [TestCategory("grid.BrowserStack.Google")]
    public void NavigateToGoogle_Windows7_Chrome()
    {
        SetOptions(false); // use Chrome
        GoogleTest(driver);
    }

    [TestMethod]
    [TestCategory("grid.BrowserStack.Google")]
    public void NavigateToGoogle_Windows10_Edge()
    {
        SetOptions(true); // use Edge
        GoogleTest(driver);
    }

    private void GoogleTest(IWebDriver driver)
    {
        driver.Navigate().GoToUrl("https://www.google.com/?q=test");
        Console.WriteLine(driver.Title);

        driver.WaitForWebElement(By.XPath("//*[@name=\"btnK\"]")).Click();
        Console.WriteLine(driver.Title);
    }
}

我安装了以下软件包:

<packages>
  <package id="Selenium.Firefox.WebDriver" version="0.21.0" targetFramework="net45" />
  <package id="Selenium.Support" version="3.4.0" targetFramework="net45" />
  <package id="Selenium.WebDriver" version="3.4.0" targetFramework="net45" />
  <package id="Selenium.WebDriver.ChromeDriver" version="2.41.0" targetFramework="net45" />
  <package id="Selenium.WebDriver.IEDriver" version="3.14.0" targetFramework="net45" />
</packages>

最佳答案

这似乎是一个特定于 selenium 语言绑定(bind)如何生成有效负载以及 browserstack 在其末端如何解析它的问题。

根据您分享的错误消息,很可能在解析请求负载时,browserstack 无法找到您的用户名和访问 key

您可以按照下面提到的步骤进行调试:

  • 更改行 driver = new RemoteWebDriver(new Uri("https://hub-cloud.browserstack.com/wd/hub/"), options);driver = new RemoteWebDriver( new Uri("http://localhost:4444/wd/hub/"), options ); .您不需要在本地启动 selenium-standalone jar。

  • 启动一个代理来读取 localhost:4444 上的流量。 (如果需要,您可以使用基于节点的实现。这是一个这样的实现:https://gist.github.com/hanikhan/f817bd64b063129cb78dc7ed0b66fdb7)

  • 观察您正在使用的 selenium 客户端绑定(bind)生成的请求负载(您提到的 v3.14)。例如,我的基于 java 的 selenium 客户端在仅传递浏览器时生成它是 desiredcapabitlies {"desiredCapabilities":{"browserName":"Chrome"},"capabilities":{"firstMatch":[{"browserName":"Chrome"}]}}

  • 现在将您的 selenium 绑定(bind)降级(到它可以工作的版本)并观察它生成的有效载荷。

检查客户端绑定(bind)是否使用严格检查,因为某些必需的功能在您端被丢弃。

如果这是真的,那么您将需要执行以下操作之一:

  • 提出有关 selenium C# 绑定(bind)的问题,以取消对您的案例的严格检查
  • 联系Browserstack,请他们提供通过严格检查的能力

关于c# - BrowserStack:意外错误。需要授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52207093/

有关c# - BrowserStack:意外错误。需要授权的更多相关文章

  1. ruby - 我需要将 Bundler 本身添加到 Gemfile 中吗? - 2

    当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/

  2. ruby-on-rails - Rails 常用字符串(用于通知和错误信息等) - 2

    大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje

  3. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  4. ruby - rspec 需要 .rspec 文件中的 spec_helper - 2

    我注意到像bundler这样的项目在每个specfile中执行requirespec_helper我还注意到rspec使用选项--require,它允许您在引导rspec时要求一个文件。您还可以将其添加到.rspec文件中,因此只要您运行不带参数的rspec就会添加它。使用上述方法有什么缺点可以解释为什么像bundler这样的项目选择在每个规范文件中都需要spec_helper吗? 最佳答案 我不在Bundler上工作,所以我不能直接谈论他们的做法。并非所有项目都checkin.rspec文件。原因是这个文件,通常按照当前的惯例,只

  5. ruby - 如何在 Lion 上安装 Xcode 4.6,需要用 RVM 升级 ruby - 2

    我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121

  6. ruby-on-rails - 迷你测试错误 : "NameError: uninitialized constant" - 2

    我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test

  7. ruby-on-rails - 如何在 Rails View 上显示错误消息? - 2

    我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c

  8. 使用 ACL 调用 upload_file 时出现 Ruby S3 "Access Denied"错误 - 2

    我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file

  9. ruby-on-rails - 错误 : Error installing pg: ERROR: Failed to build gem native extension - 2

    我克隆了一个rails仓库,我现在正尝试捆绑安装背景:OSXElCapitanruby2.2.3p173(2015-08-18修订版51636)[x86_64-darwin15]rails-v在您的Gemfile中列出的或native可用的任何gem源中找不到gem'pg(>=0)ruby​​'。运行bundleinstall以安装缺少的gem。bundleinstallFetchinggemmetadatafromhttps://rubygems.org/............Fetchingversionmetadatafromhttps://rubygems.org/...Fe

  10. ruby - #之间? Cooper 的 *Beginning Ruby* 中的错误或异常 - 2

    在Cooper的书BeginningRuby中,第166页有一个我无法重现的示例。classSongincludeComparableattr_accessor:lengthdef(other)@lengthother.lengthenddefinitialize(song_name,length)@song_name=song_name@length=lengthendenda=Song.new('Rockaroundtheclock',143)b=Song.new('BohemianRhapsody',544)c=Song.new('MinuteWaltz',60)a.betwee

随机推荐