GithubHelp home page GithubHelp logo

paul-hammant / ngwebdriver Goto Github PK

View Code? Open in Web Editor NEW
276.0 60.0 86.0 615 KB

AngularJS and WebDriver bits and pieces for Java (port of Protractor)

License: MIT License

Java 56.90% Shell 0.12% JavaScript 32.91% HTML 9.20% CSS 0.87%

ngwebdriver's Introduction

ngWebDriver

A small library of WebDriver locators and more for AngularJS (v1.x) and Angular (v2 through v12), for Java. It works with Firefox, Chrome and all the other Selenium-WebDriver browsers.

javadoc

Status

We have taken JavaScript directly from Angular's Protractor project. While ngWebDriver perfectly compliments the Java version of WebDriver, it has to pass JavaScript up to the browser to interoperate with AngularJS and Angular (less than v12), and the Protractor project has done the hard work (including testing) to make that solid. This project benefits from that work.

The Protractor team has stopped work now. Angular itself will incrementally drop old Protractor capability. We are not going to be able to keep nbWebDriver going on our own. Please don't email us to ask us or file bugs asking. If you can't go in the directions that the Angular team suggest, flip to plain Selenium use and live without the Angular-specific bits and pieces.

Compatibility

Like Protractor, ngWebDriver works with AngularJS versions greater than 1.0.6/1.1.4, and is compatible with Angular 2-12 applications. Note that for Angular 2-12 apps, the binding and model locators are not supported. We recommend using by.css.

Documentation

Waiting for Angular to finish async activity

ChromeDriver driver = new ChromeDriver();
NgWebDriver ngWebDriver = new NgWebDriver(driver);
ngWebDriver.waitForAngularRequestsToFinish();

Do this if WebDriver can possibly run ahead of Angular's ability finish it's MVC stuff in your application. In some of the error cases (e.g. if it's not an angular application or if the root selector could not be found correctly in an angular 2 app, an error message is returned from the waitForAngularRequestsToFinish method.

Locators

repeater()

As Protractor's repeater locator this works for arbitrary ng-repeat elements, not just <tr> or <td>.

ByAngular.repeater("foo in f")
ByAngular.repeater("foo in f").row(17)
ByAngular.repeater("foo in f").row(17).column("foo.name")
ByAngular.repeater("foo in f").column("foo.name")

exactRepeater()

As Protractor's exactRepeater

ByAngular.exactRepeater("foo in foos")
ByAngular.exactRepeater("foo in foos").row(17)
ByAngular.exactRepeater("foo in foos").row(17).column("foo.name")
ByAngular.exactRepeater("foo in foos").column("foo.name")

binding()

As Protractor's binding locator

ByAngular.binding("person.name")
ByAngular.binding("{{person.name}}")
// You can also use a substring for a partial match
ByAngular.binding("person");

exactBinding()

As Protractor's exactBinding locator

ByAngular.exactBinding("person.name")
ByAngular.exactBinding("{{person.name}}")

model()

As Protractor's model locator

ByAngular.model('person.name')

options()

As Protractor's options locator

ByAngular.options("c for c in colors")

buttonText()

As Protractor's buttonText locator

ByAngular.buttonText("cLiCk mE")

partialButtonText()

As Protractor's partialButtonText locator

// If you have a button name "Click me to open", using just "click" would do if you partialButtonText
ByAngular.partialButtonText("cLiCk ")

cssContainingText()

As Protractor's cssContainingText locator

ByAngular.cssContainingText("#animals ul .pet", "dog")

Page Objects.

The work in the same way at WebDriver's page object technology, there are a set of FindBy annotations for ngWebDriver:

@ByAngularBinding.FindBy(..)
@ByAngularButtonText.FindBy(..)
@ByAngularButtonText.FindBy(..)
@ByAngularCssContainingText.FindBy(..)
@ByAngularExactBinding.FindBy(..)
@ByAngularModel.FindBy(..)
@ByAngularOptions.FindBy(..)
@ByAngularPartialButtonText.FindBy(..)
@ByAngularRepeater.FindBy(..)
@ByAngularRepeaterCell.FindBy(..)
@ByAngularRepeaterColumn.FindBy(..)
@ByAngularRepeaterRow.FindBy(..)

Declare them above fields as you would have done for FindBy in the regular WebDriver and continue to to use PageFactory.initElements(..) as normal. Refer to the parameters for the new FindBy static inner classes as there's rootSelector argument that is optional, but should have been tried before you raise a bug with ngWebDriver.

Angular model interop

As with Protractor, you can change items in an Angular model, or retrieve them regardless of whether they appear in the UI or not.

Changing model variables

NgWebDriver ngWebDriver = new NgWebDriver(driver);
// change something via the model defined in $scope
ngWebDriver.mutate(formElement, "person.name", "'Wilma'");
// Note Wilma wrapped in single-quotes as it has to be a valid JavaScript
// string literal when it arrives browser-side for execution

Getting model variables

As a JSON string:

NgWebDriver ngWebDriver = new NgWebDriver(driver);
// Get something via the model defined in $scope
String personJson = ngWebDriver.retrieveJson(formElement, "person");

As a string:

NgWebDriver ngWebDriver = new NgWebDriver(driver);
// Get something via the model defined in $scope
String personName = ngWebDriver.retrieveAsString(formElement, "person.name");

As a number:

NgWebDriver ngWebDriver = new NgWebDriver(driver);
// Get something via the model defined in $scope
Long personAge = ngWebDriver.retrieveAsLong(formElement, "person.age");

As Map/dict:

NgWebDriver ngWebDriver = new NgWebDriver(driver);
// Get something via the model defined in $scope
Map person = (Map) ngWebDriver.retrieve(formElement, "person");
// note - could be List instead of a Map - WebDriver makes a late decision on that

Helping NgWebDriver find Angular apps in a page

Getting "Cannot read property '$$testability' of undefined" ?

If you're seeing $$testability referenced in a WebDriver error, then work out in you have correctly set selector for the "root element" on the Angular app. Specifically have you used .withRootSelector(..) in situations where you need to use it? Details about how to recover from that here...

To specify a different "root selector" to help ngWebDriver find the Angular app, take a look at what is defined in the ng-app attribute in the page in question. Examples:

NgWebDriver ngwd = new NgWebDriver(webDriver).withRootSelector("something-custom");
ByAngular.Factory baf = ngwd.makeByAngularFactory()
WebElement element = webDriver.findElement(baf.exactRepeater("day in days"));
element.click();

// locators
ByAngular.withRootSelector("something-custom").exactRepeater("day in days");

// or
ByAngular.Factory baf = ByAngular.withRootSelector("something-custom");
ByAngularRepeater foo = baf.exactRepeater("day in days");

Alternate root selectors

Referring to a handy StackOverflow questions - No injector found for element argument to getTestability, you can use the applicable selector for your Angular app:

  • .withRootSelector("[ng-app]")- matching an element that has the arribute ng-app (this is the default)
  • .withRootSelector("\"app-root\"")- matching an element that has the element name app-root
  • .withRootSelector("#my-app") - matching an id my-app
  • .withRootSelector("[fooBar]") - matching an attribute fooBar on any element
  • .withRootSelector("[module=todoApp]") - the "todo app" module (amongst others) on the https://angularjs.org home page.

There's a reference to css selectors you'll need to read - https://www.w3schools.com/cssref/css_selectors.asp - because that's the type of string it is going to require.

Still needing help on $$testability ?

Read the five or so bug reports on $$testability and how (most likely) you have to learn a little about you application so that you can use .withRootSelector("\"abc123\""). Those bug reports: https://github.com/paul-hammant/ngWebDriver/issues?issue+testability. Also deeply read the css_selectors page on w3schools.com (link above) so you can fine tune your selector fu before filing a bug against this project.

Other Functions

getLocationAbsUrl()

Returns the URL of the page.

String absoluteUrl = new NgWebDriver(driver).getLocationAbsUrl();

Code Examples

All our usage examples are in a single test class:

Including it in your project

Maven

<dependency>
  <groupId>com.paulhammant</groupId>
  <artifactId>ngwebdriver</artifactId>
  <version>1.1.5</version>
  <!-- You might want to delete the following line if you get "package com.paulhammant.ngwebdriver does not exist" errors -->
  <scope>test</scope>
</dependency>

<!-- you still need to have a dependency for preferred version of
  Selenium/WebDriver. That should be 3.3.1 or above -->

Non-Maven

Download from Mavens Central Repo

Releases

Last Release: 1.1.5 - Feb 22, 2020

Refer CHANGELOG

Seeking help

  1. take a look all of this README - it is not that long
  2. take a look at the issues (open and closed)
  3. read the Code of Conduct and raise an issue, but be sure to make it really really easy for committers to reproduce your error. Like a clone and a build and - bang - perfect reproduction.
  4. if there's some reason you can't do the reproduction on GitHub contact Paul Hammant - [email protected] - for custom support.

ngwebdriver's People

Contributors

auto81 avatar d-rk avatar dependabot[bot] avatar elgalu avatar manoj9788 avatar paul-hammant avatar phystem avatar rrhartjr avatar samoretc avatar sergueik avatar tarioch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ngwebdriver's Issues

cssContainingText does not replace {0} with appropriate value

Hi Paul,

I have Serenity BDD using ngWebDriver to locate my navigator.
And I can locate my navigator using the following code:

public static final Target MAIN_MENU_OPTION = Target.the("{0}")
        .located(ByAngular.cssContainingText(".app-menu-item", "Manage Models"));

which is called by:

            WaitUntil.angularRequestsHaveFinished(),
            Click.on(MenuBar.MAIN_MENU_OPTION.called("Manage Models"))

When I change the String in cssContainingText as "{0}", then ngWebDriver fails with the following error:

Caused by: org.openqa.selenium.TimeoutException: Expected condition failed: waiting for cssContainingText(.app-menu-item{0}) to be enabled (tried for 5 second(s) with 100 milliseconds interval)

For reference, the code by which I have replaced the string to "{0}":

public static final Target MAIN_MENU_OPTION = Target.the("{0}")
        .located(ByAngular.cssContainingText(".app-menu-item", "{0}"));

I can see the first "{0}" works fine in both the cases but fails within cssContainingText.
It might be to with how ngwebdriver treats the replacement string, "{0}" but I cannot pin the issue here exactly.

The reason, I have the replacement/placeholder is that I'm trying to use this locator for re-usability.

I'm using ngWebDriver: 1.1.4.
Also note that I have the same problem with other methods like binding, model.

ngWebDriver shadow dom

Ther's anyway of reaching deep css/shadow DOM via ngWebDriver or should i try via Selenium?

Thanks!

WaitForAngualrRequestToFinish not holding the DOM

Hi Paul,
Here I got some issue in my test code during title validation:
Hi Paul,
I tried to perform an end to end scenario with ng webdriver. after login, its not able to validate tile of home page and then its not able to identify elements and giving below error:

code:
package sample.example;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.Select;

import com.paulhammant.ngwebdriver.ByAngular;
import com.paulhammant.ngwebdriver.ByAngularBinding;
import com.paulhammant.ngwebdriver.NgWebDriver;

public class NGTEST
{
static NgWebDriver ngdriver;
static WebDriver driver;

public static void main(String[] args)
{
	DesiredCapabilities capabilities = new DesiredCapabilities();
	capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
	System.setProperty("webdriver.ie.driver","C:\\Users\\pnarra\\Documents\\MyJabberFiles\\[email protected]\\phyconUI\\phyconUI\\Drivers\\IEDriverServer_Win32_2.47.0\\IEDriverServer.exe");
	driver = new InternetExplorerDriver(capabilities);	
	//driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
	driver.manage().timeouts().setScriptTimeout(60, TimeUnit.SECONDS);
	ngdriver= new NgWebDriver((JavascriptExecutor)driver);
	driver.get("http://pdm-dev4.linkhealth.com");		
	ngdriver.waitForAngularRequestsToFinish();	
	if(driver.getTitle().toString().equals("Sign In With Your Optum ID - Optum ID"))
	{
		System.out.println("Entered");
		List<WebElement> models = driver.findElements(ByAngular.model("model"));
		models.get(0).click();
		models.get(0).sendKeys("MArthamCorp4");
		models.get(1).click();
		models.get(1).clear();
		models.get(1).sendKeys("Testcorp44");
		driver.findElement(By.id("SignIn")).click();
		if(driver.getTitle().toString().equals("My Practice Profile"))
		{
			System.out.println("Application found");
		}
		else
		{
			System.err.println("Application not found");
		}
		WebElement listObj = driver.findElement(By.id("taxId"));
		Select list = new Select(listObj);
		list.selectByIndex(0);
		WebElement tinObj = driver.findElement(ByAngular.model("vm.selectedProviderObj.tinObj"));
		Select tin = new Select(tinObj);
		System.out.println("The default populated tin was: "+tin.getFirstSelectedOption().getText());
	}
	
}

}

I have tried selenium wait.until explicit wait as well, but its very slow. cant I use them?

please find below screenshot for error reference.

ngerror
dom

unknown error: exception when using ByAngular.model

I am getting unknown error: exception when using ByAngular.model

org.openqa.selenium.WebDriverException: unknown error: [ng:test] http://errors.angularjs.org/1.5.8/ng/test
(Session info: chrome=52.0.2743.116)
(Driver info: chromedriver=2.22.397933 (1cab651507b88dec79b2b2a22d1943c01833cc1b),platform=Windows NT 10.0.10586 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 10 milliseconds
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
Driver info: org.openqa.selenium.chrome.ChromeDriver
I used the below code
Select typedropdown = new Select(driver.findElement(ByAngular.model("$select.search")));
typedropdown.selectByVisibleText("Branch");

WaitForAngular2ToFinish() is failing with an error "Could not find testability for element. "

@paul-hammant

First of all,Thank you for such an amazing work on ngWebDriver. I am trying to implement it for one of the sites built on Angular 4. I've gone through the sample test & tried all feasible steps - No luck. May be I am missing something.

I am using ngWebDriver in conjunction with QAF & here is how my code looks

   `QAFExtendedWebDriver driver = getDriver();
NgWebDriver ngWebDriver = new NgWebDriver((JavascriptExecutor)driver);`

when the below line executes, I am seeing an exception
ngWebDriver.WaitForAngular2ToFinish();

TestNG: e to bad ' +\n 'obfuscation.');\n } else {\n throw new Error('Cannot get testability API for unknown angular ' +\n 'version "' + window.angular.version + '"');\n }\n } catch (err) {\n callback(err.message);\n }\n"}
TestNG: );
} else {
throw new Error('Cannot get testability API for unknown angular ' +
'version "' + window.angular.version + '"');
}
} catch (err) {
callback(err.message);
}
}] Result: Could not find testability for element.

The app root on DOM shows something like this
<app-root _nghost-c0="" ng-version="5.0.3">

package com.paulhammant.ngwebdriver does not exist

I am using Maven and configured it to get ngwebdriver-0.9.7.jar. The imports statements for ngwebdriver throw error at compile time. This happens if i use these import statements in my cucumber step definition files. I have verified existence of the ngwebdriver-0.9.7 under Maven Dependencies.

I have created another project without cucumber references and it works when i use ngWebdriver in testNG class without cucumber.

import com.paulhammant.ngwebdriver.ByAngular;
import com.paulhammant.ngwebdriver.NgWebDriver;

NgWebDriver ngWebDriver = new NgWebDriver((JavascriptExecutor)driver);
driver.get("https://angularjs.org/");
ngWebDriver.waitForAngularRequestsToFinish();
driver.findElement(ByAngular.model("yourName")).sendKeys("Bill");

Please advise.

Regarding driver.get

Hello, I was trying to learn protactor testing using ng webdriver, but in your code sometimes you have use localhost in driver.get,which my machine cant open because its your machine can access only , if you can give the url , just like you have use in some test cases ,it will be great help for me..

find element By Binding is not working

I am facing this issue from last 3 days. I am trying to automate https://weather.com/en-IN webapplication which built in AngularJS.

I am trying to find element using binding but its giving me like no such element is there in DOM.
Below is the test scenario:

ChromeDriver driver = new ChromeDriver();
NgWebDriver ngWebDriver = new NgWebDriver(driver);
driver.get("https://weather.com/en-IN");
ngWebDriver.waitForAngularRequestsToFinish();
WebElement menuEle = driver.findElement(ByAngular.binding("::userLocationVm.localeDisplay"));

Please help me out for this issue.

AngularAndWebDriverTest.java needs update

ngModel.mutate(we, "location.City", "'Narnia'"); line 187

On the example webpage you are using there is no location.City model or variable. I am not sure if I am missing something or if their website has changed.

Could not import NgWebDriver into my class file

I have downloaded ngwebdriver jar file version 0.9.2 and added jar file into my project. When I instantiate NgWebDriver ngdriver=new NgWebDriver(); I could not import the class. Please let me know how to import it and needed urgently.

Thanks
Sathish

waitForAngularRequestsToFinish() is working intermittently in chrome version 47.0.25

As my application is based on angularJS, i am using the ngwebdriver's method waitForAngularRequestsToFinish to handle the background rendering to complete.
(Webdriver's method of implicit and explicit wait is not working properly on AngularJS application)

Issue is that when I ran the script yesterday, e2e automation flow was working fine. But, today the script fails as waitForAngularRequestsToFinish is not able to handle the rendering.

Please guide how to handle the above issue.

snippet of my code to execute the browser driver:

public static void callChrome()
    {
        System.setProperty("webdriver.chrome.driver", "D:\\software_setup\\chromedriver.exe");

    }

    //public static WebDriver driver=new FirefoxDriver(FFprofile());
    public static WebDriver driver=new ChromeDriver();
    public static NgWebDriver ngwebdriver=new NgWebDriver((JavascriptExecutor)driver);

Problem in initialization NgWebDriver

Hi,

I am facing problem (compile time) at the time of NgWebDriver initialization using below code.

private NgWebDriver ngWebDriver;
private WebDriver selenium;

selenium = new FirefoxDriver;
ngWebDriver = new NgWebDriver(selenium);

using above code, I am getting compile time error -->
The constructor NgWebDriver(WebDriver) is undefined

I know this can be fixed using the FirefoxDriver instead of WebDriver but i have a situation where I need to use WebDriver.

Thanks,
Nikesh

Version confusion / HtmlUnitDriver

I have an AngularJS app I want to test with this. I added it through gradle, and it seems like this library has a dependency on some version of selenium that doens't come with HtmlUnitDriver. The POM file you have on master references a 3.x selnenium, but what is in the gradle package?

I tried manually adding a reference to the html unit driver lib in gradle, but I can't construct it, presumbably some conflict with whatever selenium-java version that ngWebDriver is referencing.

java.lang.NoClassDefFoundError: org/openqa/selenium/ElementNotInteractableException

//    integrationTestCompile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.5.3'
//    integrationTestCompile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '2.53.1'
    integrationTestCompile group: 'com.paulhammant', name: 'ngwebdriver', version: '1.0'
//    integrationTestCompile group: 'org.seleniumhq.selenium', name: 'htmlunit-driver', version: '2.27'

findElements() is meaningless

This locator zooms in on a single cell, findElements() is meaningless

Is there any specific reason why findElements is not implemented for ByAngularRepeaterCell and ByAngularRepeaterRow

I needed it in my application

Using Selenium @FindBy with @ByAngularXYZ.FindBy

Hello Paul,
Relating to #26, is it possible to have a similar implementation as Selenium's native FindBy?

@FindBy(how = How.BY_ANGULAR_MODEL, rootSelector = "butter", model = "cheese")

Same with FindBys and FindAll.

I am trying to use Selenium's FindBy with the ngWebDriver FindBy here but they do not appear to work together when used in the same page object.

Angular 4

Is it compatible with angular 4. I'm always having a timeout exception while instantiating ngwebdriver

NullPointerException when trying to access waitForAngularRequestsToFinish()

java.lang.NullPointerException
at businesscomponents.ngWebDriverTest.fnTestngWebBasic(ngWebDriverTest.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at supportlibraries.DriverScript.invokeBusinessComponent(DriverScript.java:443)
at supportlibraries.DriverScript.executeTestcase(DriverScript.java:388)
at supportlibraries.DriverScript.executeTestIterations(DriverScript.java:339)
at supportlibraries.DriverScript.driveTestExecution(DriverScript.java:108)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at allocator.ParallelRunner.invokeTestScript(ParallelRunner.java:69)
at allocator.ParallelRunner.run(ParallelRunner.java:45)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

Specified root selector but still getting error Cannot read property '$$testability' of undefined

Test app url : https://angularjs.org/. specified the root selector but still getting
ERROR!
org.openqa.selenium.WebDriverException:
unknown error: Cannot read property '$$testability' of undefined
(Session info: chrome=66.0.3359.181)
(Driver info: chromedriver=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Windows NT 6.3.9600 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: 'HOU-QA-1', ip: '192.168.1.10', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_171'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.38.552522 (437e6fbedfa876..., userDataDir: C:\Users\AppData\L...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 66.0.3359.181, webStorageEnabled: true}
Session ID: 21e9f50b6f254e92b4de001cda20bd24
at com.testing.AppTest.testGoogle(AppTest.java:33)

  System.setProperty("webdriver.chrome.driver", "path of chromedriver.exe");
	ChromeDriver driver = new ChromeDriver();
	driver.get("https://angularjs.org");
   	NgWebDriver ngWebDriver = new NgWebDriver(driver).withRootSelector("todoApp");
   	ByAngular.Factory baf = ngWebDriver.makeByAngularFactory();
    WebElement element = driver.findElement(baf.model("todoList.todoText"));
	element.sendKeys("Hello");

how can I find an element used repeater in repeater (Java)

Hi Paul,

I have one question about how to find an element repeater in repeater? below is the angular code, I'm trying to find the first element under month 2014-01(or a dynamic month ), so Only can I use the function like

driver.findElements(ng.repeater("order in orderListData['2014-01']").row(0))?

and sometime it even could not find this element.

So It there any dynamic way to solve this issue?

2014-01
Error Filled
2013-12
Cancelled

Thanks
Kent

waitForAngularRequestToFInish() does help and webdriver is ahead of angular request.

I am trying to write a simple test in webdriver for angular site. Beow is my code:
`@Test
public void testapp() {

    System.setProperty("webdriver.chrome.driver", "src/test/resources/drivers/chromedriver.exe");

    ChromeDriver driver = new ChromeDriver();
    driver.get("http://nvscmlind2:8080/indv301");
    new NgWebDriver(driver).waitForAngularRequestsToFinish();

    WebElements webElements = new WebElements(driver);
    webElements.filterIcon.click();
    new NgWebDriver(driver).waitForAngularRequestsToFinish();

    SeleniumUtils.selectByVisibleText(webElements.columnSelect, "Age");
    SeleniumUtils.selectByValue(webElements.filterSelect, ">");
    SeleniumUtils.sendKeysToInput("10", webElements.filterValue);
    webElements.applyButton.click();

}`

`private static class WebElements {
public WebElements(WebDriver driver) {
PageFactory.initElements(driver, this);
}

    @FindBy(xpath = "//app-data-grid")
    private WebElement dataGrid;

    @FindBy(xpath = "//app-customization//i[@class='ic-gear']")
    private WebElement gearIcon;

    @FindBy(className = "close-modal")
    private WebElement closeModal;

    @FindBy(className = "ic-filter")
    private WebElement filterIcon;

    @FindBy(xpath = "//app-modal-content//select[@formcontrolname='name']")
    private WebElement columnSelect;

    @FindBy(xpath = "//app-modal-content//select[@formcontrolname='op']")
    private WebElement filterSelect;

    @FindBy(xpath = "//app-modal-content//input")
    WebElement filterValue;

    @FindBy(xpath = "//app-modal-content//button[text()='Apply']")
    WebElement applyButton;
}`

when I execute the code I get below error:
org.openqa.selenium.NoSuchElementException: Cannot locate element with text: Age

Now when I implement the same test in protractor it works fine everytime.
describe('Protractor Demo App', function() { it('should have a title', function() { browser.get('http://nvscmlind2:8080/indv301'); element(by.css('.ic-filter')).click(); element(by.xpath('//app-modal-content//select[@formcontrolname="name"]')).element(by.cssContainingText('option', 'Age')).click(); element(by.xpath('//app-modal-content//select[@formcontrolname="op"]')).element(by.cssContainingText('option', 'Greater than')).click(); element(by.xpath('//app-modal-content//input')).sendKeys('10'); element(by.xpath('//app-modal-content//button[text()="Apply"]')).click(); //browser.driver.sleep(20000); }); });

Why does it not work?

Cannot read property '$$testability' of undefined

The bootstrapping of angular is done manually so there is no [ng-app] tag available in DOM . App tag is used in the application . I am attaching a html snippet for the same. As its an internal application , so I can't replicate it externally. I am getting the "testability" error
app

Let me know if you need additional details

getLocationAbsUrl(); not working after upgrade to 1.0

Hi,

After upgrading to 1.0, I find that getLocationAbsUrl(); yields the following below. Worked previously in 0.9.6. Did something break, or maybe the usage changed?

org.openqa.selenium.WebDriverException: unknown error: Cannot read property '$$testability' of undefined
(Session info: chrome=55.0.2883.87)
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
...
...
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Session ID: 9b7d0e1e-7ee0-4da2-938e-30fefc7052eb
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:537)
at com.paulhammant.ngwebdriver.NgWebDriver.getLocationAbsUrl(NgWebDriver.java:81)

Can NgWebDriver work with Selenium RemoteWebDriver?

Backgroud:

My testing automation is using selenium grid, so I initialize RemoteWebDriver instance every time when selenium starts to run. I also use CDI to inject each remote webdriver to page object, but I don't think it's matter for this question.

Question:

I am wondering if I can initialize ngWebDriver with the driver passed by RemoteWebDriver.

For example:
WebDriver lWebDriver = null;
lWebDriver = new RemoteWebDriver(new URL(GRID_HUB_URL), getWebDriverCapability());
...
new NgWebDriver(lWebDriver ).waitForAngularRequestsToFinish();

ng-binding

Hi Paul ,

i try to use your library but it's not working on ng-bind i am getting the error :
TypeError: getNg1Hooks(...) is undefined

when i try to find the element like that :
ngWebDriver = new NgWebDriver((JavascriptExecutor) driver);
ngWebDriver.waitForAngularRequestsToFinish();
WebElement firstname = driver.findElement(ByAngular.exactBinding("d.name"));

the element in the page look like that :

div class="" ng-show="analyticsDashboard.pageData.name"<
div id="dashboard-top" class="dashboard-print"<
ul class="nav nav-tabs"<

li class="active" ng-repeat="d in analyticsDashboard.pageData.dashboards" ng-class="{active:d.token == analyticsDashboard.dashboardName}"<
a ng-bind="d.name" ng-click="analyticsDashboard.changeDashboard(d)">Content Transfer</a<

thanks!

How to select from an md-select?

Hi guys,

I'm having trouble figuring out how to handle md-select elements. I can save the WebElement via model locator but when I try to select something (2nd two lines) the test halts with an error. Is there something else I need to use instead of using "Select" type that I had previously used for non-Angular pages?

Here's a snippet of my code:

WebElement test = driver.findElement(ByAngular.model("requestForProposal.RegionId"));
Select select1Selection = new Select(test); // <--- This fails
select1Selection.selectByVisibleText("North America"); <--- trying to select this value

Thanks!

Getting "at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:127) Caused by: org.openqa.selenium.WebDriverException: unknown error: Cannot read property '$$testability' of undefined" while using ByAngular.model and sendKeys to that

Getting below error when i try to use ByAngular.model("dataModel.emailAddress").sendKeys("emailId"):

cucumber.runtime.CucumberException: org.openqa.selenium.WebDriverException: unknown error: Cannot read property '$$testability' of undefined
(Session info: chrome=58.0.3029.81)
(Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 13 milliseconds
Build info: version: '3.3.1', revision: '5234b325d5', time: '2017-03-10 09:10:29 +0000'
System info: host: 'GASUBRA-IN-LE01', ip: '10.40.84.56', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_92'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.29.461591 (62ebf098771772160f391d75e589dc567915b233), userDataDir=C:\Users\gasubra\AppData\Local\Temp\scoped_dir7228_9892}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=58.0.3029.81, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: 06d05ef9e9ed9232f26fe26244984f59

at cucumber.api.testng.TestNGCucumberRunner.runCucumber(TestNGCucumberRunner.java:69)
at cucumber.api.testng.AbstractTestNGCucumberTests.feature(AbstractTestNGCucumberTests.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:127)

Caused by: org.openqa.selenium.WebDriverException: unknown error: Cannot read property '$$testability' of undefined
(Session info: chrome=58.0.3029.81)
(Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 13 milliseconds
Build info: version: '3.3.1', revision: '5234b325d5', time: '2017-03-10 09:10:29 +0000'
System info: host: 'GASUBRA-IN-LE01', ip: '10.40.84.56', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_92'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.29.461591 (62ebf098771772160f391d75e589dc567915b233), userDataDir=C:\Users\gasubra\AppData\Local\Temp\scoped_dir7228_9892}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=58.0.3029.81, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: 06d05ef9e9ed9232f26fe26244984f59
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:638)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:540)
at com.paulhammant.ngwebdriver.ByAngularModel.getObject(ByAngularModel.java:16)
at com.paulhammant.ngwebdriver.ByAngular$BaseBy.findElements(ByAngular.java:177)
at com.paulhammant.ngwebdriver.ByAngularModel.findElements(ByAngularModel.java:6)
at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:359)
at com.trimble.automation.framework.ui.internal.webobjects.FindActions$1.apply(FindActions.java:116)
at com.trimble.automation.framework.ui.internal.webobjects.FindActions$1.apply(FindActions.java:105)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:209)
at com.trimble.automation.framework.ui.internal.webobjects.FindActions.findElements(FindActions.java:126)
at com.trimble.automation.framework.ui.internal.webobjects.FindActions.findTextBox(FindActions.java:32)
at com.trimble.automation.framework.ui.internal.webobjects.Page.findTextBox(Page.java:13)
at com.trimble.connect.automation.script.webapp.pageobjects.home.projects.team.Team_Page_Objects.emailAddressTextBox(Team_Page_Objects.java:69)
at com.trimble.connect.automation.script.webapp.pageobjects.home.projects.team.Team_Page.inviteUsers(Team_Page.java:89)
at com.trimble.connect.automation.script.webapp.pageobjects.home.projects.team.Team_Page_Steps.inviteUsersToProject(Team_Page_Steps.java:35)
at โœฝ.And User invites user "[email protected]" for "Admin" to the Project(java/com/trimble/connect/automation/script/webapp/tests/team/InviteUsers.feature:10)

Any help is highly appreciated.

ngWebDriver with Javascript or node.js npm module?

Hi paul,
Thank you soo much for creating ngWebDriver, in my previous project we had an angularjs application, It worked out perfectly with JAVA based developers we just imported ngWebDriver to find elements.. but now more and more organization are moving towards node.js and javascript, ProtractorTest is there but as a testing framework its just not stable. i have been using nightwatch.js which is great for non-angular websites but for angular due to elements and angular animation i'm afraid i'll have to add plenty of waits.. Honestly i'm not sure how much effort it would be create javascript based APIs. Anyways. Thanks a lot!

ngdriver.waitForAngularRequestsToFinish();

@paul-hammant , Hi Paul
I am a new user of your tool :)
Hope this gives me great exposure towards my angular application automation in Java.
I got some doubts here:
ngdriver.waitForAngularRequestsToFinish(); , what does this statement do? and
2) if I would like to run my test in sauce labs .. do you have any separate capabilities for this library or its same as Selenium webdriver ?

please advise

TypeError: Cannot call method "get" of undefined

Got an exception when calling waitForAngularRequestsToFinish(driver):

org.openqa.selenium.WebDriverException: com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot call method "get" of undefined (injected script#1)
Build info: version: '2.37.1', revision: 'a7c61cbd68657e133ae96672cf995890bad2ee42', time: '2013-10-21 09:08:07'
System info: host: 'xxx', ip: 'xxx', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_25'
Driver info: driver.version: HtmlUnitDriver

waitForAngular2RequestsToFinish() is non-functional

The waitForAngular2RequestsToFinish code attempts to load waitForAllAngular2 client-side helper function, which is missing from protractor's cliendsidescripts.js

Was it an intention to implement dedicated Angular2-only wait functionality, or just a typo?

Need Help

Hi ,

i am new to ngWebDriver, i am trying run AngularAndWebDriverTest getting below error , can you please look in to it .

2017-08-09 16:26:11.022:INFO::main: Logging initialized @417ms to org.eclipse.jetty.util.log.StdErrLog
FAILED CONFIGURATION: @BeforeSuite before_suite
java.lang.IllegalStateException: Insufficient threads: max=6 < needed(acceptors=1 + selectors=8 + request=1)
at org.eclipse.jetty.server.Server.doStart(Server.java:414)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at com.paulhammant.ngwebdriver.AngularAndWebDriverTest.before_suite(AngularAndWebDriverTest.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:217)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:144)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:326)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
at org.testng.TestNG.runSuites(TestNG.java:1133)
at org.testng.TestNG.run(TestNG.java:1104)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)

SKIPPED CONFIGURATION: @BeforeMethod resetBrowser
SKIPPED: find_by_angular_model
java.lang.IllegalStateException: Insufficient threads: max=6 < needed(acceptors=1 + selectors=8 + request=1)
at org.eclipse.jetty.server.Server.doStart(Server.java:414)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at com.paulhammant.ngwebdriver.AngularAndWebDriverTest.before_suite(AngularAndWebDriverTest.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:217)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:144)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:326)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
at org.testng.TestNG.runSuites(TestNG.java:1133)
at org.testng.TestNG.run(TestNG.java:1104)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)

ByAngular.model throws an Exception "org.openqa.selenium.WebDriverException: ha.element(...).injector(...) is undefined"

Hi All,

As my site is developed using Angular Js and i need to get it automated so thought of using NgWebDriver as a choice and also to give an try once.
So i have written a small piece of code below to test one particular functionality but then when i run it opens the browser even hooks on with url.

The real issue is while interacting with model webelement it throws error like "org.openqa.selenium.WebDriverException: ha.element(...).injector(...) is undefined".

Can somebody shed some light on this issue and provide an solution. And plz let me know where i am going wrong.

Selenium version that iam using is : 2.53.1

public class Example1{

 public  FirefoxDriver driver;
 public  NgWebDriver ngWebDriver;

@BeforeSuite
public void before_suite() throws Exception {
driver = new FirefoxDriver();
driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
ngWebDriver = new NgWebDriver(driver);

}

  public void find_by_angular_model() throws Exception
   {

        driver.get("url");

        ngWebDriver.waitForAngularRequestsToFinish();

        Thread.sleep(2000);  //just used wait for time being.

        WebElement firstname = driver.findElement(ByAngular.buttonText("Create New SLI"));
         firstname.click();
        Thread.sleep(3000);        

       driver.findElement(ByAngular.model("SLI.prefFlightNumber1")).sendKeys("1111");
        Thread.sleep(2000);  
 }

}

Console Output

FAILED: find_by_angular_model
org.openqa.selenium.WebDriverException: ha.element(...).injector(...) is undefined
Command duration or timeout: 20 milliseconds
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
System info: host: 'PDCHP64-VM10085', ip: '10.27.23.235', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_101'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=47.0.1, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: f498255c-969a-482a-88eb-9b7188df6541
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:577)
at com.paulhammant.ngwebdriver.ByAngularModel.getObject(ByAngularModel.java:16)
at com.paulhammant.ngwebdriver.ByAngular$BaseBy.findElement(ByAngular.java:170)
at com.paulhammant.ngwebdriver.ByAngularModel.findElement(ByAngularModel.java:6)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355)
at com.paulhammant.ngwebdriver.AngularAndWebDriverTest.find_by_angular_model(AngularAndWebDriverTest.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflec

NullPointerException when using angular repeater with HtmlUnitDriver

When using the ngWebDriver with the HtmlUnitDriver (Selenium's headless browser driver), I have not been able to successfully use the angular repeater. The following code will lead to a NullPointerException:

String ANGULAR_REPEATER = "some angular repeater";
WebDriver driver = new HtmlUnitDriver(true);
ngWebDriver = new NgWebDriver((JavascriptExecutor) driver);
driver.get(URL);
WebElement element = driver.findElement(ByAngular.repeater(ANGULAR_REPEATER).row(0));

Apparently, the reason is that for the vararg in
public Object executeScript(String script, final Object... args)
in HtmlUnitDriver, ngWebdriver sends a single null-Argument that later causes a null-PointerException.

I assume the simple solution would be to simply call the method with no arguments, thus preventing the NullPointerException, but maybe there is a reason for sending this null-argument?

I would also be happy to learn about a workaround that lets me use the angular repeater with HtmlUnitDriver until the issue is solved.

Issue on Set script timeout

Hi Paul,

Good Morning! hoping that you are doing great !

it was noticed that, when i mentioned setScriptTimeOut statement in tests, during first page loading , it was waiting blindly for sometime even after page load completes and element is ready to perform actions.

Can i turn off setScripttimeout statement since it needs only to ececuteAsyncScripts. or is it mandate to define this in order to use ngWebdriverLocators since these locators calls JSExecutor in backend per my understanding of your framework design ?

i am actually using webDriverwaits and i am good with that, is there any conflict of usage among these two (both scripttimeout and webdriverwait)?

Kindly , please give me your insight onthis.

thanks,
Pavan

ngWebDriver showing unexpected exceptions

Hi,
*When i am using ngWebDriver at ng -model we are getting this error "org.openqa.selenium.WebDriverException: unknown error: Cannot read property '$$testability' of undefined". Why these error showing i dont know.

*But when we are using Web Driver it working fine.

*I am sharing my code for reference purpose. Could u please check it

Code::

package angularJS;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.paulhammant.ngwebdriver.ByAngular;
import com.paulhammant.ngwebdriver.NgWebDriver;

public class Test1 {
public static WebDriver driver ;
public static NgWebDriver ngdriver;

@BeforeClass
public static void open()
{
	System.setProperty("webdriver.chrome.driver", ".\\Drivers\\chromedriver.exe");
	driver = new ChromeDriver();
	driver.manage().window().maximize();
	driver.get("https://angularjs.org/");	
}
@Test
public static void get_Message()
{
	ngdriver = new NgWebDriver((JavascriptExecutor) driver);
	ngdriver.waitForAngularRequestsToFinish();
	WebElement element = driver.findElement(ByAngular.model("yourName"));//.sendKeys("Data Name");
	element.sendKeys("venkat hi");
	String actual = driver.findElement(By.xpath("//h1[@class='ng-binding']")).getText();
	System.out.println("The name is "+actual);
}

}

Error:
org.openqa.selenium.WebDriverException: unknown error: Cannot read property '$$testability' of undefined
(Session info: chrome=62.0.3202.89)
(Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.1.7600 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds

0.9.4: java.io.FileNotFoundException: src/main/resources/js/clientsidescripts.js

I get the following with 0.9.4:

Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: src/main/resources/js/clientsidescripts.js (No such file or directory)
        at com.paulhammant.ngwebdriver.AngularJavaScriptFunctions.<clinit>(AngularJavaScriptFunctions.java:26)
        ... 106 more
Caused by: java.io.FileNotFoundException: src/main/resources/js/clientsidescripts.js (No such file or directory)
        at java.io.FileInputStream.open0(Native Method)
        at java.io.FileInputStream.open(FileInputStream.java:195)
        at java.io.FileInputStream.<init>(FileInputStream.java:138)
        at com.paulhammant.ngwebdriver.AngularJavaScriptFunctions.<clinit>(AngularJavaScriptFunctions.java:24)
        ... 106 more
Tests failed.
$ atool -l ngwebdriver-0.9.4.jar |grep -i clientsidescripts.js
    23855  11-29-15 13:47   js/clientsidescripts.js

InputStream resourceAsStream = ByAngular.class.getResourceAsStream("js/clientsidescripts.js");
if (resourceAsStream == null) {
try {
// In ngWebDriver's own build (fallback)
resourceAsStream = new FileInputStream(new File("src/main/resources/js/clientsidescripts.js"));

Get Button in repeater

Hi

i want to click on a button within a repeater. HTML looks like

<tr ng-repeat="element in elements">
    <td>{{element.value1}}</td>
    <td>{{element.value2}}</td>
    <td>
        <button class="btn btn-green" type="button" data-toggle="modal" ng-click="element.function">
        </button>
    </td>
</tr>

How can i get the Button Element?

How to Automate gaphs

Hi,

Give me some suggestion/pseudo code to Automate the graphs using ng Webdriver (my UI is built on Angular JS)

Execute scope function

Hi

i try to execute a scope function in my test class. On my GUI there is a link
<a data-target="#" ng-click="logout()">logout</a>

How can I execute the logout function within my test class? Thats not work, but something like this?
driver.findElement(ByAngular.model("logout")).click();

package com.paulhammant.ngwebdriver does not exist

Hi, I am using Maven getting the compile error for ngWebDriver.

Here i am using these versions :

Selenium-WebDriver (3.4)
Java (1.8.0.31)
Ng-Webdriver (1.1)

Error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.
3:compile (default-compile) on project Pratice-Template: Compilation failure: Compi
lation failure:
[ERROR] /D:/Git_Merge/src/main/java/utils/Utils.java:[93,35] package com.paulham
mant.ngwebdriver does not exist

Support for Angular 2

Hi,

I'm currently investigating supporting Angular 2 applications, we use your library to currently, but there doesn't seem to be any support for Angular 2?

I've seen that there's client side js 'waitForAllAngular2' which is the async call to wait for the Angular 2 JS page to construct, but there's no method in the class NgWebDriver to support it.

Would it be possible to gain support for Angular 2?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.