2

I have a simple test class like this:

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);
    }
}

and here's the HTML snippet:

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

I'm getting the following error on the Assert.IsTrue line:

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)

and the stack trace is:

   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

I only got the Protractor and Selenium WebDriver Nuget package. Is there something else I need to install or this is actually a code problem?

Scott Weldon
  • 9,673
  • 6
  • 48
  • 67
notlkk
  • 1,231
  • 2
  • 23
  • 40

2 Answers2

0

You're not actually navigating to the URL before the Assert?

Try -

[Test]
public void Basic()
{
   NgDriver.Navigate().GoToUrl(URL);
   Assert.IsTrue(ngDriver.FindElement(By.CssSelector("#my")).Displayed);
}
Ory Zaidenvorm
  • 896
  • 1
  • 6
  • 20
0

Building on what I shared below, I found that my problem was not specifying the root to the document. In my tag, I had

data-ng-app='myApp'

The code to create my protractor driver was:

ngDriver = new NgWebDriver(driver, "[ng-data='myApp']"

Protractor-net doesn't modify this direct CSS search criteria, so what worked was:

ngDriver = new NgWebDriver(driver, "[data-ng-app='myApp']"

Not an answer, but I don't have the ability to comment.

I'm seeing the same issue. Further investigation reveals that there is an exception being thrown when the NgWebDriver is instantiated. Inspecting the object shows the Location, PageSource, Title and Url members of the object created all "threw an exception of type 'System.InvalidOperationException' string {System.InvalidOperationException}". The exception only gets thrown up to the test when attempting to find an element.

My code looks like:

        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);

    }

The inspecting the ngDriver object right after it is created shows the exceptions.

If I turn off synchronization before navigating, the only member of the driver object recording the exception is the Location.

        ngDriver = new NgWebDriver(driver, "[ng-app='NCTWebPortal']");
        ngDriver.IgnoreSynchronization=true;
        ngDriver.Manage().Window.Maximize();
        ngDriver.Navigate().GoToUrl(baseURL);
        ngDriver.IgnoreSynchronization = false;