Skip to content

Instantly share code, notes, and snippets.

@demisx
Last active September 27, 2020 00:03
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save demisx/9469616 to your computer and use it in GitHub Desktop.
Save demisx/9469616 to your computer and use it in GitHub Desktop.
Protractor e2e Cheatsheet (CoffeeScript)
browser.get "/phones" # navigate to /phones URL
input.clear() # clear text input field
expect(browser.getTitle()).toMatch 'My Google Photo Gallery'
expect(browser.getCurrentUrl()).toMatch "/phones$"
# Find by...
# --------------
# ... by CSS id or class
expect(element(By.id("svapp-previous-slide-link")).getText()).toBe "Previous"
expect(element(By.id("svapp-current-slide-image")).getAttribute('src')).toMatch /\/data\/presentations\/1\/images\/Slide1.JPGX/
expect(element(By.css(".svapp-current-slide")).getText()).toBe "My Slide"
# ... element with {{scopeVar}} syntax.
element(By.binding("person.name")).getText().then (name) ->
expect(name).toBe "Foo"
return
# ... element with ng-bind="scopeVar" syntax.
expect(element(By.binding("person.email")).getText()).toBe "foo@bar.com"
# ... by model
input = element(By.model("person.name"))
input.sendKeys "123"
expect(input.getAttribute("value")).toBe "Foo123"
expect(element(By.binding("person.email")).getText()).toBe "foo@bar.com"
# ... by repeater
expect(element.all(By.repeater("phone in phones")).count()).toBe 8
expect(element.all(By.repeater("phone in phones").column("phone.name")).first().getText()).toBe "Motorola XOOM"
# Select option in dropdown list
# -----------------------------
<select ng-model="orderProp">
<option value="name">Alphabetical</option>
<option value="age">Newest</option>
</select>
element(By.model('orderProp')).$('[value="age"]').click()
# Check image is present
expect(element(By.id('recaptcha_image')).isPresent()).toBe(true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment