Skip to content

Instantly share code, notes, and snippets.

@cvakiitho
Forked from javierarques/protractorAPICheatsheet.md
Last active August 20, 2021 00:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cvakiitho/55cae3cd31d20c85a1fc6f4c0ba277dc to your computer and use it in GitHub Desktop.
Save cvakiitho/55cae3cd31d20c85a1fc6f4c0ba277dc to your computer and use it in GitHub Desktop.
UIVeri5 API Cheatsheet

UIVeri5 API cheatsheet

it uses protractor beneath, so this is a good resource: http://angular.github.io/protractor/#/api

Notes:

  • Most commands return promises, so you only resolve their values through using jasmine expect API or using .then(function()) structure.

  • Promises are resolved by WebdriverJS promise manager . If you want to schedule non-api made promise into the chain, you have to use one of:

    • .then(function(){ <your non-api code> })
    • browser.wait()
    • browser.controlFlow().execute(<promise>)

Based on this post: https://spagettikoodi.wordpress.com/2015/01/14/angular-testing-cheat-sheet/ by @crystoll

Control browser

browser.testrunner.navigation.to('https://XXXXXXXX/', {auth:'plain'}); // Load address, can also use '#yourpage'

browser.sleep(10000); // if your test is outrunning the browser

browser.getLocationAbsUrl() // get the current address

browser.ignoreSynchronization = true; // If true, uiveri5 will not attempt to synchronize with the page before performing actions - make cause wonky behaviour in further tests.

   

Here's a trick how to wait for something to become present/visible:

browser.wait(function() {
   return element(by.id('create')).isPresent();
}, 5000);
   
element(by.id('create')).click();

Check visibility

element(by.id('create')).isPresent() // Be careful with this: element is often present while it's not displayed...

element(by.id('create')).isEnabled() //Enabled/disabled, as in ng-disabled...

element(by.id('create')).isDisplayed() //Is element currently visible/displayed?

Find an element by id, model, binding, ...

element(by.id('user_name'))

element(by.css('#myItem'))

element(by.control({id: "testID"}); // details: https://github.com/SAP/ui5-uiveri5/blob/master/docs/usage/locators.md#control-locators 

element(by.textarea('person.extraDetails'));

element (by.input( 'username' ));

element (by.input( 'username' )).clear();

element(by.buttonText('Save'));

element(by.partialButtonText('Save'));

element(by.linkText('Save'));

element(by.partialLinkText('Save'));

element(by.css('.class="cssclass"]')); 

var dog = element(by.cssContainingText('.pet', 'Dog'));

Find collection of elements by css, repeater, xpath..

var list = element.all(by.css('.items));

var list3 = element.all(by.xpath('//div

expect(list.count()).toBe(3);

expect(list.get(0).getText()).toBe('First’)

expect(list.get(1).getText()).toBe('Second’)

expect(list.first().getText()).toBe('First’)

expect(list.last().getText()).toBe('Last’)

Send keystrokes, clear

element(by.id('user_name').sendKeys("user1");

sendKeys(protractor.Key.ENTER);

sendKeys(protractor.Key.TAB);

element(by.id('user_name')).clear()

Position and size, also how to deal with promises:

element(by.id('item1')).getLocation().then(function(location) {
  var x = location.x;
  var y = location.y;
});

element(by.id('item1')).getSize().then(function(size) {
  var width = size.width;
  var height = size.height;
});

Jasmine Matchers

to(N­ot)­Be( null | true | false )
to(N­ot)­Equ­al( value )
to(N­ot)­Mat­ch( regex | string )
toBe­Def­ine­d()
toBe­Und­efi­ned()
toBe­Nul­l()
toBe­Tru­thy()
toBe­Fal­sy()
to(N­ot)­Con­tain( string )
toBe­Les­sTh­an( number )
toBe­Gre­ate­rTh­an( number )
toBe­NaN()
toBe­Clo­seTo( number, precision )
toTh­row()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment