我有一个简单的测试类,如下所示:
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:UsersBrunoProjetsGitHubbbaiaprotractor-netsrcProtractorNgWebDriver.cs:line 315
at Protractor.NgWebDriver.FindElement(By by) in c:UsersBrunoProjetsGitHubbbaiaprotractor-netsrcProtractorNgWebDriver.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);
}
基于我在下面分享的内容,我发现我的问题不是指定文档的根。在我的标签中,我有
data-ng-app='myApp'
创建量角器驱动程序的代码是:
ngDriver = new NgWebDriver(driver, "[ng-data='myApp']"
Protractor net没有修改这个直接的CSS搜索标准,所以有效的是:
ngDriver = new NgWebDriver(driver, "[data-ng-app='myApp']"
没有答案,但我没有能力发表评论。
我看到了同样的问题。进一步的调查显示,在实例化NgWebDriver时会引发异常。检查对象会显示创建的对象的Location、PageSource、Title和Url成员。所有这些成员都"引发了类型为"System.InvalidOperationException"的字符串{System.InvalidOperation exception}的异常"。只有在尝试查找元素时,才会向测试抛出该异常。
我的代码看起来像:
public DefaultPOM(IWebDriver webDriver, string baseURL)
{
driver = webDriver;
this.baseURL = baseURL;
driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(10));
driver.Navigate().GoToUrl(baseURL);
ngDriver = new NgWebDriver(driver, "[ng-app='myApp']");
ngDriver.Manage().Window.Maximize();
ngDriver.Navigate().GoToUrl(baseURL);
}
在ngDriver对象创建后立即检查它会显示异常。
如果在导航前关闭同步,则记录异常的驱动程序对象的唯一成员是Location。
ngDriver = new NgWebDriver(driver, "[ng-app='NCTWebPortal']");
ngDriver.IgnoreSynchronization=true;
ngDriver.Manage().Window.Maximize();
ngDriver.Navigate().GoToUrl(baseURL);
ngDriver.IgnoreSynchronization = false;