bbaia / protractor-net

The .NET port of Protractor, an E2E test framework for Angular apps
MIT License
115 stars 72 forks source link

find elements by ng-model does not work? #48

Open debasisj opened 7 years ago

debasisj commented 7 years ago

Hi I have the ng-model = "userService.account" which is in side ng-app Now when i give a try find elements like Driver.FindElement(NgBy.Model("userService.account")); the below exceptions throws. But the code above to find elements by repeater works perfectly!! (the first 5 lines below.)


Gilgandra 15/16 Chickpeas - CHKP 933.5 mt $1,111.00 8 hours Baan Baa 15/16 Barley - F1 1713 mt $11,111.00 8 hours Ardlethan 15/16 Wheat - APH2 11 mt $2,222.00 5 days Baan Baa 15/16 Barley - F2 755 mt $22,145.00 5 days

Armatree 15/16 Sorghum - SOR 6000 mt $500.00 7 days

Then the this error for find by model 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.ExecuteScript(String script, Object[] args) at Protractor.JavaScriptBy.FindElements(ISearchContext context) in c:\Users\Bruno\Projets\GitHub\bbaia\protractor-net\src\Protractor\JavaScriptBy.cs:line 90 at Protractor.JavaScriptBy.FindElement(ISearchContext context) in c:\Users\Bruno\Projets\GitHub\bbaia\protractor-net\src\Protractor\JavaScriptBy.cs:line 49 at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by) at CropConnect.TestScripts.UnitTest1.TestMethodForDemo() in C:\VisualStudio Projects\com.GrainCorp.SL\CropConnect\TestScripts\UnitTest1.cs:line 92

Magadan84 commented 7 years ago

Hi I get the issue also. Please, fix it asap, because projects are crashed. I tried to use the previous version 0.8.0 - and I also get the issue. FindElement gives error as well: {"asynchronous script timeout: result was not received in 0 seconds\n (Session info: chrome=53.0.2785.143)\n (Driver info: chromedriver=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf),platform=Windows NT 10.0.10586 x86_64)"}

at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary2 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() в c:\Users\Bruno\Projets\GitHub\bbaia\protractor-net\src\Protractor\NgWebDriver.cs:line 364 at Protractor.NgWebDriver.FindElement(By by) в c:\Users\Bruno\Projets\GitHub\bbaia\protractor-net\src\Protractor\NgWebDriver.cs:line 279`

bbaia commented 7 years ago

Add a timeout for async scripts :

// Required for TestForAngular and WaitForAngular scripts
driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(5));
debasisj commented 7 years ago

Thanks Bruno, but my original post still unresolved What i can see, as soon i give By.Model or Binding command, execution immediately goes to exception, doubt it even look at the DOM. Where as ng-repeat works fine. Can you please suggest

disophisis commented 7 years ago

@debasisj If you try locating that element by CSS Selector: By.CssSelector("[ng-model='userService.account']")

Does that work? That might be a helpful test in this situation.

bbaia commented 7 years ago

@disophisis did you resolve your problem ? What angular version are you using ?

sergueik commented 7 years ago

@debasisj @bbaia the ngmodel may require the second argument like. NgWebElement ng_element = ng_dropdown.FindElement(NgBy.Model("data.dateDropDownInput", "[data-ng-app]")); see my fork for the example: https://github.com/sergueik/powershell_selenium/blob/master/csharp/protractor-net/Test/DatePickerTests.cs#L49 @bbaia do you mind if i create a PR fom my fork - i have somewhere between 100 and 200 tests exercising various aspects of Protractor.net , and a few extra ClientSideScripts, and misc. refacoring..

Serguei Kouzmine

debasisj commented 7 years ago

@disophisis thanks for the suggestion but finding element was not my intention instead would like to extract the data from the scope that being attached to the specific ng model @sergueik how you able to pass two parameters to NgBy.Model - is this part of your version?

sergueik commented 7 years ago

@debasisj - both .net https://github.com/sergueik/powershell_selenium/blob/master/csharp/protractor-net/Program/ClientSideScripts.cs#L245

and java https://github.com/sergueik/jProtractor/blob/master/src/main/resources/model.js#L9

ports of Protracor have

var findByModel = function(model, using, rootSelector) {
    var root = document.querySelector(rootSelector || 'body');
using = using || '[ng-app]';
    using = using || document;
... 
}
var using = arguments[0] || document;
var model = arguments[1];
var rootSelector = arguments[2];
return findByModel(model, using, rootSelector);

The genuine Protractor https://github.com/sergueik/jProtractor/blob/master/src/main/resources/model.js#L9 does not have the

    using = using || '[ng-app]';

line but has the same signature.

It DOES look like Bruno's Protractor-net does not pass the argument https://github.com/bbaia/protractor-net/blob/master/src/Protractor/NgByModel.cs#L13:

 public NgByModel(string model)
            : base(ClientSideScripts.FindModel, model)
        {

while ( Becker / myself ) Java https://github.com/sergueik/jProtractor/blob/master/src/main/java/com/jprotractor/NgBy.java#L51

 public static By model(final String model) {
    return new JavaScriptBy(new FindModel(), model);
  }

  public static By model(final String model, String rootSelector) {
    return new JavaScriptBy(new FindModel(), model, rootSelector);
  }

and .net client

public static By Model(string model, string rootSelector = null)
        {
            return new JavaScriptBy(ClientSideScripts.FindModel, model, rootSelector);

do.

The integration tests of the Angular Datepicker http://dalelotts.github.io/angular-bootstrap-datetimepicker/ by both c#
https://github.com/sergueik/powershell_selenium/blob/master/csharp/protractor-net/Test/DatePickerTests.cs and Java https://github.com/sergueik/jProtractor/blob/master/src/test/java/com/jprotractor/integration/NgDatePickerTest.java confirm it works right. Note, the tests were specifically designed to exercise this. The DatePicker page contains several ng-app fragments, and without the second argument the tests report an no injector found for element argument error (details in the code)