11/*
2- * Helper functions for the tests in `../visreg/` and `../functional/` .
2+ * Helper functions for the tests in `../visreg/`.
33 */
4- import { By , ISize , WebDriver , WebElement , WebElementPromise } from "selenium-webdriver " ;
4+ import { By , ISize , WebDriver , WebElement , WebElementPromise } from "snappit-visual-regression " ;
55import { TestContext } from "ava" ;
66
77export const baseUrl = "http://localhost:3000/helix-ui" ;
88
99export async function go ( driver : WebDriver , component : string ) {
10- await driver . get ( `${ baseUrl } /components/ ${ component } ` ) ;
10+ await driver . get ( `${ baseUrl } /${ component } ` ) ;
1111}
1212
13- export async function snapshot ( t : TestContext , element : WebElement ) {
14- t . snapshot ( await element . getAttribute ( "outerHTML" ) ) ;
13+ export async function sleep ( ms = 1500 ) {
14+ return new Promise ( ( resolve , reject ) => {
15+ setTimeout ( resolve , ms ) ;
16+ } ) ;
1517}
1618
17- export async function setViewportSize (
18- driver : WebDriver ,
19- size : ISize ,
20- ) {
21- const jsGetPadding : string = `return {
22- width: window.outerWidth - window.innerWidth,
23- height: window.outerHeight - window.innerHeight
24- }` ;
25-
26- const padding : ISize = await driver . executeScript ( jsGetPadding ) as ISize ;
27- return driver . manage ( ) . window ( ) . setSize (
28- size . width + padding . width ,
29- size . height + padding . height ,
30- ) ;
19+ export async function snapshot ( t : TestContext , element : WebElement ) {
20+ if ( process . env . TRAVIS ) {
21+ const ready = async ( ) => ( await element . getDriver ( ) . executeScript ( "return window.WebComponents.ready" ) ) as boolean ;
22+ while ( ! ( await ready ( ) ) ) {
23+ await sleep ( 100 ) ;
24+ }
25+ }
26+
27+ t . snapshot ( await element . getAttribute ( "outerHTML" ) ) ;
3128}
3229
3330export function $x (
@@ -44,7 +41,7 @@ export function $x(
4441
4542/* A "starter page object" until there's a greater need for something more robust.
4643 * For now this only contains common CSS selectors used throughout tests in the
47- * visreg/functional directories , but may also contain functions in the future.
44+ * visreg directory , but may also contain functions in the future.
4845 *
4946 * Once that happens, pull this out of `util.ts` and move it someplace more page-object-y.
5047 */
0 commit comments