Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Try Jetpack Tests with No Promise Manager #1294

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 16 additions & 62 deletions lib/driver-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,9 @@ import * as dataHelper from './data-helper';
const explicitWaitMS = config.get( 'explicitWaitMS' );
const by = webdriver.By;

export function highlightElement( driver, selector, waitOverride ) {
if ( config.has( 'highlightElements' ) && config.get( 'highlightElements' ) ) {
const timeoutWait = waitOverride ? waitOverride : explicitWaitMS;

function setStyle( element, style ) {
const previous = element.getAttribute( 'style' );
element.setAttribute( 'style', style );
setTimeout( () => {
element.setAttribute( 'style', previous );
}, 200 );
return 'highlighted';
}

let theElement = driver.findElement( selector );
return driver.wait(
function() {
return driver.executeScript(
setStyle,
theElement,
'color: red; background-color: yellow;'
);
},
timeoutWait,
'Timed out waiting for element to be Highlighted'
);
}
}

export function clickWhenClickable( driver, selector, waitOverride ) {
const timeoutWait = waitOverride ? waitOverride : explicitWaitMS;

this.highlightElement( driver, selector, waitOverride );
return driver.wait(
function() {
return driver.findElement( selector ).then(
Expand Down Expand Up @@ -205,7 +176,7 @@ export function elementIsNotPresent( driver, cssSelector ) {
} );
}

export function waitForFieldClearable( driver, selector ) {
export async function waitForFieldClearable( driver, selector ) {
return driver.wait(
function() {
return driver.findElement( selector ).then(
Expand Down Expand Up @@ -233,45 +204,28 @@ export function waitForFieldClearable( driver, selector ) {
);
}

export function setWhenSettable(
export async function setWhenSettable(
driver,
selector,
value,
{ secureValue = false, pauseBetweenKeysMS = 0, assumeSuccess = false } = {}
{ secureValue = false, pauseBetweenKeysMS = 0 } = {}
) {
const self = this;
const logValue = secureValue === true ? '*********' : value;
let self = this;
return driver.wait(
function() {
return driver.findElement( selector ).then(
async function( element ) {
await self.waitForFieldClearable( driver, selector );
if ( pauseBetweenKeysMS === 0 ) {
await element.sendKeys( value );
} else {
for ( let i = 0; i < value.length; i++ ) {
driver.sleep( pauseBetweenKeysMS ).then( () => {
element.sendKeys( value[ i ] );
} );
}
}

return (
assumeSuccess ||
element.getAttribute( 'value' ).then(
actualValue => {
return actualValue === value;
},
function() {
return false;
}
)
);
},
function() {
return false;
async function() {
await self.waitForFieldClearable( driver, selector );
const element = await driver.findElement( selector );
if ( pauseBetweenKeysMS === 0 ) {
await element.sendKeys( value );
} else {
for ( let i = 0; i < value.length; i++ ) {
await driver.sleep( pauseBetweenKeysMS );
await element.sendKeys( value[ i ] );
}
);
}
const actualValue = await element.getAttribute( 'value' );
return actualValue === value;
},
explicitWaitMS,
`Timed out waiting for element with ${ selector.using } of '${
Expand Down
3 changes: 3 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ RETURN=0
CLEAN=0
GREP=""

#disable selenium promise manager
export SELENIUM_PROMISE_MANAGER=0

# Warn if NODE_ENV variable is not set
if [ "$NODE_ENV" = "" ]; then
echo "WARNING: NODE_ENV environment variable is not set."
Expand Down
2 changes: 1 addition & 1 deletion scripts/run-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if [ "$NODE_ENV_OVERRIDE" != "" ]; then
fi

#disable selenium promise manager
#export SELENIUM_PROMISE_MANAGER=0
export SELENIUM_PROMISE_MANAGER=0

export TESTARGS="-R -p"

Expand Down