Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dherges
Created August 4, 2017 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dherges/8e98ac9925d38f2ab1442b862a562fdf to your computer and use it in GitHub Desktop.
Save dherges/8e98ac9925d38f2ab1442b862a562fdf to your computer and use it in GitHub Desktop.
Angular, Protractor, Cucumber
import { browser, by, element, until } from 'protractor';
export class AppPage {
public navigateTo() {
return browser.get('/');
}
public enterSearchInput(text: string) {
return element(by.css('input[aria-label="search"]'))
.sendKeys(text);
}
public getSearchResultItems() {
const condition = until.elementsLocated(by.css('.search-results .search-result-item'));
return browser.wait(condition, 5000);
}
}
import { expect } from 'chai';
import { defineSupportCode } from 'cucumber';
import { AppPage } from './app.po';
defineSupportCode(({Given, When, Then, Before}) => {
let app: AppPage;
Before(() => {
app = new AppPage();
});
Given('I am on the angular.io site',
() => app.navigateTo());
When('I type "{term}" into the search input field',
(text: string) => app.enterSearchInput(text));
Then('I should see some results in the search overlay',
() => app.getSearchResultItems()
.then(elems => expect(elems.length).to.be.greaterThan(0)));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment