2017-01-18 23:13:48 +01:00
|
|
|
import {ElementFinder, by, element, ProtractorBy, browser} from 'protractor';
|
2017-05-15 23:28:30 +02:00
|
|
|
import {Point} from './actions';
|
2017-01-18 23:13:48 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Normalizes either turning a selector into an
|
|
|
|
|
* ElementFinder or returning the finder itself.
|
|
|
|
|
*/
|
|
|
|
|
export function getElement(el: FinderResult): ElementFinder {
|
|
|
|
|
return typeof el === 'string' ? element(by.css(el)) : el;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Waits for an element to be rendered.
|
|
|
|
|
*/
|
|
|
|
|
export function waitForElement(selector: string) {
|
|
|
|
|
return browser.isElementPresent(by.css(selector) as ProtractorBy);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-15 23:28:30 +02:00
|
|
|
/**
|
|
|
|
|
* Determines the current scroll position of the page.
|
|
|
|
|
*/
|
|
|
|
|
export async function getScrollPosition(): Promise<Point> {
|
|
|
|
|
const snippet = `
|
|
|
|
|
var documentRect = document.documentElement.getBoundingClientRect();
|
|
|
|
|
var x = -documentRect.left || document.body.scrollLeft || window.scrollX ||
|
|
|
|
|
document.documentElement.scrollLeft || 0;
|
|
|
|
|
var y = -documentRect.top || document.body.scrollTop || window.scrollY ||
|
|
|
|
|
document.documentElement.scrollTop || 0;
|
|
|
|
|
|
|
|
|
|
return {x: x, y: y};
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
return await browser.executeScript<Point>(snippet);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-18 23:13:48 +01:00
|
|
|
export type FinderResult = ElementFinder | string;
|