2017-03-17 19:02:03 -04:00
|
|
|
import { browser, element, by, promise, ElementFinder } from 'protractor';
|
|
|
|
|
|
|
|
const githubRegex = /https:\/\/github.com\/angular\/angular\//;
|
2017-01-27 03:20:51 -05:00
|
|
|
|
|
|
|
export class SitePage {
|
2017-02-07 15:57:18 -05:00
|
|
|
links = element.all(by.css('md-toolbar a'));
|
2017-03-29 17:13:40 -04:00
|
|
|
docsMenuLink = element(by.cssContainingText('aio-top-menu a', 'Docs'));
|
2017-02-07 15:57:18 -05:00
|
|
|
docViewer = element(by.css('aio-doc-viewer'));
|
2017-02-09 14:58:36 -05:00
|
|
|
codeExample = element.all(by.css('aio-doc-viewer pre > code'));
|
2017-03-17 19:02:03 -04:00
|
|
|
ghLink = this.docViewer
|
|
|
|
.all(by.css('a'))
|
|
|
|
.filter((a: ElementFinder) => a.getAttribute('href').then(href => githubRegex.test(href)))
|
|
|
|
.first();
|
2017-03-13 21:08:23 -04:00
|
|
|
gaReady: promise.Promise<any>;
|
2017-03-29 17:13:40 -04:00
|
|
|
getNavItem(pattern: RegExp) {
|
2017-03-21 03:02:58 -04:00
|
|
|
return element.all(by.css('aio-nav-item a'))
|
|
|
|
.filter(element => element.getText().then(text => pattern.test(text)))
|
|
|
|
.first();
|
|
|
|
}
|
|
|
|
getLink(path) { return element(by.css(`a[href="${path}"]`)); }
|
|
|
|
ga() { return browser.executeScript('return window["gaCalls"]') as promise.Promise<any[][]>; }
|
|
|
|
locationPath() { return browser.executeScript('return document.location.pathname') as promise.Promise<string>; }
|
2017-02-02 15:10:47 -05:00
|
|
|
|
2017-03-17 19:02:03 -04:00
|
|
|
navigateTo(pageUrl = '') {
|
|
|
|
return browser.get('/' + pageUrl).then(_ => this.replaceGa(_));
|
2017-01-27 03:20:51 -05:00
|
|
|
}
|
|
|
|
|
2017-02-02 15:10:47 -05:00
|
|
|
getDocViewerText() {
|
2017-02-07 15:57:18 -05:00
|
|
|
return this.docViewer.getText();
|
2017-01-27 03:20:51 -05:00
|
|
|
}
|
2017-02-07 15:57:18 -05:00
|
|
|
|
2017-03-22 16:24:40 -04:00
|
|
|
getInnerHtml(element) {
|
|
|
|
// `getInnerHtml` was removed from webDriver and this is the workaround.
|
|
|
|
// See https://github.com/angular/protractor/blob/master/CHANGELOG.md#breaking-changes
|
|
|
|
return browser.executeScript('return arguments[0].innerHTML;', element);
|
|
|
|
}
|
|
|
|
|
2017-03-13 21:08:23 -04:00
|
|
|
/**
|
|
|
|
* Replace the ambient Google Analytics tracker with homebrew spy
|
|
|
|
* don't send commands to GA during e2e testing!
|
|
|
|
* @param _ - forward's anything passed in
|
|
|
|
*/
|
|
|
|
private replaceGa(_: any) {
|
|
|
|
|
|
|
|
this.gaReady = browser.driver.executeScript(() => {
|
|
|
|
// Give ga() a "ready" callback:
|
|
|
|
// https://developers.google.com/analytics/devguides/collection/analyticsjs/command-queue-reference
|
|
|
|
window['ga'](() => {
|
|
|
|
window['gaCalls'] = [];
|
|
|
|
window['ga'] = function() { window['gaCalls'].push(arguments); };
|
|
|
|
});
|
|
|
|
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
// wait for GaService to start using window.ga after analytics lib loads.
|
|
|
|
const d = promise.defer();
|
|
|
|
setTimeout(() => d.fulfill(), 1000); // GaService.initializeDelay
|
|
|
|
return d.promise;
|
|
|
|
});
|
|
|
|
|
|
|
|
return _;
|
|
|
|
}
|
2017-01-27 03:20:51 -05:00
|
|
|
}
|
2017-03-13 21:08:23 -04:00
|
|
|
|