2017-09-08 06:57:33 -04:00
|
|
|
import { browser, element, by, promise, ElementFinder, ExpectedConditions } from 'protractor';
|
2017-03-17 19:02:03 -04:00
|
|
|
|
|
|
|
const githubRegex = /https:\/\/github.com\/angular\/angular\//;
|
2017-01-27 03:20:51 -05:00
|
|
|
|
|
|
|
export class SitePage {
|
2017-05-15 17:52:39 -04:00
|
|
|
|
2017-02-07 15:57:18 -05:00
|
|
|
links = element.all(by.css('md-toolbar a'));
|
2017-11-14 20:01:00 -05:00
|
|
|
homeLink = element(by.css('a.home'));
|
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-05-15 17:52:39 -04:00
|
|
|
|
|
|
|
static setWindowWidth(newWidth: number) {
|
|
|
|
const win = browser.driver.manage().window();
|
|
|
|
return win.getSize().then(oldSize => win.setSize(newWidth, oldSize.height));
|
|
|
|
}
|
|
|
|
|
2017-03-29 17:13:40 -04:00
|
|
|
getNavItem(pattern: RegExp) {
|
2017-05-15 17:52:39 -04:00
|
|
|
return element.all(by.css('aio-nav-item .vertical-menu-item'))
|
2017-03-21 03:02:58 -04:00
|
|
|
.filter(element => element.getText().then(text => pattern.test(text)))
|
|
|
|
.first();
|
|
|
|
}
|
2017-11-02 15:40:14 -04:00
|
|
|
getTopMenuLink(path) { return element(by.css(`aio-top-menu a[href="${path}"]`)); }
|
2017-10-19 08:58:27 -04:00
|
|
|
ga() { return browser.executeScript('return window["ga"].q') as promise.Promise<any[][]>; }
|
2017-03-21 03:02:58 -04:00
|
|
|
locationPath() { return browser.executeScript('return document.location.pathname') as promise.Promise<string>; }
|
2017-02-02 15:10:47 -05:00
|
|
|
|
2017-11-13 15:56:01 -05:00
|
|
|
navigateTo(pageUrl) {
|
2017-12-12 08:26:03 -05:00
|
|
|
// Navigate to the page, disable animations, and wait for Angular.
|
|
|
|
return browser.get('/' + pageUrl)
|
|
|
|
.then(() => browser.executeScript('document.body.classList.add(\'no-animations\')'))
|
|
|
|
.then(() => browser.waitForAngular());
|
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-06-01 17:03:10 -04:00
|
|
|
getScrollTop() {
|
|
|
|
return browser.executeScript('return window.pageYOffset');
|
|
|
|
}
|
|
|
|
|
|
|
|
scrollToBottom() {
|
|
|
|
return browser.executeScript('window.scrollTo(0, document.body.scrollHeight)');
|
|
|
|
}
|
|
|
|
|
2017-09-08 06:57:33 -04:00
|
|
|
enterSearch(query: string) {
|
2017-09-09 13:15:46 -04:00
|
|
|
const input = element(by.css('.search-container input[type=search]'));
|
|
|
|
input.clear();
|
|
|
|
input.sendKeys(query);
|
2017-09-08 06:57:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
getSearchResults() {
|
|
|
|
const results = element.all(by.css('.search-results li'));
|
|
|
|
browser.wait(ExpectedConditions.presenceOf(results.first()), 8000);
|
2018-01-10 05:41:15 -05:00
|
|
|
return results.map(link => link && link.getText());
|
2017-09-08 06:57:33 -04:00
|
|
|
}
|
2017-01-27 03:20:51 -05:00
|
|
|
}
|