Add support for multiple sessions in a browser
Fixes gh-49
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
package sample
|
||||
|
||||
import geb.spock.*
|
||||
import sample.pages.HomePage;
|
||||
import sample.pages.LinkPage;
|
||||
import spock.lang.Stepwise
|
||||
import pages.*
|
||||
|
||||
/**
|
||||
* Tests the demo that supports multiple sessions
|
||||
*
|
||||
* @author Rob Winch
|
||||
*/
|
||||
@Stepwise
|
||||
class UserTests extends GebReportingSpec {
|
||||
def 'first visit not authenticated'() {
|
||||
when:
|
||||
to HomePage
|
||||
then:
|
||||
form
|
||||
!username
|
||||
}
|
||||
|
||||
def 'login single user'() {
|
||||
setup:
|
||||
def user = 'rob'
|
||||
when:
|
||||
login(user, user)
|
||||
then:
|
||||
username == user
|
||||
}
|
||||
|
||||
def 'add account'() {
|
||||
when:
|
||||
addAccount.click(HomePage)
|
||||
then:
|
||||
form
|
||||
!username
|
||||
}
|
||||
|
||||
def 'log in second user'() {
|
||||
setup:
|
||||
def user = 'luke'
|
||||
when:
|
||||
login(user, user)
|
||||
then:
|
||||
username == user
|
||||
}
|
||||
|
||||
def 'following links keeps new session'() {
|
||||
when:
|
||||
navLink.click(LinkPage)
|
||||
then:
|
||||
username == 'luke'
|
||||
}
|
||||
|
||||
def 'switch account rob'() {
|
||||
setup:
|
||||
def user = 'rob'
|
||||
when:
|
||||
switchAccount(user)
|
||||
then:
|
||||
username == user
|
||||
}
|
||||
|
||||
def 'following links keeps original session'() {
|
||||
when:
|
||||
navLink.click(LinkPage)
|
||||
then:
|
||||
username == 'rob'
|
||||
}
|
||||
|
||||
def 'switch account luke'() {
|
||||
setup:
|
||||
def user = 'luke'
|
||||
when:
|
||||
switchAccount(user)
|
||||
then:
|
||||
username == user
|
||||
}
|
||||
|
||||
def 'logout luke'() {
|
||||
when:
|
||||
logout.click(HomePage)
|
||||
then:
|
||||
!username
|
||||
}
|
||||
|
||||
def 'switch back rob'() {
|
||||
setup:
|
||||
def user = 'rob'
|
||||
when:
|
||||
switchAccount(user)
|
||||
then:
|
||||
username == user
|
||||
}
|
||||
|
||||
def 'logout rob'() {
|
||||
when:
|
||||
logout.click(HomePage)
|
||||
then:
|
||||
!username
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package sample.pages
|
||||
|
||||
import geb.*
|
||||
|
||||
/**
|
||||
* The home page
|
||||
*
|
||||
* @author Rob Winch
|
||||
*/
|
||||
class HomePage extends Page {
|
||||
static url = ''
|
||||
static at = { assert driver.title == 'Demonstrates Multi User Log In'; true}
|
||||
static content = {
|
||||
navLink { $('#navLink') }
|
||||
form { $('form') }
|
||||
username(required:false) { $('#un').text() }
|
||||
logout(required:false) { $('#logout') }
|
||||
addAccount(required:false) { $('#addAccount') }
|
||||
submit { $('input[type=submit]') }
|
||||
login(required:false) { user, pass ->
|
||||
form.username = user
|
||||
form.password = pass
|
||||
submit.click(HomePage)
|
||||
}
|
||||
switchAccount{ un ->
|
||||
$("#switchAccount${un}").click(HomePage)
|
||||
}
|
||||
attributes { moduleList AttributeRow, $("table tr").tail() }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package sample.pages
|
||||
|
||||
import geb.*
|
||||
|
||||
/**
|
||||
* The Links Page
|
||||
*
|
||||
* @author Rob Winch
|
||||
*/
|
||||
class LinkPage extends Page {
|
||||
static url = ''
|
||||
static at = { assert driver.title == 'Linked Page'; true}
|
||||
static content = {
|
||||
form { $('#navLinks') }
|
||||
username(required:false) { $('#un').text() }
|
||||
switchAccount{ un ->
|
||||
$("#switchAccount${un}").click(HomePage)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user