gpt4 book ai didi

c# - 使用 Protractor 的 C# 单元测试中的无效操作异常

转载 作者:太空宇宙 更新时间:2023-11-03 15:23:24 25 4
gpt4 key购买 nike

我有一个像这样的简单测试类:

public class MyTest
{
const string URL = "https://example.com/content/mypage.aspx";

IWebDriver driver;
NgWebDriver ngDriver;

[SetUp]
public void Setup()
{
driver = new ChromeDriver();
driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(10));
ngDriver = new NgWebDriver(driver);
}

[TearDown]
public void Teardown()
{
ngDriver.Quit();
}

[Test]
public void Basic()
{
ngDriver.Url = URL;

Assert.IsTrue(ngDriver.FindElement(By.CssSelector("#my")).Displayed);
}
}

这是 HTML 片段:

<kendo-button id="my" ng-click="myCtrl.doSomething()">Do Something</kendo-button>

我在 Assert.IsTrue 行收到以下错误:

javascript error: [ng:test] http://errors.angularjs.org/1.3.15/ng/test
JavaScript stack:
Error: [ng:test] http://errors.angularjs.org/1.3.15/ng/test
at Error (native)
at https://example.com/AngularJS/1.3.15/angular.min.js:6:417
at Object.Ld [as getTestability] (https://example.com/AngularJS/1.3.15/angular.min.js:18:468)
at eval (eval at executeAsyncScript (unknown source), <anonymous>:10:13)
at eval (eval at executeAsyncScript (unknown source), <anonymous>:18:5)
at executeAsyncScript (<anonymous>:329:26)
at <anonymous>:345:29
at callFunction (<anonymous>:237:33)
at <anonymous>:247:23
at <anonymous>:248:3
(Session info: chrome=49.0.2623.87)
(Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.1 SP1 x86_64) (UnexpectedJavaScriptError)

堆栈跟踪是:

   at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.ExecuteScriptCommand(String script, String commandName, Object[] args)
at OpenQA.Selenium.Remote.RemoteWebDriver.ExecuteAsyncScript(String script, Object[] args)
at Protractor.NgWebDriver.WaitForAngular() in c:\Users\Bruno\Projets\GitHub\bbaia\protractor-net\src\Protractor\NgWebDriver.cs:line 315
at Protractor.NgWebDriver.FindElement(By by) in c:\Users\Bruno\Projets\GitHub\bbaia\protractor-net\src\Protractor\NgWebDriver.cs:line 262

我只有 Protractor 和 Selenium WebDriver Nuget 包。是否还有其他我需要安装的东西,或者这实际上是代码问题?

最佳答案

您实际上并没有导航到 Assert 之前的 URL?

尝试-

[Test]
public void Basic()
{
NgDriver.Navigate().GoToUrl(URL);
Assert.IsTrue(ngDriver.FindElement(By.CssSelector("#my")).Displayed);
}

关于c# - 使用 Protractor 的 C# 单元测试中的无效操作异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36342951/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com