switch(process.env.__NIGHTWATCH_ENV_KEY): {
case 'chrome_1':
//steps for browser1
case 'chrome_2':
//steps for browser2
}#!/bin/bash
# lock-session.sh
CREATE=false
REMOVE=false
while getopts ":crt:l:w:" opt; do
case ${opt} in
c )
CREATE=true
;;
r ) # process option t
REMOVE=true
;;
t )
MAXTRIES=$OPTARG
;;
l )
LOCKFILE=$OPTARG
;;
w )
FILETEXT=$OPTARG
;;
\? ) echo "Usage: cmd [-c] [-r] [-t tries] [-l lockfile] [-w text in file]"
;;
esac
done
if [ -z $LOCKFILE ]; then
LOCKFILE=tests/testfiles/autotestlock.txt
fi
if [ -z $FILETEXT ]; then
FILETEXT=`date`
fi
if [ $CREATE = true ]; then
if [ -e $LOCKFILE ]; then
echo "A session already has lock on ${LOCKFILE}. Waiting ..."
i=1
if [ -z $MAXTRIES ]; then
echo "Defaulting to 40 tries."
MAXTRIES=40
fi
while [ -e $LOCKFILE ] && [ $i -lt $MAXTRIES ]
do
echo "Waiting for ${LOCKFILE} to free up. ${i} of ${MAXTRIES}"
((i++))
sleep 5
done
if [ -e $LOCKFILE ]; then
echo "Timed out waiting for ${LOCKFILE}"
exit 1
else
echo "${LOCKFILE} free after ${i} tries. Creating now"
echo $FILETEXT > $LOCKFILE
fi
else
echo "Creating lock file: ${LOCKFILE}"
echo $FILETEXT > $LOCKFILE
fi
elif [ $REMOVE = true ]; then
echo "Removing lock file: ${LOCKFILE}"
rm -f $LOCKFILE
fi
/**
* lockSession - Handles session lock management for multi-user tests
* @param {object} lock
* @param {boolean} lock.establish - true = establish lock, false = free up lock
* @param {text} lock.text - text to write to log file (for debugging)
* @param {boolean} [lock.skipPause=false] - will pause after freeing up lock file unless skipPause = true
* @param {number} [lock.seconds=250] - How long to wait for lock before error
*/
exports.command = function(lock) {
var waitIterations = (lock.seconds > 0) ? Math.floor(lock.seconds / 5) : 30;
var fileTextSwitch = (lock.text) ? ` -w ${lock.text}` : '';
if (lock.establish === true) {
// Establishing a lock. Will wait to get it
this
.executeShellCommand(`./tests/scripts/lock-session.sh -c -t ${waitIterations} ${fileTextSwitch}`, "Error establishing session lock")
.consoleLog('Lock created')
} else {
// Removing lock
this
.executeShellCommand("./tests/scripts/lock-session.sh -r", "Error removing session lock")
.consoleLog('Lock removed')
//Pause to give other side a chance to grab the lock. Can skip for cleanup at beginning, end.
if (lock.skipPause === undefined || lock.skipPause === false) {
this
.consoleLog('Pausing after removing lock so other side can get lock')
.pause(this.globals.defaultLongPause)
}
}
return this;
};
And then make calls to lockSession as appropriate in your test script:
var primaryUser = (process.env.__NIGHTWATCH_ENV_KEY === `${process.env.__NIGHTWATCH_ENV}_1` || process.env.__NIGHTWATCH_ENV_KEY === undefined)
module.exports = {
"Step 1": browser => {
if (primaryUser) {
browser
// Remove lock to start test
.lockSession({establish: false, skipPause: true})
.lockSession({establish: true, text: 'primary', seconds: 120})
<DO YOUR TEST STEPS FOR primaryClient>
// Free up lock
.lockSession({establish: false})
} else {
// Pause so secondUser does not grab lock first
browser
.pause(browser.globals.defaultLongPause)
// My turn for lock
.lockSession({establish: true, text: 'secondary', seconds: 200})
<DO YOUR TEST STEPS for secondUser>
// Free up lock
.lockSession({establish: false})
}
},
--
You received this message because you are subscribed to the Google Groups "NightwatchJs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nightwatchjs...@googlegroups.com.
To post to this group, send email to nightw...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nightwatchjs/ff634fb7-e9a9-4a2d-b5be-0189ac3d8d63%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
![]() | Mark Liberman Software Engineer - Test Automation |
Given I am running a multi-user test with users "User A, User B"
When I am in User A's browser
And I log in as "admin@mywebapp.com"
And I create an account for "us...@mywebapp.com"
Then the account list shows an active account for "us...@somesite.com"
When I am in User B's browser
And I log in as "us...@somesite.com"
Then the message "Welcome to your account!" appears
When I am in User B's browser
And I disable the account for "us...@mywebapp.com"
And I create an account for "us...@somesite.com"Then the account list shows an account for "us...@somesite.com"
Then the account list shows a disabled account for "us...@somesite.com"
When I am in User B's browser
Then a dialog appears with the warning "Someone has disabled your account. You will be redirected to the login screen."
When I wait for the warning dialog to go away
Then the login page is shown