diff --git a/examples/extended/src/integration-test/groovy/page/AbstractSecurityPage.groovy b/examples/extended/src/integration-test/groovy/page/AbstractSecurityPage.groovy index 86f74c24..69ed76b7 100644 --- a/examples/extended/src/integration-test/groovy/page/AbstractSecurityPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/AbstractSecurityPage.groovy @@ -5,7 +5,7 @@ import geb.Page abstract class AbstractSecurityPage extends Page { void submit() { - submit.click() + submitBtn.click() } protected boolean assertContentContains(String expected) { @@ -13,7 +13,6 @@ abstract class AbstractSecurityPage extends Page { true } - protected boolean assertContentMatches(String regex) { assert $().text() ==~ regex true diff --git a/examples/extended/src/integration-test/groovy/page/CreatePage.groovy b/examples/extended/src/integration-test/groovy/page/CreatePage.groovy index dbf4b642..29443a30 100644 --- a/examples/extended/src/integration-test/groovy/page/CreatePage.groovy +++ b/examples/extended/src/integration-test/groovy/page/CreatePage.groovy @@ -2,14 +2,13 @@ package page abstract class CreatePage extends AbstractSecurityPage { - static at = { title == 'Create ' + typeName() } - + static at = { title == "Create ${typeName()}" } static content = { form { $('createForm') } - submit { $('a', id: 'create') } + submitBtn { $('a', id: 'create') } } boolean assertNotUnique() { - assertContentContains 'must be unique' + assertContentContains('must be unique') } } diff --git a/examples/extended/src/integration-test/groovy/page/EditPage.groovy b/examples/extended/src/integration-test/groovy/page/EditPage.groovy index 248e4ec3..f9ff6b27 100644 --- a/examples/extended/src/integration-test/groovy/page/EditPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/EditPage.groovy @@ -2,14 +2,13 @@ package page abstract class EditPage extends AbstractSecurityPage { - static at = { title == 'Edit ' + typeName() } - + static at = { title == "Edit ${typeName()}" } static content = { form { $('editForm') } - submit { $('a', id: 'update') } + submitBtn { $('a', id: 'update') } } void delete() { - js.exec 'document.forms.deleteForm.submit()' + js.exec('document.forms.deleteForm.submit()') } } diff --git a/examples/extended/src/integration-test/groovy/page/SearchPage.groovy b/examples/extended/src/integration-test/groovy/page/SearchPage.groovy index b4e53dec..4b17f534 100644 --- a/examples/extended/src/integration-test/groovy/page/SearchPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/SearchPage.groovy @@ -2,31 +2,28 @@ package page abstract class SearchPage extends AbstractSecurityPage { - static at = { title == typeName() + ' Search' } - + static at = { title == "${typeName()} Search" } static atCheckWaiting = true - static content = { form { $('search') } - submit { $('a', id: 'searchButton') } + submitBtn { $('a', id: 'searchButton') } } boolean assertNoResults() { - assertContentContains 'No results' - assertContentDoesNotContain 'Showing' + assertContentContains('No results') + assertContentDoesNotContain('Showing') true } boolean assertNotSearched() { - assertContentContains 'Search' - assertContentDoesNotContain 'No results' - assertContentDoesNotContain 'Showing' + assertContentContains('Search') + assertContentDoesNotContain('No results') + assertContentDoesNotContain('Showing') true } boolean assertResults(int start, int end, int total) { - assertContentContains "Showing $start through $end out of ${total}." + assertContentContains("Showing $start through $end out of ${total}.") true } - } diff --git a/examples/extended/src/integration-test/groovy/page/aclClass/AclClassCreatePage.groovy b/examples/extended/src/integration-test/groovy/page/aclClass/AclClassCreatePage.groovy index 1e53baef..3282b59f 100644 --- a/examples/extended/src/integration-test/groovy/page/aclClass/AclClassCreatePage.groovy +++ b/examples/extended/src/integration-test/groovy/page/aclClass/AclClassCreatePage.groovy @@ -6,9 +6,7 @@ import page.CreatePage class AclClassCreatePage extends CreatePage { static url = 'aclClass/create' - static typeName = { 'AclClass' } - static content = { className { $(name: 'className').module(TextInput) } } diff --git a/examples/extended/src/integration-test/groovy/page/aclClass/AclClassEditPage.groovy b/examples/extended/src/integration-test/groovy/page/aclClass/AclClassEditPage.groovy index ccd604f6..91597281 100644 --- a/examples/extended/src/integration-test/groovy/page/aclClass/AclClassEditPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/aclClass/AclClassEditPage.groovy @@ -6,9 +6,7 @@ import page.EditPage class AclClassEditPage extends EditPage { static url = 'aclClass/edit' - static typeName = { 'AclClass' } - static content = { className { $(name: 'className').module(TextInput) } } diff --git a/examples/extended/src/integration-test/groovy/page/aclClass/AclClassSearchPage.groovy b/examples/extended/src/integration-test/groovy/page/aclClass/AclClassSearchPage.groovy index a44f66e6..85a9d17c 100644 --- a/examples/extended/src/integration-test/groovy/page/aclClass/AclClassSearchPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/aclClass/AclClassSearchPage.groovy @@ -6,9 +6,7 @@ import page.SearchPage class AclClassSearchPage extends SearchPage { static url = 'aclClass/search' - static typeName = { 'AclClass' } - static content = { className { $(name: 'className').module(TextInput) } } diff --git a/examples/extended/src/integration-test/groovy/page/aclEntry/AclEntryCreatePage.groovy b/examples/extended/src/integration-test/groovy/page/aclEntry/AclEntryCreatePage.groovy index 53f7c3eb..3cff7c8e 100644 --- a/examples/extended/src/integration-test/groovy/page/aclEntry/AclEntryCreatePage.groovy +++ b/examples/extended/src/integration-test/groovy/page/aclEntry/AclEntryCreatePage.groovy @@ -8,9 +8,7 @@ import page.CreatePage class AclEntryCreatePage extends CreatePage { static url = 'aclEntry/create' - static typeName = { 'AclEntry' } - static content = { aclObjectIdentityId { $(name: 'aclObjectIdentity.id').module(TextInput) } aceOrder { $(name: 'aceOrder').module(TextInput) } diff --git a/examples/extended/src/integration-test/groovy/page/aclEntry/AclEntryEditPage.groovy b/examples/extended/src/integration-test/groovy/page/aclEntry/AclEntryEditPage.groovy index 617ec94e..3f0692d8 100644 --- a/examples/extended/src/integration-test/groovy/page/aclEntry/AclEntryEditPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/aclEntry/AclEntryEditPage.groovy @@ -8,9 +8,7 @@ import page.EditPage class AclEntryEditPage extends EditPage { static url = 'aclEntry/edit' - static typeName = { 'AclEntry' } - static content = { aclObjectIdentityId { $(name: 'aclObjectIdentity.id').module(TextInput) } aceOrder { $(name: 'aceOrder').module(TextInput) } diff --git a/examples/extended/src/integration-test/groovy/page/aclEntry/AclEntrySearchPage.groovy b/examples/extended/src/integration-test/groovy/page/aclEntry/AclEntrySearchPage.groovy index 923c94b9..e3855832 100644 --- a/examples/extended/src/integration-test/groovy/page/aclEntry/AclEntrySearchPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/aclEntry/AclEntrySearchPage.groovy @@ -6,9 +6,7 @@ import page.SearchPage class AclEntrySearchPage extends SearchPage { static url = 'aclEntry/search' - static typeName = { 'AclEntry' } - static content = { aclObjectIdentity { $(name: 'aclObjectIdentity.id').module(TextInput) } aceOrder { $(name: 'aceOrder').module(TextInput) } diff --git a/examples/extended/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentityCreatePage.groovy b/examples/extended/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentityCreatePage.groovy index 90662a23..746810cb 100644 --- a/examples/extended/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentityCreatePage.groovy +++ b/examples/extended/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentityCreatePage.groovy @@ -7,9 +7,7 @@ import page.CreatePage class AclObjectIdentityCreatePage extends CreatePage { static url = 'aclObjectIdentity/create' - static typeName = { 'AclObjectIdentity' } - static content = { aclClass { $(name: 'aclClass.id').module(Select) } objectId { $(name: 'objectId').module(TextInput) } diff --git a/examples/extended/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentityEditPage.groovy b/examples/extended/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentityEditPage.groovy index e5bbb71d..81f52fe2 100644 --- a/examples/extended/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentityEditPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentityEditPage.groovy @@ -6,9 +6,7 @@ import page.EditPage class AclObjectIdentityEditPage extends EditPage { static url = 'aclObjectIdentity/edit' - static typeName = { 'AclObjectIdentity' } - static content = { objectId { $(name: 'objectId').module(TextInput) } } diff --git a/examples/extended/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentitySearchPage.groovy b/examples/extended/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentitySearchPage.groovy index 2bf6485d..8b43ba75 100644 --- a/examples/extended/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentitySearchPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentitySearchPage.groovy @@ -7,9 +7,7 @@ import page.SearchPage class AclObjectIdentitySearchPage extends SearchPage { static url = 'aclObjectIdentity/search' - static typeName = { 'AclObjectIdentity' } - static content = { aclClass { $(name: 'aclClass.id').module(Select) } objectId { $(name: 'objectId').module(TextInput) } diff --git a/examples/extended/src/integration-test/groovy/page/aclSid/AclSidCreatePage.groovy b/examples/extended/src/integration-test/groovy/page/aclSid/AclSidCreatePage.groovy index 50340863..71e37235 100644 --- a/examples/extended/src/integration-test/groovy/page/aclSid/AclSidCreatePage.groovy +++ b/examples/extended/src/integration-test/groovy/page/aclSid/AclSidCreatePage.groovy @@ -7,9 +7,7 @@ import page.CreatePage class AclSidCreatePage extends CreatePage { static url = 'aclSid/create' - static typeName = { 'AclSid' } - static content = { sid { $(name: 'sid').module(TextInput) } principal { $(name: 'principal').module(Checkbox) } diff --git a/examples/extended/src/integration-test/groovy/page/aclSid/AclSidEditPage.groovy b/examples/extended/src/integration-test/groovy/page/aclSid/AclSidEditPage.groovy index 763ab0ee..48a7cd7b 100644 --- a/examples/extended/src/integration-test/groovy/page/aclSid/AclSidEditPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/aclSid/AclSidEditPage.groovy @@ -7,9 +7,7 @@ import page.EditPage class AclSidEditPage extends EditPage { static url = 'aclSid/edit' - static typeName = { 'AclSid' } - static content = { sid { $(name: 'sid').module(TextInput) } principal { $(name: 'principal').module(Checkbox) } diff --git a/examples/extended/src/integration-test/groovy/page/aclSid/AclSidSearchPage.groovy b/examples/extended/src/integration-test/groovy/page/aclSid/AclSidSearchPage.groovy index 71e5605e..6edcf744 100644 --- a/examples/extended/src/integration-test/groovy/page/aclSid/AclSidSearchPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/aclSid/AclSidSearchPage.groovy @@ -7,9 +7,7 @@ import page.SearchPage class AclSidSearchPage extends SearchPage { static url = 'aclSid/search' - static typeName = { 'AclSid' } - static content = { sid { $(name: 'sid').module(TextInput) } principal { $(name: 'principal').module(RadioButtons) } diff --git a/examples/extended/src/integration-test/groovy/page/persistentLogin/PersistentLoginSearchPage.groovy b/examples/extended/src/integration-test/groovy/page/persistentLogin/PersistentLoginSearchPage.groovy index c0da0470..8af6faf4 100644 --- a/examples/extended/src/integration-test/groovy/page/persistentLogin/PersistentLoginSearchPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/persistentLogin/PersistentLoginSearchPage.groovy @@ -6,9 +6,7 @@ import page.SearchPage class PersistentLoginSearchPage extends SearchPage { static url = 'persistentLogin/search' - static typeName = { 'PersistentLogin' } - static content = { series { $(name: 'series').module(TextInput) } token { $(name: 'token').module(TextInput) } diff --git a/examples/extended/src/integration-test/groovy/page/profile/ProfileCreatePage.groovy b/examples/extended/src/integration-test/groovy/page/profile/ProfileCreatePage.groovy index dce84709..1e770ef7 100644 --- a/examples/extended/src/integration-test/groovy/page/profile/ProfileCreatePage.groovy +++ b/examples/extended/src/integration-test/groovy/page/profile/ProfileCreatePage.groovy @@ -8,26 +8,22 @@ import page.CreatePage class ProfileCreatePage extends AbstractSecurityPage { static at = { title == 'Create Profile' } - - static url = 'profile/create' - - static content = { myQuestion { $('#myQuestion1').module(TextInput) } myQuestion2 { $('#myQuestion2').module(TextInput) } myAnswer2 { $('#myAnswer2').module(TextInput) } myAnswer { $('#myAnswer1').module(TextInput) } - submit { $("#create")} + submitBtn { $('#create')} } void create(String userName) { - def userSelect = $(name: "user.id").module(Select) + def userSelect = $(name: 'user.id').module(Select) userSelect.selected = userName - myQuestion = "Count to 8" - myQuestion2 = "Count to 4" - myAnswer2 = "1234" - myAnswer = "12345678" + myQuestion = 'Count to 8' + myQuestion2 = 'Count to 4' + myAnswer2 = '1234' + myAnswer = '12345678' submit() } } diff --git a/examples/extended/src/integration-test/groovy/page/profile/ProfileEditPage.groovy b/examples/extended/src/integration-test/groovy/page/profile/ProfileEditPage.groovy index c1e9c9f2..028a2d07 100644 --- a/examples/extended/src/integration-test/groovy/page/profile/ProfileEditPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/profile/ProfileEditPage.groovy @@ -7,34 +7,30 @@ import page.AbstractSecurityPage class ProfileEditPage extends AbstractSecurityPage { static url = 'profile/edit' - static at = { title == 'Edit Profile' } - - static content = { myQuestion { $('#myQuestion1').module(TextInput) } myQuestion2 { $('#myQuestion2').module(TextInput) } myAnswer2 { $('#myAnswer2').module(TextInput) } myAnswer { $('#myAnswer1').module(TextInput) } - submit { $("#update")} + submitBtn { $('#update')} } void updateProfile(String userName) { - def userSelect = $(name: "user.id").module(Select) + def userSelect = $(name: 'user.id').module(Select) userSelect.selected = userName - myQuestion = "Count to 4" - myQuestion2 = "Count to 5" - myAnswer2 = "12345" - myAnswer = "1234" - + myQuestion = 'Count to 4' + myQuestion2 = 'Count to 5' + myAnswer2 = '12345' + myAnswer = '1234' submit() } void deleteProfile() { - $("#deleteButton").click() + $('#deleteButton').click() waitFor { - $("span", text:"Are you sure?") + $('span', text: 'Are you sure?') } - $("button", text:"Delete").click() + $('button', text: 'Delete').click() } } \ No newline at end of file diff --git a/examples/extended/src/integration-test/groovy/page/profile/ProfileListPage.groovy b/examples/extended/src/integration-test/groovy/page/profile/ProfileListPage.groovy index e1a53b4b..81e7aa19 100644 --- a/examples/extended/src/integration-test/groovy/page/profile/ProfileListPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/profile/ProfileListPage.groovy @@ -1,19 +1,16 @@ package page.profile -import geb.module.Select -import geb.module.TextInput import page.AbstractSecurityPage class ProfileListPage extends AbstractSecurityPage { - static at = { title == 'Profile List' } - - static url = 'profile' - - + static at = { title == 'Profile List' } static content = { - + profileEditLink { String username -> $('a', text: "User(username:$username)").parent().parent().children().first().children('a') } } + void editProfile(String username) { + profileEditLink(username).click() + } } diff --git a/examples/extended/src/integration-test/groovy/page/register/ForgotPasswordPage.groovy b/examples/extended/src/integration-test/groovy/page/register/ForgotPasswordPage.groovy index ad4a9429..992d5cfb 100644 --- a/examples/extended/src/integration-test/groovy/page/register/ForgotPasswordPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/register/ForgotPasswordPage.groovy @@ -6,14 +6,10 @@ import page.AbstractSecurityPage class ForgotPasswordPage extends AbstractSecurityPage { static url = 'register/forgotPassword' - static at = { title == 'Forgot Password' } - static content = { form { $('forgotPasswordForm') } - username { $(name: 'username').module(TextInput) } - - submit { $('a', id: 'submit') } + submitBtn { $('a', id: 'submit') } } } diff --git a/examples/extended/src/integration-test/groovy/page/register/RegisterPage.groovy b/examples/extended/src/integration-test/groovy/page/register/RegisterPage.groovy index cd68c5a3..b8140840 100644 --- a/examples/extended/src/integration-test/groovy/page/register/RegisterPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/register/RegisterPage.groovy @@ -1,22 +1,19 @@ package page.register +import geb.module.PasswordInput import geb.module.TextInput import page.AbstractSecurityPage class RegisterPage extends AbstractSecurityPage { static url = 'register' - static at = { title == 'Register' } - static content = { form { $('registerForm') } - username { $(name: 'username').module(TextInput) } email { $(name: 'email').module(TextInput) } - password { $(name: 'password').module(TextInput) } - password2 { $(name: 'password2').module(TextInput) } - - submit { $('a', id: 'submit') } + password { $(name: 'password').module(PasswordInput) } + password2 { $(name: 'password2').module(PasswordInput) } + submitBtn { $('a', id: 'submit') } } } diff --git a/examples/extended/src/integration-test/groovy/page/register/ResetPasswordPage.groovy b/examples/extended/src/integration-test/groovy/page/register/ResetPasswordPage.groovy index 1cf2b709..801c5df2 100644 --- a/examples/extended/src/integration-test/groovy/page/register/ResetPasswordPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/register/ResetPasswordPage.groovy @@ -1,19 +1,17 @@ package page.register -import geb.module.TextInput +import geb.module.PasswordInput import page.AbstractSecurityPage class ResetPasswordPage extends AbstractSecurityPage { static url = 'register/resetPassword' - static at = { title == 'Reset Password' } - static content = { form { $('resetPasswordForm') } - password { $('#password') } - password2 { $('#password2') } - submit { $('a', id: 'submit') } + password { $('#password').module(PasswordInput) } + password2 { $('#password2').module(PasswordInput) } + submitBtn { $('a', id: 'submit') } } def enterNewPassword(String p1, String p2) { diff --git a/examples/extended/src/integration-test/groovy/page/register/SecurityQuestionsPage.groovy b/examples/extended/src/integration-test/groovy/page/register/SecurityQuestionsPage.groovy index 0d414722..d3a5b8f6 100644 --- a/examples/extended/src/integration-test/groovy/page/register/SecurityQuestionsPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/register/SecurityQuestionsPage.groovy @@ -6,18 +6,11 @@ import page.AbstractSecurityPage class SecurityQuestionsPage extends AbstractSecurityPage { static url = 'register/securityQuestions' - static at = { title == 'Security Questions' } - static content = { form { $('securityQuestionsForm') } question1 { $('#myAnswer1').module(TextInput) } question2 { $('#myAnswer2').module(TextInput) } - submit { $('a', id: 'submit') } - } - - def answerQuestions() { - question1.value('1234') - question2.value('12345') + submitBtn { $('a', id: 'submit') } } } diff --git a/examples/extended/src/integration-test/groovy/page/registrationCode/RegistrationCodeEditPage.groovy b/examples/extended/src/integration-test/groovy/page/registrationCode/RegistrationCodeEditPage.groovy index f4affae3..7f7afe95 100644 --- a/examples/extended/src/integration-test/groovy/page/registrationCode/RegistrationCodeEditPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/registrationCode/RegistrationCodeEditPage.groovy @@ -6,9 +6,7 @@ import page.EditPage class RegistrationCodeEditPage extends EditPage { static url = 'registrationCode/edit' - static typeName = { 'RegistrationCode' } - static content = { token { $(name: 'token').module(TextInput) } username { $('#username').module(TextInput) } diff --git a/examples/extended/src/integration-test/groovy/page/registrationCode/RegistrationCodeSearchPage.groovy b/examples/extended/src/integration-test/groovy/page/registrationCode/RegistrationCodeSearchPage.groovy index 681a009a..cd442e66 100644 --- a/examples/extended/src/integration-test/groovy/page/registrationCode/RegistrationCodeSearchPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/registrationCode/RegistrationCodeSearchPage.groovy @@ -6,9 +6,7 @@ import page.SearchPage class RegistrationCodeSearchPage extends SearchPage { static url = 'registrationCode/search' - static typeName = { 'Registration Code' } - static content = { token { $(name: 'token').module(TextInput) } username { $('#username').module(TextInput) } diff --git a/examples/extended/src/integration-test/groovy/page/requestmap/RequestmapCreatePage.groovy b/examples/extended/src/integration-test/groovy/page/requestmap/RequestmapCreatePage.groovy index 68196150..f23f7bb4 100644 --- a/examples/extended/src/integration-test/groovy/page/requestmap/RequestmapCreatePage.groovy +++ b/examples/extended/src/integration-test/groovy/page/requestmap/RequestmapCreatePage.groovy @@ -6,9 +6,7 @@ import page.CreatePage class RequestmapCreatePage extends CreatePage { static url = 'requestmap/create' - static typeName = { 'Requestmap' } - static content = { configAttribute { $(name: 'configAttribute').module(TextInput) } urlPattern { $(name: 'url').module(TextInput) } diff --git a/examples/extended/src/integration-test/groovy/page/requestmap/RequestmapEditPage.groovy b/examples/extended/src/integration-test/groovy/page/requestmap/RequestmapEditPage.groovy index a7b1c151..d0b60de5 100644 --- a/examples/extended/src/integration-test/groovy/page/requestmap/RequestmapEditPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/requestmap/RequestmapEditPage.groovy @@ -6,9 +6,7 @@ import page.EditPage class RequestmapEditPage extends EditPage { static url = 'requestmap/edit' - static typeName = { 'Requestmap' } - static content = { configAttribute { $(name: 'configAttribute').module(TextInput) } urlPattern { $(name: 'url').module(TextInput) } diff --git a/examples/extended/src/integration-test/groovy/page/requestmap/RequestmapSearchPage.groovy b/examples/extended/src/integration-test/groovy/page/requestmap/RequestmapSearchPage.groovy index 37ba3882..8d43b719 100644 --- a/examples/extended/src/integration-test/groovy/page/requestmap/RequestmapSearchPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/requestmap/RequestmapSearchPage.groovy @@ -6,9 +6,7 @@ import page.SearchPage class RequestmapSearchPage extends SearchPage { static url = 'requestmap/search' - static typeName = { 'Requestmap' } - static content = { configAttribute { $(name: 'configAttribute').module(TextInput) } urlPattern { $(name: 'url').module(TextInput) } diff --git a/examples/extended/src/integration-test/groovy/page/role/RoleCreatePage.groovy b/examples/extended/src/integration-test/groovy/page/role/RoleCreatePage.groovy index fd634f40..3b7c4b5a 100644 --- a/examples/extended/src/integration-test/groovy/page/role/RoleCreatePage.groovy +++ b/examples/extended/src/integration-test/groovy/page/role/RoleCreatePage.groovy @@ -6,9 +6,7 @@ import page.CreatePage class RoleCreatePage extends CreatePage { static url = 'role/create' - static typeName = { 'Role' } - static content = { authority { $(name: 'authority').module(TextInput) } } diff --git a/examples/extended/src/integration-test/groovy/page/role/RoleEditPage.groovy b/examples/extended/src/integration-test/groovy/page/role/RoleEditPage.groovy index ccc1ed1d..58444394 100644 --- a/examples/extended/src/integration-test/groovy/page/role/RoleEditPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/role/RoleEditPage.groovy @@ -6,9 +6,7 @@ import page.EditPage class RoleEditPage extends EditPage { static url = 'role/edit' - static typeName = { 'Role' } - static content = { authority { $(name: 'authority').module(TextInput) } } diff --git a/examples/extended/src/integration-test/groovy/page/role/RoleSearchPage.groovy b/examples/extended/src/integration-test/groovy/page/role/RoleSearchPage.groovy index e0646395..2c03eb9e 100644 --- a/examples/extended/src/integration-test/groovy/page/role/RoleSearchPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/role/RoleSearchPage.groovy @@ -6,9 +6,7 @@ import page.SearchPage class RoleSearchPage extends SearchPage { static url = 'role/search' - static typeName = { 'Role' } - static content = { authority { $(name: 'authority').module(TextInput) } } diff --git a/examples/extended/src/integration-test/groovy/page/user/UserCreatePage.groovy b/examples/extended/src/integration-test/groovy/page/user/UserCreatePage.groovy index 794deb0c..f88c6f4c 100644 --- a/examples/extended/src/integration-test/groovy/page/user/UserCreatePage.groovy +++ b/examples/extended/src/integration-test/groovy/page/user/UserCreatePage.groovy @@ -1,17 +1,17 @@ package page.user import geb.module.Checkbox +import geb.module.PasswordInput import geb.module.TextInput import page.CreatePage class UserCreatePage extends CreatePage { static url = 'user/create' - static typeName = { 'User' } - static content = { username { $('#username').module(TextInput) } + password { $('#password').module(PasswordInput) } enabled { $(name: 'enabled').module(Checkbox) } accountExpired { $(name: 'accountExpired').module(Checkbox) } accountLocked { $(name: 'accountLocked').module(Checkbox) } diff --git a/examples/extended/src/integration-test/groovy/page/user/UserEditPage.groovy b/examples/extended/src/integration-test/groovy/page/user/UserEditPage.groovy index 82bbe042..575f4e7b 100644 --- a/examples/extended/src/integration-test/groovy/page/user/UserEditPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/user/UserEditPage.groovy @@ -7,9 +7,7 @@ import page.EditPage class UserEditPage extends EditPage { static url = 'user/edit' - static typeName = { 'User' } - static content = { username { $('#username').module(TextInput) } enabled { $(name: 'enabled').module(Checkbox) } diff --git a/examples/extended/src/integration-test/groovy/page/user/UserSearchPage.groovy b/examples/extended/src/integration-test/groovy/page/user/UserSearchPage.groovy index 4a3aa090..fb2e03a4 100644 --- a/examples/extended/src/integration-test/groovy/page/user/UserSearchPage.groovy +++ b/examples/extended/src/integration-test/groovy/page/user/UserSearchPage.groovy @@ -7,9 +7,7 @@ import page.SearchPage class UserSearchPage extends SearchPage { static url = 'user/search' - static typeName = { 'User' } - static content = { username { $('#username').module(TextInput) } enabled { $(name: 'enabled').module(RadioButtons) } diff --git a/examples/extended/src/integration-test/groovy/spec/AbstractSecuritySpec.groovy b/examples/extended/src/integration-test/groovy/spec/AbstractSecuritySpec.groovy index 245c47f2..7ddbc418 100644 --- a/examples/extended/src/integration-test/groovy/spec/AbstractSecuritySpec.groovy +++ b/examples/extended/src/integration-test/groovy/spec/AbstractSecuritySpec.groovy @@ -1,11 +1,8 @@ package spec import geb.driver.CachingDriverFactory -import geb.spock.GebReportingSpec -import grails.plugin.springsecurity.SpringSecurityUtils -import grails.testing.mixin.integration.Integration -import spock.lang.Stepwise import grails.plugin.geb.ContainerGebSpec +import grails.plugin.springsecurity.SpringSecurityUtils abstract class AbstractSecuritySpec extends ContainerGebSpec { @@ -19,7 +16,7 @@ abstract class AbstractSecuritySpec extends ContainerGebSpec { protected void logout() { String url = SpringSecurityUtils.securityConfig.logout.filterProcessesUrl - go url + browser.go(url) browser.clearCookies() } @@ -28,23 +25,26 @@ abstract class AbstractSecuritySpec extends ContainerGebSpec { } protected void assertContentContains(String expected) { - assert $().text().contains(expected) + assert browser.$().text().contains(expected) } // used to verify hidden content like menus and jGrowl flash messages protected void assertHtmlContains(String expected) { + // For some reason, an extra call to pageSource is sometimes + // needed here, for jGrowl messages to be rendered to the page + assert browser.driver.pageSource assert browser.driver.pageSource.contains(expected) } protected void assertContentContainsOne(String expected1, String expected2) { - assert $().text().contains(expected1) || $().text().contains(expected2) + assert browser.$().text().contains(expected1) || $().text().contains(expected2) } protected void assertContentMatches(String regex) { - assert $().text() ==~ regex + assert browser.$().text() ==~ regex } protected void assertContentDoesNotContain(String unexpected) { - assert !$().text().contains(unexpected) + assert !browser.$().text().contains(unexpected) } } diff --git a/examples/extended/src/integration-test/groovy/spec/AclClassSpec.groovy b/examples/extended/src/integration-test/groovy/spec/AclClassSpec.groovy index 70d90a25..a5ab482c 100644 --- a/examples/extended/src/integration-test/groovy/spec/AclClassSpec.groovy +++ b/examples/extended/src/integration-test/groovy/spec/AclClassSpec.groovy @@ -4,90 +4,92 @@ import grails.testing.mixin.integration.Integration import page.aclClass.AclClassCreatePage import page.aclClass.AclClassEditPage import page.aclClass.AclClassSearchPage -import spock.lang.Stepwise -@Stepwise @Integration class AclClassSpec extends AbstractSecuritySpec { void testFindAll() { when: - to AclClassSearchPage + def aclClassSearchPage = browser.to(AclClassSearchPage) then: - assertNotSearched() + aclClassSearchPage.assertNotSearched() when: - submit() + aclClassSearchPage.submit() then: - at AclClassSearchPage - assertResults 1, 1, 1 + browser.at(AclClassSearchPage) + aclClassSearchPage.assertResults(1, 1, 1) } void testFindByName() { when: - to AclClassSearchPage - search 'report' + def aclClassSearchPage = browser.to(AclClassSearchPage).tap { + search('report') + } then: - at AclClassSearchPage - assertResults 1, 1, 1 - assertContentContains 'test.Report' + browser.at(AclClassSearchPage) + aclClassSearchPage.assertResults(1, 1, 1) + assertContentContains('test.Report') } void testUniqueName() { when: - to AclClassCreatePage - create 'test.Report' + def aclClassCreatePage = browser.to(AclClassCreatePage).tap { + create('test.Report') + } then: - at AclClassCreatePage - assertNotUnique() + browser.at(AclClassCreatePage) + aclClassCreatePage.assertNotUnique() } void testCreateAndEdit() { given: - String newName = 'com.some.domain.Clazz' + UUID.randomUUID() + String newName = "com.some.domain.Clazz${UUID.randomUUID()}" // make sure it doesn't exist when: - to AclClassSearchPage - search newName + def aclClassSearchPage = browser.to(AclClassSearchPage).tap { + search(newName) + } then: - at AclClassSearchPage - assertNoResults() + browser.at(AclClassSearchPage) + aclClassSearchPage.assertNoResults() // create when: - to AclClassCreatePage - create newName + browser.to(AclClassCreatePage).with { + create(newName) + } then: - at AclClassEditPage - className == newName + def aclClassEditPage = browser.at(AclClassEditPage) + aclClassEditPage.className.text == newName // edit when: - update newName + '_new' + aclClassEditPage.update("${newName}_new") then: - at AclClassEditPage - className == newName + '_new' + browser.at(AclClassEditPage) + aclClassEditPage.className.text == "${newName}_new" // delete when: - delete() + aclClassEditPage.delete() then: - at AclClassSearchPage + browser.at(AclClassSearchPage) when: - search newName + '_new' + aclClassSearchPage.search("${newName}_new") then: - at AclClassSearchPage - assertNoResults() + browser.at(AclClassSearchPage) + aclClassSearchPage.assertNoResults() } } diff --git a/examples/extended/src/integration-test/groovy/spec/AclEntrySpec.groovy b/examples/extended/src/integration-test/groovy/spec/AclEntrySpec.groovy index afa8ab1b..04bdc700 100644 --- a/examples/extended/src/integration-test/groovy/spec/AclEntrySpec.groovy +++ b/examples/extended/src/integration-test/groovy/spec/AclEntrySpec.groovy @@ -4,83 +4,87 @@ import grails.testing.mixin.integration.Integration import page.aclEntry.AclEntryCreatePage import page.aclEntry.AclEntryEditPage import page.aclEntry.AclEntrySearchPage -import spock.lang.Stepwise -@Stepwise @Integration class AclEntrySpec extends AbstractSecuritySpec { void testFindAll() { when: - to AclEntrySearchPage + def aclEntrySearchPage = browser.to(AclEntrySearchPage) then: - assertNotSearched() + aclEntrySearchPage.assertNotSearched() when: - submit() + aclEntrySearchPage.submit() then: - at AclEntrySearchPage - assertResults 1, 10, 275 + browser.at(AclEntrySearchPage) + aclEntrySearchPage.assertResults(1, 10, 275) } void testFindByOid() { when: - to AclEntrySearchPage - aclObjectIdentity = '60' - submit() + def aclEntrySearchPage = browser.to(AclEntrySearchPage).tap { + aclObjectIdentity = '60' + submit() + } then: - at AclEntrySearchPage - assertResults 1, 3, 3 - - assertContentContains '60' - assertContentContains '398' - assertContentContains '399' - assertContentContains '400' - assertContentContains 'user1' - assertContentContains 'admin' - assertContentDoesNotContain '>user2' - assertContentContains 'BasePermission[...............................R=1]' - assertContentContains 'BasePermission[...........................A....=16]' + browser.at(AclEntrySearchPage) + aclEntrySearchPage.assertResults(1, 3, 3) + + assertContentContains('60') + assertContentContains('398') + assertContentContains('399') + assertContentContains('400') + assertContentContains('user1') + assertContentContains('admin') + assertContentDoesNotContain('>user2') + assertContentContains('BasePermission[...............................R=1]') + assertContentContains('BasePermission[...........................A....=16]') } void testFindByAceOrder() { when: - to AclEntrySearchPage - aceOrder = '2' - submit() + def aclEntrySearchPage = browser.to(AclEntrySearchPage).tap { + aceOrder = '2' + submit() + } then: - at AclEntrySearchPage - assertResults 1, 10, 67 - ['104', '111', '119', '126', '131', '136', '141', '146', '152', '159'].each { assertContentContains it } + browser.at(AclEntrySearchPage) + aclEntrySearchPage.assertResults(1, 10, 67) + ['104', '111', '119', '126', '131', '136', '141', '146', '152', '159'].each { + assertContentContains it + } } void testFindByMask() { when: - to AclEntrySearchPage - mask = '1' - submit() + def aclEntrySearchPage = browser.to(AclEntrySearchPage).tap { + mask = '1' + submit() + } then: - at AclEntrySearchPage - assertResults 1, 10, 172 + browser.at(AclEntrySearchPage) + aclEntrySearchPage.assertResults(1, 10, 172) } void testUniqueOrder() { when: - to AclEntryCreatePage - aclObjectIdentityId = '3' - aceOrder = '2' - sid.selected = '1' - mask = '1' - submit() + def aclEntryCreatePage = browser.to(AclEntryCreatePage).tap { + aclObjectIdentityId = '3' + aceOrder = '1' + sid.selected = '1' + mask = '1' + submit() + } then: - at AclEntryCreatePage - assertNotUnique() + browser.at(AclEntryCreatePage) + aclEntryCreatePage.assertNotUnique() } void testCreateAndEdit() { @@ -89,50 +93,52 @@ class AclEntrySpec extends AbstractSecuritySpec { // make sure it doesn't exist when: - to AclEntrySearchPage - aclObjectIdentity = '10' - aceOrder = newOrder - submit() + def aclEntrySearchPage = browser.to(AclEntrySearchPage).tap { + aclObjectIdentity = '10' + aceOrder = newOrder + submit() + } then: - at AclEntrySearchPage - assertNoResults() + browser.at(AclEntrySearchPage) + aclEntrySearchPage.assertNoResults() // create when: - to AclEntryCreatePage - aclObjectIdentityId = '10' - aceOrder = newOrder - sid.selected = '2' - mask = '2' - submit() + def aclEntryCreatePage = browser.to(AclEntryCreatePage).tap { + aclObjectIdentityId = '10' + aceOrder = newOrder + sid.selected = '2' + mask = '2' + submit() + } then: - at AclEntryEditPage - aceOrder == newOrder + def aclEntryEditPage = browser.at(AclEntryEditPage) + aclEntryEditPage.aceOrder.text == newOrder // edit when: - aceOrder = ((newOrder as int) + 1) as String - submit() + aclEntryEditPage.aceOrder = ((newOrder as int) + 1) as String + aclEntryEditPage.submit() then: - at AclEntryEditPage - aceOrder == ((newOrder as int) + 1) as String + browser.at(AclEntryEditPage) + aclEntryEditPage.aceOrder.text == ((newOrder as int) + 1) as String // delete when: - delete() + aclEntryEditPage.delete() then: - at AclEntrySearchPage + browser.at(AclEntrySearchPage) when: - aceOrder = ((newOrder as int) + 1) as String - submit() + aclEntrySearchPage.aceOrder = ((newOrder as int) + 1) as String + aclEntrySearchPage.submit() then: - at AclEntrySearchPage - assertNoResults() + browser.at(AclEntrySearchPage) + aclEntrySearchPage.assertNoResults() } } diff --git a/examples/extended/src/integration-test/groovy/spec/AclObjectIdentitySpec.groovy b/examples/extended/src/integration-test/groovy/spec/AclObjectIdentitySpec.groovy index c96f74db..f948b9a9 100644 --- a/examples/extended/src/integration-test/groovy/spec/AclObjectIdentitySpec.groovy +++ b/examples/extended/src/integration-test/groovy/spec/AclObjectIdentitySpec.groovy @@ -4,61 +4,62 @@ import grails.testing.mixin.integration.Integration import page.aclObjectIdentity.AclObjectIdentityCreatePage import page.aclObjectIdentity.AclObjectIdentityEditPage import page.aclObjectIdentity.AclObjectIdentitySearchPage -import spock.lang.Stepwise -@Stepwise @Integration class AclObjectIdentitySpec extends AbstractSecuritySpec { void testFindAll() { when: - to AclObjectIdentitySearchPage + def aclObjectIdentitySearchPage = browser.to(AclObjectIdentitySearchPage) then: - assertNotSearched() + aclObjectIdentitySearchPage.assertNotSearched() when: - submit() + aclObjectIdentitySearchPage.submit() then: - at AclObjectIdentitySearchPage - assertResults 1, 10, 100 + browser.at(AclObjectIdentitySearchPage) + aclObjectIdentitySearchPage.assertResults(1, 10, 100) } void testFindById() { when: - to AclObjectIdentitySearchPage - objectId = '10' - submit() + def aclObjectIdentitySearchPage = browser.to(AclObjectIdentitySearchPage).tap { + objectId = '10' + submit() + } then: - at AclObjectIdentitySearchPage - assertResults 1, 1, 1 - assertContentContains 'test.Report' + browser.at(AclObjectIdentitySearchPage) + aclObjectIdentitySearchPage.assertResults(1, 1, 1) + assertContentContains('test.Report') } void testFindByOwner() { when: - to AclObjectIdentitySearchPage - ownerId = '1' - submit() + def aclObjectIdentitySearchPage = browser.to(AclObjectIdentitySearchPage).tap { + ownerId = '1' + submit() + } then: - at AclObjectIdentitySearchPage - assertResults 1, 10, 98 + browser.at(AclObjectIdentitySearchPage) + aclObjectIdentitySearchPage.assertResults(1, 10, 98) } void testUniqueId() { when: - to AclObjectIdentityCreatePage - aclClass.selected = '1' - objectId = 1 - ownerId.selected = '2' - submit() + def aclObjectIdentityCreatePage = browser.to(AclObjectIdentityCreatePage).tap { + aclClass.selected = '1' + objectId = 1 + ownerId.selected = '2' + submit() + } then: - at AclObjectIdentityCreatePage - assertNotUnique() + browser.at(AclObjectIdentityCreatePage) + aclObjectIdentityCreatePage.assertNotUnique() } void testCreateAndEdit() { @@ -67,47 +68,49 @@ class AclObjectIdentitySpec extends AbstractSecuritySpec { // make sure it doesn't exist when: - to AclObjectIdentitySearchPage - objectId = newId - submit() + def aclObjectIdentitySearchPage = browser.to(AclObjectIdentitySearchPage).tap { + objectId = newId + submit() + } then: - assertNoResults() + aclObjectIdentitySearchPage.assertNoResults() // create when: - to AclObjectIdentityCreatePage - aclClass.selected = '1' - objectId = newId - ownerId.selected = '2' - submit() + browser.to(AclObjectIdentityCreatePage).with { + aclClass.selected = '1' + objectId = newId + ownerId.selected = '2' + submit() + } then: - at AclObjectIdentityEditPage - objectId == newId + def aclObjectIdentityEditPage = browser.at(AclObjectIdentityEditPage) + aclObjectIdentityEditPage.objectId.text == newId // edit when: - objectId = (newId.toInteger() + 1).toString() - submit() + aclObjectIdentityEditPage.objectId = (newId.toInteger() + 1).toString() + aclObjectIdentityEditPage.submit() then: - at AclObjectIdentityEditPage - objectId == (newId.toInteger() + 1).toString() + browser.at(AclObjectIdentityEditPage) + aclObjectIdentityEditPage.objectId.text == (newId.toInteger() + 1).toString() // delete when: - delete() + aclObjectIdentityEditPage.delete() then: - at AclObjectIdentitySearchPage + browser.at(AclObjectIdentitySearchPage) when: - objectId = (newId.toInteger() + 1).toString() - submit() + aclObjectIdentitySearchPage.objectId = (newId.toInteger() + 1).toString() + aclObjectIdentitySearchPage.submit() then: - at AclObjectIdentitySearchPage - assertNoResults() + browser.at(AclObjectIdentitySearchPage) + aclObjectIdentitySearchPage.assertNoResults() } } diff --git a/examples/extended/src/integration-test/groovy/spec/AclSidSpec.groovy b/examples/extended/src/integration-test/groovy/spec/AclSidSpec.groovy index ce240454..0378b6f5 100644 --- a/examples/extended/src/integration-test/groovy/spec/AclSidSpec.groovy +++ b/examples/extended/src/integration-test/groovy/spec/AclSidSpec.groovy @@ -4,108 +4,112 @@ import grails.testing.mixin.integration.Integration import page.aclSid.AclSidCreatePage import page.aclSid.AclSidEditPage import page.aclSid.AclSidSearchPage -import spock.lang.Stepwise -@Stepwise @Integration class AclSidSpec extends AbstractSecuritySpec { void testFindAll() { when: - to AclSidSearchPage + def aclSidSearchPage = browser.to(AclSidSearchPage) then: - assertNotSearched() + aclSidSearchPage.assertNotSearched() when: - submit() + aclSidSearchPage.submit() then: - at AclSidSearchPage - assertResults 1, 3, 3 + browser.at(AclSidSearchPage) + aclSidSearchPage.assertResults(1, 3, 3) } void testFindBySid() { when: - to AclSidSearchPage - search 'user' + def aclSidSearchPage = browser.to(AclSidSearchPage).tap { + search('user') + } then: - at AclSidSearchPage - assertResults 1, 2, 2 + browser.at(AclSidSearchPage) + aclSidSearchPage.assertResults(1, 2, 2) - assertContentContains 'user1' - assertContentContains 'user2' + assertContentContains('user1') + assertContentContains('user2') } void testFindByPrincipal() { when: - to AclSidSearchPage - principal.checked = '1' - submit() + def aclSidSearchPage = browser.to(AclSidSearchPage) + // Temporary workaround for problem with Geb RadioButtons module + //aclSidSearchPage.principal.checked = '1' + browser.$('input', type: 'radio', name: 'principal', value: '1').click() + aclSidSearchPage.submit() then: - at AclSidSearchPage - assertContentContains 'user1' - assertContentContains 'user2' - assertContentContains 'admin' + browser.at(AclSidSearchPage) + assertContentContains('user1') + assertContentContains('user2') + assertContentContains('admin') } void testUniqueName() { when: - to AclSidCreatePage - create 'user1', true + def aclSidCreatePage = browser.to(AclSidCreatePage).tap { + create('user1', true) + } then: - at AclSidCreatePage - assertContentContains 'must be unique' + browser.at(AclSidCreatePage) + assertContentContains('must be unique') } void testCreateAndEdit() { given: - String newName = 'newuser' + UUID.randomUUID() + String newName = "newuser${UUID.randomUUID()}" // make sure it doesn't exist when: - to AclSidSearchPage - sid = newName - submit() + def aclSidSearchPage = browser.to(AclSidSearchPage).tap { + sid = newName + submit() + } then: - assertNoResults() + aclSidSearchPage.assertNoResults() // create when: - to AclSidCreatePage - create newName, true + def aclSidCreatePage = browser.to(AclSidCreatePage).tap { + create(newName, true) + } then: - at AclSidEditPage - sid == newName - principal.checked + def aclSidEditPage = browser.at(AclSidEditPage) + aclSidEditPage.sid.text == newName + aclSidEditPage.principal.checked // edit when: - sid = newName + '_new' - submit() + aclSidEditPage.sid = "${newName}_new" + aclSidEditPage.submit() then: - at AclSidEditPage - sid == newName + '_new' + browser.at(AclSidEditPage) + aclSidEditPage.sid.text == "${newName}_new" // delete when: - delete() + aclSidEditPage.delete() then: - at AclSidSearchPage + browser.at(AclSidSearchPage) when: - sid = newName + '_new' - submit() + aclSidSearchPage.sid = "${newName}_new" + aclSidSearchPage.submit() then: - at AclSidSearchPage - assertNoResults() + browser.at(AclSidSearchPage) + aclSidSearchPage.assertNoResults() } } diff --git a/examples/extended/src/integration-test/groovy/spec/ExtendedMenuSpec.groovy b/examples/extended/src/integration-test/groovy/spec/ExtendedMenuSpec.groovy index 12a78faf..cb69aca7 100644 --- a/examples/extended/src/integration-test/groovy/spec/ExtendedMenuSpec.groovy +++ b/examples/extended/src/integration-test/groovy/spec/ExtendedMenuSpec.groovy @@ -1,15 +1,13 @@ package spec import grails.testing.mixin.integration.Integration -import spock.lang.Stepwise -@Stepwise @Integration class ExtendedMenuSpec extends AbstractSecuritySpec { void testIndex() { when: - go '' + browser.go('') String html = pageSource then: diff --git a/examples/extended/src/integration-test/groovy/spec/ExtendedSecurityInfoSpec.groovy b/examples/extended/src/integration-test/groovy/spec/ExtendedSecurityInfoSpec.groovy index d56c0bc9..3df82610 100644 --- a/examples/extended/src/integration-test/groovy/spec/ExtendedSecurityInfoSpec.groovy +++ b/examples/extended/src/integration-test/groovy/spec/ExtendedSecurityInfoSpec.groovy @@ -3,9 +3,7 @@ package spec import grails.testing.mixin.integration.Integration import org.springframework.security.core.userdetails.User import org.springframework.security.core.userdetails.UserCache -import spock.lang.Stepwise -@Stepwise @Integration class ExtendedSecurityInfoSpec extends AbstractSecuritySpec { @@ -13,114 +11,115 @@ class ExtendedSecurityInfoSpec extends AbstractSecuritySpec { void testConfig() { when: - go 'securityInfo/config' + browser.go('securityInfo/config') then: - assertContentContains 'adh.ajaxErrorPage /login/ajaxDenied' - assertContentContains 'Showing 1 to 10 of ' + assertContentContains('adh.ajaxErrorPage /login/ajaxDenied') + assertContentContains('Showing 1 to 10 of ') } void testMappings() { when: - go 'securityInfo/mappings' + browser.go('securityInfo/mappings') then: - assertContentContainsOne 'ROLE_RUN_AS, IS_AUTHENTICATED_FULLY', - 'IS_AUTHENTICATED_FULLY, ROLE_RUN_AS' - - assertContentContains '/j_spring_security_switch_user' - assertContentContains '/secure/**' - assertContentContains 'ROLE_ADMIN' + assertContentContainsOne( + 'ROLE_RUN_AS, IS_AUTHENTICATED_FULLY', + 'IS_AUTHENTICATED_FULLY, ROLE_RUN_AS' + ) + + assertContentContains('/j_spring_security_switch_user') + assertContentContains('/secure/**') + assertContentContains('ROLE_ADMIN') } void testCurrentAuth() { when: - go 'securityInfo/currentAuth' + browser.go('securityInfo/currentAuth') then: - assertContentContains 'Details WebAuthenticationDetails' - assertContentContains '__grails.anonymous.user__' + assertContentContains('Details WebAuthenticationDetails') + assertContentContains('__grails.anonymous.user__') } - void testUsercache() { + void testUserCache() { given: userCache.putUserInCache(new User('testuser', 'pw', [])) when: - go 'securityInfo/usercache' + browser.go('securityInfo/usercache') then: - assertContentContains 'UserCache class: org.ehcache.jsr107.Eh107Cache' - assertContentContains 'testuser' + assertContentContains('UserCache class: org.ehcache.jsr107.Eh107Cache') + assertContentContains('testuser') cleanup: userCache.removeUserFromCache('testuser') } - void testEmptyUsercache() { + void testEmptyUserCache() { when: - go 'securityInfo/usercache' + browser.go('securityInfo/usercache') then: - assertContentContains 'UserCache class: org.ehcache.jsr107.Eh107Cache' - assertContentDoesNotContain'testuser' + assertContentContains('UserCache class: org.ehcache.jsr107.Eh107Cache') + assertContentDoesNotContain('testuser') } void testFilterChains() { when: - go 'securityInfo/filterChains' + browser.go('securityInfo/filterChains') then: - assertContentContains '/assets/**' - assertContentContains '/**/js/**' - assertContentContains '/**/css/**' - assertContentContains '/**/images/**' - assertContentContains '/**/favicon.ico' - assertContentContains '/**' - assertContentContains 'grails.plugin.springsecurity.web.SecurityRequestHolderFilter' - assertContentContains 'org.springframework.security.web.access.channel.ChannelProcessingFilter' - assertContentContains 'org.springframework.security.web.context.SecurityContextPersistenceFilter' - assertContentContains 'org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter' - assertContentContains 'grails.plugin.springsecurity.web.filter.GrailsRememberMeAuthenticationFilter' - assertContentContains 'grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter' - - assertContentContains 'org.springframework.security.web.access.intercept.FilterSecurityInterceptor' - assertContentContains 'grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter' - assertContentContains 'grails.plugin.springsecurity.web.authentication.GrailsUsernamePasswordAuthenticationFilter' - assertContentContains 'org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter' - assertContentContains 'grails.plugin.springsecurity.web.filter.GrailsRememberMeAuthenticationFilter' - assertContentContains 'grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter' - //assertContentContains 'org.springframework.security.web.access.ExceptionTranslationFilter' - assertContentContains 'org.springframework.security.web.access.intercept.FilterSecurityInterceptor' - assertContentContains 'org.springframework.security.web.authentication.switchuser.SwitchUserFilter' + assertContentContains('/assets/**') + assertContentContains('/**/js/**') + assertContentContains('/**/css/**') + assertContentContains('/**/images/**') + assertContentContains('/**/favicon.ico') + assertContentContains('/**') + assertContentContains('grails.plugin.springsecurity.web.SecurityRequestHolderFilter') + assertContentContains('org.springframework.security.web.access.channel.ChannelProcessingFilter') + assertContentContains('org.springframework.security.web.context.SecurityContextPersistenceFilter') + assertContentContains('org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter') + assertContentContains('grails.plugin.springsecurity.web.filter.GrailsRememberMeAuthenticationFilter') + assertContentContains('grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter') + + assertContentContains('org.springframework.security.web.access.intercept.FilterSecurityInterceptor') + assertContentContains('grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter') + assertContentContains('grails.plugin.springsecurity.web.authentication.GrailsUsernamePasswordAuthenticationFilter') + assertContentContains('org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter') + assertContentContains('grails.plugin.springsecurity.web.filter.GrailsRememberMeAuthenticationFilter') + assertContentContains('grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter') + assertContentContains('org.springframework.security.web.access.intercept.FilterSecurityInterceptor') + assertContentContains('org.springframework.security.web.authentication.switchuser.SwitchUserFilter') } void testLogoutHandlers() { when: - go 'securityInfo/logoutHandlers' + browser.go('securityInfo/logoutHandlers') then: - assertContentContains 'org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices' - assertContentContains 'org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler' + assertContentContains('org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices') + assertContentContains('org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler') } void testVoters() { when: - go 'securityInfo/voters' + browser.go('securityInfo/voters') then: - assertContentContains 'org.springframework.security.access.vote.AuthenticatedVoter' - assertContentContains 'org.springframework.security.access.vote.RoleHierarchyVoter' - assertContentContains 'grails.plugin.springsecurity.web.access.expression.WebExpressionVoter' + assertContentContains('org.springframework.security.access.vote.AuthenticatedVoter') + assertContentContains('org.springframework.security.access.vote.RoleHierarchyVoter') + assertContentContains('grails.plugin.springsecurity.web.access.expression.WebExpressionVoter') } void testProviders() { when: - go 'securityInfo/providers' + browser.go('securityInfo/providers') then: - assertContentContains 'org.springframework.security.authentication.dao.DaoAuthenticationProvider' - assertContentContains 'grails.plugin.springsecurity.authentication.GrailsAnonymousAuthenticationProvider' - assertContentContains 'org.springframework.security.authentication.RememberMeAuthenticationProvider' + assertContentContains('org.springframework.security.authentication.dao.DaoAuthenticationProvider') + assertContentContains('grails.plugin.springsecurity.authentication.GrailsAnonymousAuthenticationProvider') + assertContentContains('org.springframework.security.authentication.RememberMeAuthenticationProvider') } } diff --git a/examples/extended/src/integration-test/groovy/spec/PersistentLoginSpec.groovy b/examples/extended/src/integration-test/groovy/spec/PersistentLoginSpec.groovy index 939bc10d..ecaff733 100644 --- a/examples/extended/src/integration-test/groovy/spec/PersistentLoginSpec.groovy +++ b/examples/extended/src/integration-test/groovy/spec/PersistentLoginSpec.groovy @@ -2,71 +2,72 @@ package spec import grails.testing.mixin.integration.Integration import page.persistentLogin.PersistentLoginSearchPage -import spock.lang.Stepwise -@Stepwise @Integration class PersistentLoginSpec extends AbstractSecuritySpec { void testFindAll() { when: - to PersistentLoginSearchPage + def persistentLoginSearchPage = browser.to(PersistentLoginSearchPage) then: - assertNotSearched() + persistentLoginSearchPage.assertNotSearched() when: - submit() + persistentLoginSearchPage.submit() then: - at PersistentLoginSearchPage - assertResults 1, 10, 20 + browser.at(PersistentLoginSearchPage) + persistentLoginSearchPage.assertResults(1, 10, 20) } void testFindByUsername() { when: - to PersistentLoginSearchPage - username = '3' - submit() + def persistentLoginSearchPage = browser.to(PersistentLoginSearchPage).tap { + username = '3' + submit() + } then: - at PersistentLoginSearchPage - assertResults 1, 2, 2 + browser.at(PersistentLoginSearchPage) + persistentLoginSearchPage.assertResults(1, 2, 2) - assertContentContains 'persistent_login_test_3' - assertContentContains 'persistent_login_test_13' + assertContentContains('persistent_login_test_3') + assertContentContains('persistent_login_test_13') - assertContentContains 'series3' - assertContentContains 'series13' + assertContentContains('series3') + assertContentContains('series13') } void testFindByToken() { when: - to PersistentLoginSearchPage - token = '3' - submit() + def persistenLoginSearchPage = browser.to(PersistentLoginSearchPage).tap { + token = '3' + submit() + } then: - at PersistentLoginSearchPage - assertResults 1, 2, 2 + browser.at(PersistentLoginSearchPage) + persistenLoginSearchPage.assertResults(1, 2, 2) - assertContentContains 'token13' - assertContentContains 'token3' + assertContentContains('token13') + assertContentContains('token3') } void testFindBySeries() { when: - to PersistentLoginSearchPage - series = '4' - submit() + def persistentLoginSearchPage = browser.to(PersistentLoginSearchPage).tap { + series = '4' + submit() + } then: - at PersistentLoginSearchPage - assertResults 1, 2, 2 + browser.at(PersistentLoginSearchPage) + persistentLoginSearchPage.assertResults(1, 2, 2) - assertContentContains 'series4' - assertContentContains 'series14' - assertContentContains 'persistent_login_test_4' - assertContentContains 'persistent_login_test_14' + assertContentContains('series4') + assertContentContains('series14') + assertContentContains('persistent_login_test_4') + assertContentContains('persistent_login_test_14') } } diff --git a/examples/extended/src/integration-test/groovy/spec/RegisterSpec.groovy b/examples/extended/src/integration-test/groovy/spec/RegisterSpec.groovy index 7e4c78ff..add0d652 100644 --- a/examples/extended/src/integration-test/groovy/spec/RegisterSpec.groovy +++ b/examples/extended/src/integration-test/groovy/spec/RegisterSpec.groovy @@ -1,266 +1,220 @@ package spec -import com.dumbster.smtp.SimpleSmtpServer -import com.dumbster.smtp.SmtpMessage import grails.testing.mixin.integration.Integration -import org.springframework.test.annotation.DirtiesContext +import page.profile.ProfileCreatePage import page.profile.ProfileEditPage import page.profile.ProfileListPage import page.register.ForgotPasswordPage import page.register.RegisterPage +import page.register.ResetPasswordPage import page.register.SecurityQuestionsPage -import page.profile.ProfileCreatePage import page.user.UserEditPage import page.user.UserSearchPage -import page.register.ResetPasswordPage -import spock.lang.PendingFeature -import spock.lang.Stepwise -@DirtiesContext(classMode=DirtiesContext.ClassMode.BEFORE_CLASS) -@Stepwise @Integration class RegisterSpec extends AbstractSecuritySpec { - private SimpleSmtpServer server - - void setup() { - startMailServer() - } - - void cleanup() { - server.stop() - } - void testRegisterValidation() { when: - to RegisterPage - submit() + def registerPage = browser.to(RegisterPage).tap { + submit() + } then: - assertContentContains 'Username is required' - assertContentContains 'Email is required' - assertContentContains 'Password is required' + assertContentContains('Username is required') + assertContentContains('Email is required') + assertContentContains('Password is required') when: - username = 'admin' - email = 'foo' - $('#password') << 'abcdefghijk' - $('#password2') << 'mnopqrstuwzy' - submit() + registerPage.with { + username = 'admin' + email = 'foo' + password = 'abcdefghijk' + password2 = 'mnopqrstuwzy' + submit() + } then: - assertContentContains 'The username is taken' - assertContentContains 'Please provide a valid email address' - assertContentContains 'Password must have at least one letter, number, and special character: !@#$%^&' - assertContentContains 'Passwords do not match' + assertContentContains('The username is taken') + assertContentContains('Please provide a valid email address') + assertContentContains('Password must have at least one letter, number, and special character: !@#$%^&') + assertContentContains('Passwords do not match') when: - username = 'abcdef123' - email = 'abcdef@abcdef.com' - $('#password') << 'aaaaaaaa' - $('#password2') << 'aaaaaaaa' - submit() + registerPage.with { + username = 'abcdef123' + email = 'abcdef@abcdef.com' + password = 'aaaaaaaa' + password2 = 'aaaaaaaa' + submit() + } then: - assertContentContains 'Password must have at least one letter, number, and special character: !@#$%^&' - + assertContentContains('Password must have at least one letter, number, and special character: !@#$%^&') } void testForgotPasswordValidation() { when: - to ForgotPasswordPage - submit() + def forgotPasswordPage = browser.to(ForgotPasswordPage).tap { + submit() + } then: - assertContentContains 'Please enter your username' + assertContentContains('Please enter your username') when: - username = '1111' - submit() + forgotPasswordPage.with { + username = '1111' + submit() + } then: - assertContentContains 'No user was found with that username' + assertContentContains('No user was found with that username') } - // FIXME - @DirtiesContext - @PendingFeature(reason="test is failing at deleteProfile stage") void testRegisterAndForgotPassword() { - given: - String un = 'test_user_abcdef' + System.currentTimeMillis() + String un = "test_user_abcdef${System.currentTimeMillis()}" + when: - go 'register/resetPassword?t=123' + browser.go('register/resetPassword?t=123') then: - assertHtmlContains 'Sorry, we have no record of that request, or it has expired' + assertHtmlContains('Sorry, we have no record of that request, or it has expired') when: - to RegisterPage + def registerPage = browser.to(RegisterPage) then: - at RegisterPage + browser.at(RegisterPage) when: - username = un - email = un + '@abcdef.com' - $('#password') << 'aaaaaa1#' - $('#password2') << 'aaaaaa1#' - submit() - + registerPage.with { + username = un + email = "$un@abcdef.com" + password = 'aaaaaa1#' + password2 = 'aaaaaa1#' + submit() + } then: - assertHtmlContains 'Your registration is complete' - + assertHtmlContains('Your registration is complete') when: - to ProfileCreatePage - create(un) + browser.to(ProfileCreatePage).with { + create(un) + } then: - at ProfileListPage - assertHtmlContains 'created' + def profileListPage = browser.at(ProfileListPage) + assertHtmlContains('created') when: - $("a", text: "User(username:"+un+")").parent().parent().children().first().children('a').click() + profileListPage.editProfile(un) then: - at ProfileEditPage + def profileEditPage = browser.at(ProfileEditPage) when: - updateProfile(un) + profileEditPage.updateProfile(un) then: - at ProfileListPage - assertHtmlContains "updated" + browser.at(ProfileListPage) + assertHtmlContains('updated') when: logout() - go '' + browser.go('') then: - assertContentContains 'Log in' + assertContentContains('Log in') when: - to ForgotPasswordPage - username = un - submit() + browser.to(ForgotPasswordPage).with { + username = un + submit() + } then: - at SecurityQuestionsPage - + def securityQuestionPage = browser.at(SecurityQuestionsPage) when: - question1 = '1234' - question2 = '12345' - submit() + securityQuestionPage.with { + question1 = '1234' + question2 = '12345' + submit() + } then: - at ResetPasswordPage + def resetPasswordPage = browser.at(ResetPasswordPage) when: - submit() + resetPasswordPage.submit() then: - assertContentContains 'Password is required' + assertContentContains('Password is required') when: - enterNewPassword('abcdefghijk','mnopqrstuwzy') + resetPasswordPage.enterNewPassword('abcdefghijk','mnopqrstuwzy') then: - assertContentContains 'Password must have at least one letter, number, and special character: !@#$%^&' - assertContentContains 'Passwords do not match' + assertContentContains('Password must have at least one letter, number, and special character: !@#$%^&') + assertContentContains('Passwords do not match') when: - enterNewPassword('aaaaaaaa','aaaaaaaa') + resetPasswordPage.enterNewPassword('aaaaaaaa', 'aaaaaaaa') then: - assertContentContains 'Password must have at least one letter, number, and special character: !@#$%^&' + assertContentContains('Password must have at least one letter, number, and special character: !@#$%^&') when: - enterNewPassword('aaaaaa1#','aaaaaa1#') + resetPasswordPage.enterNewPassword('aaaaaa1#', 'aaaaaa1#') then: - assertHtmlContains 'Your password was successfully changed' + assertHtmlContains('Your password was successfully changed') when: logout() - go '' + browser.go('') then: - assertContentContains 'Log in' + assertContentContains('Log in') when: - to ProfileListPage + browser.to(ProfileListPage) then: - at ProfileListPage + browser.at(ProfileListPage) when: - $("a", text: "User(username:"+un+")").parent().parent().children().first().children('a').click() + profileListPage.editProfile(un) then: - at ProfileEditPage + def profileEditPage2 = browser.at(ProfileEditPage) when: - deleteProfile() + profileEditPage2.deleteProfile() then: - assertHtmlContains 'deleted' + assertHtmlContains('deleted') when: - go 'user/edit?username=' + un + browser.go("user/edit?username=$un") then: - at UserEditPage - username == un + def userEditPage = browser.at(UserEditPage) + userEditPage.username.text == un when: - delete() + userEditPage.delete() then: - at UserSearchPage + browser.at(UserSearchPage) when: - go 'user/edit?username=' + un + browser.go("user/edit?username=$un") then: - assertHtmlContains 'User not found' - } - - private SmtpMessage getCurrentEmail() { - def received = server.receivedEmail - def email - while (received.hasNext()) { - email = received.next() - } - email - } - - private String findCode(String body, String action) { - def matcher = body =~ /(?s).*$action\?t=(.+)".*/ - assert matcher.hasGroup() - assert matcher.count == 1 - matcher[0][1] - } - - private void startMailServer() { - - int port = 1025 - while (true) { - try { - new ServerSocket(port).close() - break - } - catch (IOException e) { - port++ - assert port < 2000, 'cannot find open port' - } - } - - server = SimpleSmtpServer.start(port) - - go 'testData/updateMailSenderPort?port=' + port - assertContentContains 'OK: ' + port + assertHtmlContains('User not found') } -} +} \ No newline at end of file diff --git a/examples/extended/src/integration-test/groovy/spec/RegistrationCodeSpec.groovy b/examples/extended/src/integration-test/groovy/spec/RegistrationCodeSpec.groovy index f6e4a26f..e083ef0e 100644 --- a/examples/extended/src/integration-test/groovy/spec/RegistrationCodeSpec.groovy +++ b/examples/extended/src/integration-test/groovy/spec/RegistrationCodeSpec.groovy @@ -3,80 +3,82 @@ package spec import grails.testing.mixin.integration.Integration import page.registrationCode.RegistrationCodeEditPage import page.registrationCode.RegistrationCodeSearchPage -import spock.lang.Stepwise -@Stepwise @Integration class RegistrationCodeSpec extends AbstractSecuritySpec { void testFindAll() { when: - to RegistrationCodeSearchPage + def registrationCodeSearchPage = browser.to(RegistrationCodeSearchPage) then: - assertNotSearched() + registrationCodeSearchPage.assertNotSearched() when: - submit() + registrationCodeSearchPage.submit() then: - at RegistrationCodeSearchPage - assertResults 1, 10, 14 - assertContentContains 'registration_test_2' - assertContentContains '0a154624f36d42e4aa68991a9477bd04' + browser.at(RegistrationCodeSearchPage) + registrationCodeSearchPage.assertResults(1, 10, 14) + assertContentContains('registration_test_2') + assertContentContains('0a154624f36d42e4aa68991a9477bd04') } void testFindByToken() { when: - to RegistrationCodeSearchPage - token = '4a7f88afec3746f7aab2f5d0d8df6d8e' - submit() + def registrationCodeSearchPage = browser.to(RegistrationCodeSearchPage).tap { + token = '4a7f88afec3746f7aab2f5d0d8df6d8e' + submit() + } then: - at RegistrationCodeSearchPage - assertResults 1, 1, 1 - assertContentContains 'registration_test_1' - assertContentContains '4a7f88afec3746f7aab2f5d0d8df6d8e' + browser.at(RegistrationCodeSearchPage) + registrationCodeSearchPage.assertResults(1, 1, 1) + assertContentContains('registration_test_1') + assertContentContains('4a7f88afec3746f7aab2f5d0d8df6d8e') } void testFindByUsername() { when: - to RegistrationCodeSearchPage - username = 'registration_test_3' - submit() + def registrationCodeSearchPage = browser.to(RegistrationCodeSearchPage).tap { + username = 'registration_test_3' + submit() + } then: - at RegistrationCodeSearchPage - assertResults 1, 5, 5 - assertContentContains 'registration_test_3' - assertContentContains '89f9bbc658b14808ae4c77c6e17e551a' + browser.at(RegistrationCodeSearchPage) + registrationCodeSearchPage.assertResults(1, 5, 5) + assertContentContains('registration_test_3') + assertContentContains('89f9bbc658b14808ae4c77c6e17e551a') } void testEdit() { when: - go 'registrationCode/edit/4' + browser.go('registrationCode/edit/4') then: - at RegistrationCodeEditPage - username == 'registration_test_1' - token == 'a50e061e0e2f424fb7fbc2ff3dae597d' + def registrationCodeEditPage = browser.at(RegistrationCodeEditPage) + registrationCodeEditPage.username.text == 'registration_test_1' + registrationCodeEditPage.token.text == 'a50e061e0e2f424fb7fbc2ff3dae597d' when: - username = 'new_user' - token = 'new_token' - submit() + registrationCodeEditPage.with { + username = 'new_user' + token = 'new_token' + submit() + } then: - at RegistrationCodeEditPage - username == 'new_user' - token == 'new_token' + browser.at(RegistrationCodeEditPage) + registrationCodeEditPage.username.text == 'new_user' + registrationCodeEditPage.token.text == 'new_token' when: - go 'registrationCode/edit/4' + browser.go('registrationCode/edit/4') then: - at RegistrationCodeEditPage - username == 'new_user' - token == 'new_token' + browser.at(RegistrationCodeEditPage) + registrationCodeEditPage.username.text == 'new_user' + registrationCodeEditPage.token.text == 'new_token' } } diff --git a/examples/extended/src/integration-test/groovy/spec/RequestmapSpec.groovy b/examples/extended/src/integration-test/groovy/spec/RequestmapSpec.groovy index 1d745abd..fc74adf9 100644 --- a/examples/extended/src/integration-test/groovy/spec/RequestmapSpec.groovy +++ b/examples/extended/src/integration-test/groovy/spec/RequestmapSpec.groovy @@ -4,117 +4,120 @@ import grails.testing.mixin.integration.Integration import page.requestmap.RequestmapCreatePage import page.requestmap.RequestmapEditPage import page.requestmap.RequestmapSearchPage -import spock.lang.Stepwise -@Stepwise @Integration class RequestmapSpec extends AbstractSecuritySpec { void testFindAll() { when: - to RequestmapSearchPage + def requestmapSearchPage = browser.to(RequestmapSearchPage) then: - assertNotSearched() + requestmapSearchPage.assertNotSearched() when: - submit() + requestmapSearchPage.submit() then: - at RequestmapSearchPage - assertResults 1, 3, 3 - assertContentContains '/secure/**' - assertContentContains 'ROLE_ADMIN' - assertContentContains '/j_spring_security_switch_user' - assertContentContains 'ROLE_RUN_AS' - assertContentContains '/**' - assertContentContains 'permitAll' + browser.at(RequestmapSearchPage) + requestmapSearchPage.assertResults(1, 3, 3) + assertContentContains('/secure/**') + assertContentContains('ROLE_ADMIN') + assertContentContains('/j_spring_security_switch_user') + assertContentContains('ROLE_RUN_AS') + assertContentContains('/**') + assertContentContains('permitAll') } void testFindByConfigAttribute() { when: - to RequestmapSearchPage - configAttribute = 'run' - submit() + def requestmapSearchPage = browser.to(RequestmapSearchPage).tap { + configAttribute = 'run' + submit() + } then: - at RequestmapSearchPage - assertResults 1, 1, 1 - assertContentContains '/j_spring_security_switch_user' - assertContentContains 'ROLE_RUN_AS' + browser.at(RequestmapSearchPage) + requestmapSearchPage.assertResults(1, 1, 1) + assertContentContains('/j_spring_security_switch_user') + assertContentContains('ROLE_RUN_AS') } void testFindByUrl() { when: - to RequestmapSearchPage - urlPattern = 'secure' - submit() + def requestmapSearchPage = browser.to(RequestmapSearchPage).tap { + urlPattern = 'secure' + submit() + } then: - at RequestmapSearchPage - assertResults 1, 1, 1 - assertContentContains '/secure/**' - assertContentContains 'ROLE_ADMIN' + browser.at(RequestmapSearchPage) + requestmapSearchPage.assertResults(1, 1, 1) + assertContentContains('/secure/**') + assertContentContains('ROLE_ADMIN') } void testUniqueUrl() { when: - to RequestmapCreatePage - urlPattern = '/secure/**' - configAttribute = 'ROLE_FOO' - submit() + def requestmapCreatePage = browser.to(RequestmapCreatePage).tap { + urlPattern = '/secure/**' + configAttribute = 'ROLE_FOO' + submit() + } then: - at RequestmapCreatePage - assertNotUnique() + browser.at(RequestmapCreatePage) + requestmapCreatePage.assertNotUnique() } void testCreateAndEdit() { given: - String newPattern = '/foo/' + UUID.randomUUID() + String newPattern = "/foo/${UUID.randomUUID()}" // make sure it doesn't exist when: - to RequestmapSearchPage - urlPattern = newPattern - submit() + def requestmapSearchPage = browser.to(RequestmapSearchPage).tap { + urlPattern = newPattern + submit() + } then: - assertNoResults() + requestmapSearchPage.assertNoResults() // create when: - to RequestmapCreatePage - urlPattern = newPattern - configAttribute = 'ROLE_FOO' - submit() + browser.to(RequestmapCreatePage).with { + urlPattern = newPattern + configAttribute = 'ROLE_FOO' + submit() + } then: - at RequestmapEditPage - urlPattern == newPattern + def requestmapEditPage = browser.at(RequestmapEditPage) + requestmapSearchPage.urlPattern.text == newPattern // edit when: - urlPattern = newPattern + '/new' - submit() + requestmapEditPage.urlPattern = "${newPattern}/new" + requestmapEditPage.submit() then: - at RequestmapEditPage - urlPattern == newPattern + '/new' + browser.at(RequestmapEditPage) + requestmapEditPage.urlPattern.text == "${newPattern}/new" // delete when: - delete() + requestmapEditPage.delete() then: - at RequestmapSearchPage + browser.at(RequestmapSearchPage) when: - urlPattern = newPattern + '/new' - submit() + requestmapSearchPage.urlPattern = "${newPattern}/new" + requestmapSearchPage.submit() then: - at RequestmapSearchPage - assertNoResults() + browser.at(RequestmapSearchPage) + requestmapSearchPage.assertNoResults() } } diff --git a/examples/extended/src/integration-test/groovy/spec/RoleSpec.groovy b/examples/extended/src/integration-test/groovy/spec/RoleSpec.groovy index 18074c65..225114da 100644 --- a/examples/extended/src/integration-test/groovy/spec/RoleSpec.groovy +++ b/examples/extended/src/integration-test/groovy/spec/RoleSpec.groovy @@ -4,92 +4,94 @@ import grails.testing.mixin.integration.Integration import page.role.RoleCreatePage import page.role.RoleEditPage import page.role.RoleSearchPage -import spock.lang.Stepwise -@Stepwise @Integration class RoleSpec extends AbstractSecuritySpec { void testFindAll() { when: - to RoleSearchPage + def roleSearchPage = browser.to(RoleSearchPage) then: - assertNotSearched() + roleSearchPage.assertNotSearched() when: - submit() + roleSearchPage.submit() then: - at RoleSearchPage - assertResults 1, 10, 12 - assertContentContains 'ROLE_COFFEE' + browser.at(RoleSearchPage) + roleSearchPage.assertResults(1, 10, 12) + assertContentContains('ROLE_COFFEE') } void testFindByAuthority() { when: - to RoleSearchPage - search 'ad' + def roleSearchPage = browser.to(RoleSearchPage).tap { + search('ad') + } then: - at RoleSearchPage - assertResults 1, 2, 2 + browser.at(RoleSearchPage) + roleSearchPage.assertResults(1, 2, 2) - assertContentContains 'ROLE_ADMIN' - assertContentContains 'ROLE_INSTEAD' + assertContentContains('ROLE_ADMIN') + assertContentContains('ROLE_INSTEAD') } void testUniqueName() { when: - to RoleCreatePage - create 'ROLE_ADMIN' + def roleCreatePage = browser.to(RoleCreatePage).tap { + create('ROLE_ADMIN') + } then: - at RoleCreatePage - assertNotUnique() + browser.at(RoleCreatePage) + roleCreatePage.assertNotUnique() } void testCreateAndEdit() { given: - String newName = 'ROLE_NEW_TEST' + UUID.randomUUID() + String newName = "ROLE_NEW_TEST${UUID.randomUUID()}" // make sure it doesn't exist when: - to RoleSearchPage - search newName + def roleSearchPage = browser.to(RoleSearchPage).tap { + search(newName) + } then: - assertNoResults() + roleSearchPage.assertNoResults() // create when: - to RoleCreatePage - create newName + browser.to(RoleCreatePage).with { + create(newName) + } then: - at RoleEditPage - authority == newName + def roleEditPage = browser.at(RoleEditPage) + roleEditPage.authority.text == newName // edit when: - update newName + '_new' + roleEditPage.update("${newName}_new") then: - at RoleEditPage - authority == newName + '_new' + browser.at(RoleEditPage) + roleEditPage.authority.text == "${newName}_new" // delete when: - delete() + roleEditPage.delete() then: - at RoleSearchPage + browser.at(RoleSearchPage) when: - search newName + '_new' + roleSearchPage.search("${newName}_new") then: - at RoleSearchPage - assertNoResults() + browser.at(RoleSearchPage) + roleSearchPage.assertNoResults() } } diff --git a/examples/extended/src/integration-test/groovy/spec/UserSpec.groovy b/examples/extended/src/integration-test/groovy/spec/UserSpec.groovy index bea9f9d0..43a27e1d 100644 --- a/examples/extended/src/integration-test/groovy/spec/UserSpec.groovy +++ b/examples/extended/src/integration-test/groovy/spec/UserSpec.groovy @@ -4,167 +4,173 @@ import grails.testing.mixin.integration.Integration import page.user.UserCreatePage import page.user.UserEditPage import page.user.UserSearchPage -import spock.lang.Stepwise -@Stepwise @Integration class UserSpec extends AbstractSecuritySpec { void testFindAll() { when: - to UserSearchPage + def userSearchPage = browser.to(UserSearchPage) then: - assertNotSearched() + userSearchPage.assertNotSearched() when: - submit() + userSearchPage.submit() then: - at UserSearchPage - assertResults 1, 10, 22 + browser.at(UserSearchPage) + userSearchPage.assertResults(1, 10, 22) } void testFindByUsername() { when: - to UserSearchPage - - username = 'foo' - submit() + def userSearchPage = browser.to(UserSearchPage).tap { + username = 'foo' + submit() + } then: - at UserSearchPage - assertResults 1, 3, 3 + browser.at(UserSearchPage) + userSearchPage.assertResults(1, 3, 3) - assertContentContains 'foon_2' - assertContentContains 'foolkiller' - assertContentContains 'foostra' + assertContentContains('foon_2') + assertContentContains('foolkiller') + assertContentContains('foostra') } void testFindByDisabled() { when: - to UserSearchPage + def userSearchPage = browser.to(UserSearchPage) - enabled.checked = '-1' - submit() + // Temporary workaround for problem with Geb RadioButtons module + //userSearchPage.enabled.checked = '-1' + browser.$('input', type: 'radio', name: 'enabled', value: '-1').click() + userSearchPage.submit() then: - at UserSearchPage - assertResults 1, 1, 1 - assertContentContains 'billy9494' + browser.at(UserSearchPage) + userSearchPage.assertResults(1, 1, 1) + assertContentContains('billy9494') } void testFindByAccountExpired() { when: - to UserSearchPage - - accountExpired.checked = '1' + def userSearchPage = browser.to(UserSearchPage) - submit() + // Temporary workaround for problem with Geb RadioButtons module + //userSearchPage.accountExpired.checked = '1' + browser.$('input', type: 'radio', name: 'accountExpired', value: '1').click() + userSearchPage.submit() then: - at UserSearchPage - assertResults 1, 3, 3 - assertContentContains 'maryrose' - assertContentContains 'ratuig' - assertContentContains 'rome20c' + browser.at(UserSearchPage) + userSearchPage.assertResults(1, 3, 3) + assertContentContains('maryrose') + assertContentContains('ratuig') + assertContentContains('rome20c') } void testFindByAccountLocked() { when: - to UserSearchPage - - accountLocked.checked = '1' + def userSearchPage = browser.to(UserSearchPage) - submit() + // Temporary workaround for problem with Geb RadioButtons module + //userSearchPage.accountLocked.checked = '1' + browser.$('input', type: 'radio', name: 'accountLocked', value: '1').click() + userSearchPage.submit() then: - at UserSearchPage - assertResults 1, 3, 3 - assertContentContains 'aaaaaasd' - assertContentContains 'achen' - assertContentContains 'szhang1999' + browser.at(UserSearchPage) + userSearchPage.assertResults(1, 3, 3) + assertContentContains('aaaaaasd') + assertContentContains('achen') + assertContentContains('szhang1999') } void testFindByPasswordExpired() { when: - to UserSearchPage + def userSearchPage = browser.to(UserSearchPage) - passwordExpired.checked = '1' - - submit() + // Temporary workaround for problem with Geb RadioButtons module + //userSearchPage.passwordExpired.checked = '1' + browser.$('input', type: 'radio', name: 'passwordExpired', value: '1').click() + userSearchPage.submit() then: - at UserSearchPage - assertResults 1, 3, 3 - assertContentContains 'hhheeeaaatt' - assertContentContains 'mscanio' - assertContentContains 'kittal' + browser.at(UserSearchPage) + userSearchPage.assertResults(1, 3, 3) + assertContentContains('hhheeeaaatt') + assertContentContains('mscanio') + assertContentContains('kittal') } void testCreateAndEdit() { given: - String newUsername = 'newuser' + UUID.randomUUID() + String newUsername = "newuser${UUID.randomUUID()}" // make sure it doesn't exist when: - to UserSearchPage - - username = newUsername - submit() + def userSearchPage = browser.to(UserSearchPage).tap { + username = newUsername + submit() + } then: - at UserSearchPage - assertNoResults() + browser.at(UserSearchPage) + userSearchPage.assertNoResults() // create when: - to UserCreatePage + browser.to(UserCreatePage).with { + username = newUsername + password = 'password' + enabled.check() + submit() + } - username = newUsername - $('#password') << 'password' - enabled.check() - submit() then: - at UserEditPage - username == newUsername - enabled.checked - !accountExpired.checked - !accountLocked.checked - !passwordExpired.checked + def userEditPage = browser.at(UserEditPage) + userEditPage.username.text == newUsername + userEditPage.enabled.checked + !userEditPage.accountExpired.checked + !userEditPage.accountLocked.checked + !userEditPage.passwordExpired.checked // edit when: - String updatedName = newUsername + '_updated' - username = updatedName - enabled.uncheck() - accountExpired.check() - accountLocked.check() - passwordExpired.check() - submit() + String updatedName = "${newUsername}_updated" + userEditPage.with { + username = updatedName + enabled.uncheck() + accountExpired.check() + accountLocked.check() + passwordExpired.check() + submit() + } then: - at UserEditPage - username == updatedName - !enabled.checked - accountExpired.checked - accountLocked.checked - passwordExpired.checked + browser.at(UserEditPage) + userEditPage.username.text == updatedName + !userEditPage.enabled.checked + userEditPage.accountExpired.checked + userEditPage.accountLocked.checked + userEditPage.passwordExpired.checked // delete when: - delete() + userEditPage.delete() then: - at UserSearchPage + browser.at(UserSearchPage) when: - username = updatedName - submit() + userSearchPage.username = updatedName + userSearchPage.submit() then: - at UserSearchPage - assertNoResults() + browser.at(UserSearchPage) + userSearchPage.assertNoResults() } } diff --git a/examples/extended/src/integration-test/groovy/test/ProfileServiceSpec.groovy b/examples/extended/src/integration-test/groovy/test/ProfileServiceSpec.groovy index c0e784b3..6cc0355c 100644 --- a/examples/extended/src/integration-test/groovy/test/ProfileServiceSpec.groovy +++ b/examples/extended/src/integration-test/groovy/test/ProfileServiceSpec.groovy @@ -2,50 +2,35 @@ package test import grails.gorm.transactions.Rollback import grails.testing.mixin.integration.Integration -import grails.testing.services.ServiceUnitTest -import org.spockframework.runtime.model.SpecInfo import spock.lang.Specification import org.hibernate.SessionFactory -import spock.lang.Stepwise -@Stepwise -@Integration @Rollback +@Integration class ProfileServiceSpec extends Specification { ProfileService profileService SessionFactory sessionFactory - private Long setupData() { - } - - void "test get"() { - setupData() - + void 'test get'() { expect: profileService.get(1) != null } - void "test list"() { - setupData() - + void 'test list'() { when: - List profileList = profileService.list(max: 2, offset: 2) + def profileList = profileService.list(max: 2, offset: 2) then: profileList.size() == 2 - } - void "test count"() { - setupData() - + void 'test count'() { expect: profileService.count() == 4 } - void "test delete"() { - + void 'test delete'() { expect: profileService.count() == 4 @@ -57,10 +42,15 @@ class ProfileServiceSpec extends Specification { profileService.count() == 3 } - void "test save"() { + void 'test save'() { when: - - Profile profile = new Profile(user:User.findByUsername("foon_2"),myAnswer1:'1234',myQuestion1: "Count to four",myAnswer2: '12345', myQuestion2: 'Count to Five') + def profile = new Profile( + user: User.findByUsername('foon_2'), + myAnswer1: '1234', + myQuestion1: 'Count to four', + myAnswer2: '12345', + myQuestion2: 'Count to Five' + ) profileService.save(profile) then: diff --git a/examples/extended/src/test/groovy/test/ProfileListenerServiceSpec.groovy b/examples/extended/src/test/groovy/test/ProfileListenerServiceSpec.groovy index 244381f1..af264ba6 100644 --- a/examples/extended/src/test/groovy/test/ProfileListenerServiceSpec.groovy +++ b/examples/extended/src/test/groovy/test/ProfileListenerServiceSpec.groovy @@ -1,6 +1,6 @@ package test - +import grails.plugin.springsecurity.SpringSecurityService import grails.testing.gorm.DataTest import grails.testing.services.ServiceUnitTest import org.grails.datastore.mapping.engine.event.PreInsertEvent @@ -11,27 +11,38 @@ import spock.lang.Specification class ProfileListenerServiceSpec extends Specification implements ServiceUnitTest, DataTest { def setupSpec() { - mockDomain Profile - mockDomain User + mockDomain(Profile) + mockDomain(User) } Closure doWithSpring() {{ -> // <1> - springSecurityService(grails.plugin.springsecurity.SpringSecurityService) - + springSecurityService(SpringSecurityService) }} @Rollback - void "test my answer is encoded on insert"() { + void 'test my answer is encoded on insert'() { given: - User u = new User(username: "adminTest",password: "pass",email: "test@user.com",accountLocked: false,accountExpired: false) - Profile prof = new Profile(myQuestion2: 'Practical Grails 3', myQuestion1: 'Eric Helgeson', myAnswer2: "12345", myAnswer1: "1234", user: u) + User u = new User( + username: 'adminTest', + password: 'pass', + email: 'test@user.com', + accountLocked: false, + accountExpired: false + ) + Profile prof = new Profile( + myQuestion2: 'Practical Grails 3', + myQuestion1: 'Eric Helgeson', + myAnswer2: '12345', + myAnswer1: '1234', + user: u + ) when: - service.springSecurityService = Stub(grails.plugin.springsecurity.SpringSecurityService) { + service.springSecurityService = Stub(SpringSecurityService) { encodePassword(_ as String) >> 'XXXX-5125' } - service.onProfilePreInsert(new PreInsertEvent(dataStore, prof)) + service.onProfilePreInsert(new PreInsertEvent(datastore, prof)) then: prof.myAnswer1 == 'XXXX-5125' @@ -39,24 +50,35 @@ class ProfileListenerServiceSpec extends Specification implements ServiceUnitTes } @Rollback - void "test my answer is encoded on update"() { + void 'test my answer is encoded on update'() { given: - User u = new User(username: "adminTest",password: "pass",email: "test@user.com",accountLocked: false,accountExpired: false) - Profile prof = new Profile(myQuestion2: 'Practical Grails 3', myQuestion1: 'Eric Helgeson', myAnswer2: "12345", myAnswer1: "1234", user: u) + User u = new User( + username: 'adminTest', + password: 'pass', + email: 'test@user.com', + accountLocked: false, + accountExpired: false + ) + Profile prof = new Profile( + myQuestion2: 'Practical Grails 3', + myQuestion1: 'Eric Helgeson', + myAnswer2: '12345', + myAnswer1: '1234', + user: u + ) when: - - service.springSecurityService = Stub(grails.plugin.springsecurity.SpringSecurityService) { - encodePassword(_ as String) >> { - args -> args[0] + 'XXXX-5125' + service.springSecurityService = Stub(SpringSecurityService) { + encodePassword(_ as String) >> { args -> + args[0] + 'XXXX-5125' } } - prof.save(flush:true) - service.onProfilePreInsert(new PreInsertEvent(dataStore, prof)) + prof.save(flush: true) + service.onProfilePreInsert(new PreInsertEvent(datastore, prof)) - prof.myAnswer2 = "1232321344" - service.onProfilePreUpdate(new PreUpdateEvent(dataStore, prof)) + prof.myAnswer2 = '1232321344' + service.onProfilePreUpdate(new PreUpdateEvent(datastore, prof)) then: prof.myAnswer2 == '1232321344XXXX-5125' diff --git a/examples/simple/src/integration-test/groovy/module/RolesTab.groovy b/examples/simple/src/integration-test/groovy/module/RolesTab.groovy index 6d2532d9..96e2e75c 100644 --- a/examples/simple/src/integration-test/groovy/module/RolesTab.groovy +++ b/examples/simple/src/integration-test/groovy/module/RolesTab.groovy @@ -9,16 +9,16 @@ import geb.navigator.Navigator class RolesTab extends Module { static content = { - tab { $("a", href: "#tab-roles") } + tab { $('a', href: '#tab-roles') } } void select() { tab.click() - waitFor { $("li", "aria-controls": "tab-roles", "aria-selected": "true") } + waitFor { $('li', 'aria-controls': 'tab-roles', 'aria-selected': 'true') } } int totalRoles() { - return $("input", type: "checkbox", id: startsWith("ROLE_")).size().toInteger() + return $('input', type: 'checkbox', id: startsWith('ROLE_')).size().toInteger() } int totalEnabledRoles() { @@ -26,15 +26,15 @@ class RolesTab extends Module { } Navigator findAllEnabledRoles() { - return $("input", type: "checkbox", id: startsWith("ROLE_"), checked: "checked") + return $('input', type: 'checkbox', id: startsWith('ROLE_'), checked: 'checked') } void enableRole(String roleName) { - $("input", type: "checkbox", id: roleName).value(true) + $('input', type: 'checkbox', id: roleName).value(true) } void disableRole(String roleName) { - $("input", type: "checkbox", id: roleName).value(false) + $('input', type: 'checkbox', id: roleName).value(false) } boolean hasEnabledRole(String roleName) { @@ -44,6 +44,4 @@ class RolesTab extends Module { boolean hasEnabledRoles(List roleNames) { return findAllEnabledRoles().collect { it.attr('id') }.containsAll(roleNames) } - - } diff --git a/examples/simple/src/integration-test/groovy/page/AbstractSecurityPage.groovy b/examples/simple/src/integration-test/groovy/page/AbstractSecurityPage.groovy index a334d9f1..69ed76b7 100644 --- a/examples/simple/src/integration-test/groovy/page/AbstractSecurityPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/AbstractSecurityPage.groovy @@ -5,7 +5,7 @@ import geb.Page abstract class AbstractSecurityPage extends Page { void submit() { - submit.click() + submitBtn.click() } protected boolean assertContentContains(String expected) { diff --git a/examples/simple/src/integration-test/groovy/page/CreatePage.groovy b/examples/simple/src/integration-test/groovy/page/CreatePage.groovy index dbf4b642..b96e723c 100644 --- a/examples/simple/src/integration-test/groovy/page/CreatePage.groovy +++ b/examples/simple/src/integration-test/groovy/page/CreatePage.groovy @@ -2,11 +2,10 @@ package page abstract class CreatePage extends AbstractSecurityPage { - static at = { title == 'Create ' + typeName() } - + static at = { title == "Create ${typeName()}" } static content = { form { $('createForm') } - submit { $('a', id: 'create') } + submitBtn { $('a', id: 'create') } } boolean assertNotUnique() { diff --git a/examples/simple/src/integration-test/groovy/page/EditPage.groovy b/examples/simple/src/integration-test/groovy/page/EditPage.groovy index 248e4ec3..f9ff6b27 100644 --- a/examples/simple/src/integration-test/groovy/page/EditPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/EditPage.groovy @@ -2,14 +2,13 @@ package page abstract class EditPage extends AbstractSecurityPage { - static at = { title == 'Edit ' + typeName() } - + static at = { title == "Edit ${typeName()}" } static content = { form { $('editForm') } - submit { $('a', id: 'update') } + submitBtn { $('a', id: 'update') } } void delete() { - js.exec 'document.forms.deleteForm.submit()' + js.exec('document.forms.deleteForm.submit()') } } diff --git a/examples/simple/src/integration-test/groovy/page/SearchPage.groovy b/examples/simple/src/integration-test/groovy/page/SearchPage.groovy index 090f6a30..4b17f534 100644 --- a/examples/simple/src/integration-test/groovy/page/SearchPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/SearchPage.groovy @@ -2,30 +2,28 @@ package page abstract class SearchPage extends AbstractSecurityPage { - static at = { title == typeName() + ' Search' } - + static at = { title == "${typeName()} Search" } static atCheckWaiting = true - static content = { form { $('search') } - submit { $('a', id: 'searchButton') } + submitBtn { $('a', id: 'searchButton') } } boolean assertNoResults() { - assertContentContains 'No results' - assertContentDoesNotContain 'Showing' + assertContentContains('No results') + assertContentDoesNotContain('Showing') true } boolean assertNotSearched() { - assertContentContains 'Search' - assertContentDoesNotContain 'No results' - assertContentDoesNotContain 'Showing' + assertContentContains('Search') + assertContentDoesNotContain('No results') + assertContentDoesNotContain('Showing') true } boolean assertResults(int start, int end, int total) { - assertContentContains "Showing $start through $end out of ${total}." + assertContentContains("Showing $start through $end out of ${total}.") true } } diff --git a/examples/simple/src/integration-test/groovy/page/aclClass/AclClassCreatePage.groovy b/examples/simple/src/integration-test/groovy/page/aclClass/AclClassCreatePage.groovy index 1e53baef..3282b59f 100644 --- a/examples/simple/src/integration-test/groovy/page/aclClass/AclClassCreatePage.groovy +++ b/examples/simple/src/integration-test/groovy/page/aclClass/AclClassCreatePage.groovy @@ -6,9 +6,7 @@ import page.CreatePage class AclClassCreatePage extends CreatePage { static url = 'aclClass/create' - static typeName = { 'AclClass' } - static content = { className { $(name: 'className').module(TextInput) } } diff --git a/examples/simple/src/integration-test/groovy/page/aclClass/AclClassEditPage.groovy b/examples/simple/src/integration-test/groovy/page/aclClass/AclClassEditPage.groovy index ccd604f6..91597281 100644 --- a/examples/simple/src/integration-test/groovy/page/aclClass/AclClassEditPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/aclClass/AclClassEditPage.groovy @@ -6,9 +6,7 @@ import page.EditPage class AclClassEditPage extends EditPage { static url = 'aclClass/edit' - static typeName = { 'AclClass' } - static content = { className { $(name: 'className').module(TextInput) } } diff --git a/examples/simple/src/integration-test/groovy/page/aclClass/AclClassSearchPage.groovy b/examples/simple/src/integration-test/groovy/page/aclClass/AclClassSearchPage.groovy index a44f66e6..85a9d17c 100644 --- a/examples/simple/src/integration-test/groovy/page/aclClass/AclClassSearchPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/aclClass/AclClassSearchPage.groovy @@ -6,9 +6,7 @@ import page.SearchPage class AclClassSearchPage extends SearchPage { static url = 'aclClass/search' - static typeName = { 'AclClass' } - static content = { className { $(name: 'className').module(TextInput) } } diff --git a/examples/simple/src/integration-test/groovy/page/aclEntry/AclEntryCreatePage.groovy b/examples/simple/src/integration-test/groovy/page/aclEntry/AclEntryCreatePage.groovy index 53f7c3eb..3cff7c8e 100644 --- a/examples/simple/src/integration-test/groovy/page/aclEntry/AclEntryCreatePage.groovy +++ b/examples/simple/src/integration-test/groovy/page/aclEntry/AclEntryCreatePage.groovy @@ -8,9 +8,7 @@ import page.CreatePage class AclEntryCreatePage extends CreatePage { static url = 'aclEntry/create' - static typeName = { 'AclEntry' } - static content = { aclObjectIdentityId { $(name: 'aclObjectIdentity.id').module(TextInput) } aceOrder { $(name: 'aceOrder').module(TextInput) } diff --git a/examples/simple/src/integration-test/groovy/page/aclEntry/AclEntryEditPage.groovy b/examples/simple/src/integration-test/groovy/page/aclEntry/AclEntryEditPage.groovy index 617ec94e..3f0692d8 100644 --- a/examples/simple/src/integration-test/groovy/page/aclEntry/AclEntryEditPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/aclEntry/AclEntryEditPage.groovy @@ -8,9 +8,7 @@ import page.EditPage class AclEntryEditPage extends EditPage { static url = 'aclEntry/edit' - static typeName = { 'AclEntry' } - static content = { aclObjectIdentityId { $(name: 'aclObjectIdentity.id').module(TextInput) } aceOrder { $(name: 'aceOrder').module(TextInput) } diff --git a/examples/simple/src/integration-test/groovy/page/aclEntry/AclEntrySearchPage.groovy b/examples/simple/src/integration-test/groovy/page/aclEntry/AclEntrySearchPage.groovy index 923c94b9..e3855832 100644 --- a/examples/simple/src/integration-test/groovy/page/aclEntry/AclEntrySearchPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/aclEntry/AclEntrySearchPage.groovy @@ -6,9 +6,7 @@ import page.SearchPage class AclEntrySearchPage extends SearchPage { static url = 'aclEntry/search' - static typeName = { 'AclEntry' } - static content = { aclObjectIdentity { $(name: 'aclObjectIdentity.id').module(TextInput) } aceOrder { $(name: 'aceOrder').module(TextInput) } diff --git a/examples/simple/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentityCreatePage.groovy b/examples/simple/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentityCreatePage.groovy index 90662a23..746810cb 100644 --- a/examples/simple/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentityCreatePage.groovy +++ b/examples/simple/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentityCreatePage.groovy @@ -7,9 +7,7 @@ import page.CreatePage class AclObjectIdentityCreatePage extends CreatePage { static url = 'aclObjectIdentity/create' - static typeName = { 'AclObjectIdentity' } - static content = { aclClass { $(name: 'aclClass.id').module(Select) } objectId { $(name: 'objectId').module(TextInput) } diff --git a/examples/simple/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentityEditPage.groovy b/examples/simple/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentityEditPage.groovy index e5bbb71d..81f52fe2 100644 --- a/examples/simple/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentityEditPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentityEditPage.groovy @@ -6,9 +6,7 @@ import page.EditPage class AclObjectIdentityEditPage extends EditPage { static url = 'aclObjectIdentity/edit' - static typeName = { 'AclObjectIdentity' } - static content = { objectId { $(name: 'objectId').module(TextInput) } } diff --git a/examples/simple/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentitySearchPage.groovy b/examples/simple/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentitySearchPage.groovy index 2bf6485d..8b43ba75 100644 --- a/examples/simple/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentitySearchPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/aclObjectIdentity/AclObjectIdentitySearchPage.groovy @@ -7,9 +7,7 @@ import page.SearchPage class AclObjectIdentitySearchPage extends SearchPage { static url = 'aclObjectIdentity/search' - static typeName = { 'AclObjectIdentity' } - static content = { aclClass { $(name: 'aclClass.id').module(Select) } objectId { $(name: 'objectId').module(TextInput) } diff --git a/examples/simple/src/integration-test/groovy/page/aclSid/AclSidCreatePage.groovy b/examples/simple/src/integration-test/groovy/page/aclSid/AclSidCreatePage.groovy index 50340863..71e37235 100644 --- a/examples/simple/src/integration-test/groovy/page/aclSid/AclSidCreatePage.groovy +++ b/examples/simple/src/integration-test/groovy/page/aclSid/AclSidCreatePage.groovy @@ -7,9 +7,7 @@ import page.CreatePage class AclSidCreatePage extends CreatePage { static url = 'aclSid/create' - static typeName = { 'AclSid' } - static content = { sid { $(name: 'sid').module(TextInput) } principal { $(name: 'principal').module(Checkbox) } diff --git a/examples/simple/src/integration-test/groovy/page/aclSid/AclSidEditPage.groovy b/examples/simple/src/integration-test/groovy/page/aclSid/AclSidEditPage.groovy index 763ab0ee..48a7cd7b 100644 --- a/examples/simple/src/integration-test/groovy/page/aclSid/AclSidEditPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/aclSid/AclSidEditPage.groovy @@ -7,9 +7,7 @@ import page.EditPage class AclSidEditPage extends EditPage { static url = 'aclSid/edit' - static typeName = { 'AclSid' } - static content = { sid { $(name: 'sid').module(TextInput) } principal { $(name: 'principal').module(Checkbox) } diff --git a/examples/simple/src/integration-test/groovy/page/aclSid/AclSidSearchPage.groovy b/examples/simple/src/integration-test/groovy/page/aclSid/AclSidSearchPage.groovy index 71e5605e..6edcf744 100644 --- a/examples/simple/src/integration-test/groovy/page/aclSid/AclSidSearchPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/aclSid/AclSidSearchPage.groovy @@ -7,9 +7,7 @@ import page.SearchPage class AclSidSearchPage extends SearchPage { static url = 'aclSid/search' - static typeName = { 'AclSid' } - static content = { sid { $(name: 'sid').module(TextInput) } principal { $(name: 'principal').module(RadioButtons) } diff --git a/examples/simple/src/integration-test/groovy/page/persistentLogin/PersistentLoginSearchPage.groovy b/examples/simple/src/integration-test/groovy/page/persistentLogin/PersistentLoginSearchPage.groovy index c0da0470..8af6faf4 100644 --- a/examples/simple/src/integration-test/groovy/page/persistentLogin/PersistentLoginSearchPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/persistentLogin/PersistentLoginSearchPage.groovy @@ -6,9 +6,7 @@ import page.SearchPage class PersistentLoginSearchPage extends SearchPage { static url = 'persistentLogin/search' - static typeName = { 'PersistentLogin' } - static content = { series { $(name: 'series').module(TextInput) } token { $(name: 'token').module(TextInput) } diff --git a/examples/simple/src/integration-test/groovy/page/register/ForgotPasswordPage.groovy b/examples/simple/src/integration-test/groovy/page/register/ForgotPasswordPage.groovy index ad4a9429..992d5cfb 100644 --- a/examples/simple/src/integration-test/groovy/page/register/ForgotPasswordPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/register/ForgotPasswordPage.groovy @@ -6,14 +6,10 @@ import page.AbstractSecurityPage class ForgotPasswordPage extends AbstractSecurityPage { static url = 'register/forgotPassword' - static at = { title == 'Forgot Password' } - static content = { form { $('forgotPasswordForm') } - username { $(name: 'username').module(TextInput) } - - submit { $('a', id: 'submit') } + submitBtn { $('a', id: 'submit') } } } diff --git a/examples/simple/src/integration-test/groovy/page/register/RegisterPage.groovy b/examples/simple/src/integration-test/groovy/page/register/RegisterPage.groovy index cd68c5a3..b8140840 100644 --- a/examples/simple/src/integration-test/groovy/page/register/RegisterPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/register/RegisterPage.groovy @@ -1,22 +1,19 @@ package page.register +import geb.module.PasswordInput import geb.module.TextInput import page.AbstractSecurityPage class RegisterPage extends AbstractSecurityPage { static url = 'register' - static at = { title == 'Register' } - static content = { form { $('registerForm') } - username { $(name: 'username').module(TextInput) } email { $(name: 'email').module(TextInput) } - password { $(name: 'password').module(TextInput) } - password2 { $(name: 'password2').module(TextInput) } - - submit { $('a', id: 'submit') } + password { $(name: 'password').module(PasswordInput) } + password2 { $(name: 'password2').module(PasswordInput) } + submitBtn { $('a', id: 'submit') } } } diff --git a/examples/simple/src/integration-test/groovy/page/register/ResetPasswordPage.groovy b/examples/simple/src/integration-test/groovy/page/register/ResetPasswordPage.groovy new file mode 100644 index 00000000..801c5df2 --- /dev/null +++ b/examples/simple/src/integration-test/groovy/page/register/ResetPasswordPage.groovy @@ -0,0 +1,22 @@ +package page.register + +import geb.module.PasswordInput +import page.AbstractSecurityPage + +class ResetPasswordPage extends AbstractSecurityPage { + + static url = 'register/resetPassword' + static at = { title == 'Reset Password' } + static content = { + form { $('resetPasswordForm') } + password { $('#password').module(PasswordInput) } + password2 { $('#password2').module(PasswordInput) } + submitBtn { $('a', id: 'submit') } + } + + def enterNewPassword(String p1, String p2) { + password = p1 + password2 = p2 + submit() + } +} \ No newline at end of file diff --git a/examples/simple/src/integration-test/groovy/page/registrationCode/RegistrationCodeEditPage.groovy b/examples/simple/src/integration-test/groovy/page/registrationCode/RegistrationCodeEditPage.groovy index f4affae3..7f7afe95 100644 --- a/examples/simple/src/integration-test/groovy/page/registrationCode/RegistrationCodeEditPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/registrationCode/RegistrationCodeEditPage.groovy @@ -6,9 +6,7 @@ import page.EditPage class RegistrationCodeEditPage extends EditPage { static url = 'registrationCode/edit' - static typeName = { 'RegistrationCode' } - static content = { token { $(name: 'token').module(TextInput) } username { $('#username').module(TextInput) } diff --git a/examples/simple/src/integration-test/groovy/page/registrationCode/RegistrationCodeSearchPage.groovy b/examples/simple/src/integration-test/groovy/page/registrationCode/RegistrationCodeSearchPage.groovy index 681a009a..cd442e66 100644 --- a/examples/simple/src/integration-test/groovy/page/registrationCode/RegistrationCodeSearchPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/registrationCode/RegistrationCodeSearchPage.groovy @@ -6,9 +6,7 @@ import page.SearchPage class RegistrationCodeSearchPage extends SearchPage { static url = 'registrationCode/search' - static typeName = { 'Registration Code' } - static content = { token { $(name: 'token').module(TextInput) } username { $('#username').module(TextInput) } diff --git a/examples/simple/src/integration-test/groovy/page/requestmap/RequestmapCreatePage.groovy b/examples/simple/src/integration-test/groovy/page/requestmap/RequestmapCreatePage.groovy index 68196150..f23f7bb4 100644 --- a/examples/simple/src/integration-test/groovy/page/requestmap/RequestmapCreatePage.groovy +++ b/examples/simple/src/integration-test/groovy/page/requestmap/RequestmapCreatePage.groovy @@ -6,9 +6,7 @@ import page.CreatePage class RequestmapCreatePage extends CreatePage { static url = 'requestmap/create' - static typeName = { 'Requestmap' } - static content = { configAttribute { $(name: 'configAttribute').module(TextInput) } urlPattern { $(name: 'url').module(TextInput) } diff --git a/examples/simple/src/integration-test/groovy/page/requestmap/RequestmapEditPage.groovy b/examples/simple/src/integration-test/groovy/page/requestmap/RequestmapEditPage.groovy index a7b1c151..d0b60de5 100644 --- a/examples/simple/src/integration-test/groovy/page/requestmap/RequestmapEditPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/requestmap/RequestmapEditPage.groovy @@ -6,9 +6,7 @@ import page.EditPage class RequestmapEditPage extends EditPage { static url = 'requestmap/edit' - static typeName = { 'Requestmap' } - static content = { configAttribute { $(name: 'configAttribute').module(TextInput) } urlPattern { $(name: 'url').module(TextInput) } diff --git a/examples/simple/src/integration-test/groovy/page/requestmap/RequestmapSearchPage.groovy b/examples/simple/src/integration-test/groovy/page/requestmap/RequestmapSearchPage.groovy index 37ba3882..8d43b719 100644 --- a/examples/simple/src/integration-test/groovy/page/requestmap/RequestmapSearchPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/requestmap/RequestmapSearchPage.groovy @@ -6,9 +6,7 @@ import page.SearchPage class RequestmapSearchPage extends SearchPage { static url = 'requestmap/search' - static typeName = { 'Requestmap' } - static content = { configAttribute { $(name: 'configAttribute').module(TextInput) } urlPattern { $(name: 'url').module(TextInput) } diff --git a/examples/simple/src/integration-test/groovy/page/role/RoleCreatePage.groovy b/examples/simple/src/integration-test/groovy/page/role/RoleCreatePage.groovy index fd634f40..3b7c4b5a 100644 --- a/examples/simple/src/integration-test/groovy/page/role/RoleCreatePage.groovy +++ b/examples/simple/src/integration-test/groovy/page/role/RoleCreatePage.groovy @@ -6,9 +6,7 @@ import page.CreatePage class RoleCreatePage extends CreatePage { static url = 'role/create' - static typeName = { 'Role' } - static content = { authority { $(name: 'authority').module(TextInput) } } diff --git a/examples/simple/src/integration-test/groovy/page/role/RoleEditPage.groovy b/examples/simple/src/integration-test/groovy/page/role/RoleEditPage.groovy index ccc1ed1d..58444394 100644 --- a/examples/simple/src/integration-test/groovy/page/role/RoleEditPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/role/RoleEditPage.groovy @@ -6,9 +6,7 @@ import page.EditPage class RoleEditPage extends EditPage { static url = 'role/edit' - static typeName = { 'Role' } - static content = { authority { $(name: 'authority').module(TextInput) } } diff --git a/examples/simple/src/integration-test/groovy/page/role/RoleSearchPage.groovy b/examples/simple/src/integration-test/groovy/page/role/RoleSearchPage.groovy index e0646395..2c03eb9e 100644 --- a/examples/simple/src/integration-test/groovy/page/role/RoleSearchPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/role/RoleSearchPage.groovy @@ -6,9 +6,7 @@ import page.SearchPage class RoleSearchPage extends SearchPage { static url = 'role/search' - static typeName = { 'Role' } - static content = { authority { $(name: 'authority').module(TextInput) } } diff --git a/examples/simple/src/integration-test/groovy/page/user/UserCreatePage.groovy b/examples/simple/src/integration-test/groovy/page/user/UserCreatePage.groovy index 794deb0c..f88c6f4c 100644 --- a/examples/simple/src/integration-test/groovy/page/user/UserCreatePage.groovy +++ b/examples/simple/src/integration-test/groovy/page/user/UserCreatePage.groovy @@ -1,17 +1,17 @@ package page.user import geb.module.Checkbox +import geb.module.PasswordInput import geb.module.TextInput import page.CreatePage class UserCreatePage extends CreatePage { static url = 'user/create' - static typeName = { 'User' } - static content = { username { $('#username').module(TextInput) } + password { $('#password').module(PasswordInput) } enabled { $(name: 'enabled').module(Checkbox) } accountExpired { $(name: 'accountExpired').module(Checkbox) } accountLocked { $(name: 'accountLocked').module(Checkbox) } diff --git a/examples/simple/src/integration-test/groovy/page/user/UserEditPage.groovy b/examples/simple/src/integration-test/groovy/page/user/UserEditPage.groovy index 03038490..42f08c93 100644 --- a/examples/simple/src/integration-test/groovy/page/user/UserEditPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/user/UserEditPage.groovy @@ -8,15 +8,13 @@ import page.EditPage class UserEditPage extends EditPage { static url = 'user/edit' - static typeName = { 'User' } - static content = { username { $('#username').module(TextInput) } enabled { $(name: 'enabled').module(Checkbox) } accountExpired { $(name: 'accountExpired').module(Checkbox) } accountLocked { $(name: 'accountLocked').module(Checkbox) } passwordExpired { $(name: 'passwordExpired').module(Checkbox) } - rolesTab {module RolesTab} + rolesTab { module RolesTab } } } diff --git a/examples/simple/src/integration-test/groovy/page/user/UserSearchPage.groovy b/examples/simple/src/integration-test/groovy/page/user/UserSearchPage.groovy index 4a3aa090..fb2e03a4 100644 --- a/examples/simple/src/integration-test/groovy/page/user/UserSearchPage.groovy +++ b/examples/simple/src/integration-test/groovy/page/user/UserSearchPage.groovy @@ -7,9 +7,7 @@ import page.SearchPage class UserSearchPage extends SearchPage { static url = 'user/search' - static typeName = { 'User' } - static content = { username { $('#username').module(TextInput) } enabled { $(name: 'enabled').module(RadioButtons) } diff --git a/examples/simple/src/integration-test/groovy/spec/AbstractSecuritySpec.groovy b/examples/simple/src/integration-test/groovy/spec/AbstractSecuritySpec.groovy index e7102de6..23c5c73d 100644 --- a/examples/simple/src/integration-test/groovy/spec/AbstractSecuritySpec.groovy +++ b/examples/simple/src/integration-test/groovy/spec/AbstractSecuritySpec.groovy @@ -16,7 +16,7 @@ abstract class AbstractSecuritySpec extends ContainerGebSpec { protected void logout() { String url = SpringSecurityUtils.securityConfig.logout.filterProcessesUrl - go url + browser.go(url) browser.clearCookies() } @@ -25,23 +25,26 @@ abstract class AbstractSecuritySpec extends ContainerGebSpec { } protected void assertContentContains(String expected) { - assert $().text().contains(expected) + assert browser.$().text().contains(expected) } // used to verify hidden content like menus and jGrowl flash messages protected void assertHtmlContains(String expected) { + // For some reason, an extra call to pageSource is sometimes + // needed here, for jGrowl messages to be rendered to the page + assert browser.driver.pageSource assert browser.driver.pageSource.contains(expected) } protected void assertContentContainsOne(String expected1, String expected2) { - assert $().text().contains(expected1) || $().text().contains(expected2) + assert browser.$().text().contains(expected1) || browser.$().text().contains(expected2) } protected void assertContentMatches(String regex) { - assert $().text() ==~ regex + assert browser.$().text() ==~ regex } protected void assertContentDoesNotContain(String unexpected) { - assert !$().text().contains(unexpected) + assert !browser.$().text().contains(unexpected) } } diff --git a/examples/simple/src/integration-test/groovy/spec/DefaultMenuSpec.groovy b/examples/simple/src/integration-test/groovy/spec/DefaultMenuSpec.groovy index 48f90c85..d0975138 100644 --- a/examples/simple/src/integration-test/groovy/spec/DefaultMenuSpec.groovy +++ b/examples/simple/src/integration-test/groovy/spec/DefaultMenuSpec.groovy @@ -1,36 +1,34 @@ package spec import grails.testing.mixin.integration.Integration -import spock.lang.Stepwise -@Stepwise @Integration class DefaultMenuSpec extends AbstractSecuritySpec { void testIndex() { when: - go '' + browser.go('') String html = pageSource then: - html.contains 'Spring Security Management Console' + html.contains('Spring Security Management Console') - html.contains 'Users' + html.contains('Users') - html.contains 'Roles' + html.contains('Roles') - html.contains 'Requestmaps' + html.contains('Requestmaps') - html.contains 'Registration Code' + html.contains('Registration Code') - html.contains 'Configuration' - html.contains 'Mappings' - html.contains 'Current Authentication' - html.contains 'User Cache' - html.contains 'Filter Chains' - html.contains 'Logout Handlers' - html.contains 'Voters' - html.contains 'Authentication Providers' + html.contains('Configuration') + html.contains('Mappings') + html.contains('Current Authentication') + html.contains('User Cache') + html.contains('Filter Chains') + html.contains('Logout Handlers') + html.contains('Voters') + html.contains('Authentication Providers') !html.contains('Persistent Logins') diff --git a/examples/simple/src/integration-test/groovy/spec/DefaultSecurityInfoSpec.groovy b/examples/simple/src/integration-test/groovy/spec/DefaultSecurityInfoSpec.groovy index 0cf21949..ef3e1588 100644 --- a/examples/simple/src/integration-test/groovy/spec/DefaultSecurityInfoSpec.groovy +++ b/examples/simple/src/integration-test/groovy/spec/DefaultSecurityInfoSpec.groovy @@ -3,9 +3,7 @@ package spec import grails.testing.mixin.integration.Integration import org.springframework.security.core.userdetails.User import org.springframework.security.core.userdetails.UserCache -import spock.lang.Stepwise -@Stepwise @Integration class DefaultSecurityInfoSpec extends AbstractSecuritySpec { @@ -13,33 +11,35 @@ class DefaultSecurityInfoSpec extends AbstractSecuritySpec { void testConfig() { when: - go 'securityInfo/config' + browser.go('securityInfo/config') then: - assertContentContains 'adh.ajaxErrorPage /login/ajaxDenied' - assertContentContains 'Showing 1 to 10 of ' + assertContentContains('adh.ajaxErrorPage /login/ajaxDenied') + assertContentContains('Showing 1 to 10 of ') } void testMappings() { when: - go 'securityInfo/mappings' + browser.go('securityInfo/mappings') then: - assertContentContainsOne 'ROLE_RUN_AS, IS_AUTHENTICATED_FULLY', - 'IS_AUTHENTICATED_FULLY, ROLE_RUN_AS' - - assertContentContains '/j_spring_security_switch_user' - assertContentContains '/secure/**' - assertContentContains 'ROLE_ADMIN' + assertContentContainsOne( + 'ROLE_RUN_AS, IS_AUTHENTICATED_FULLY', + 'IS_AUTHENTICATED_FULLY, ROLE_RUN_AS' + ) + + assertContentContains('/j_spring_security_switch_user') + assertContentContains('/secure/**') + assertContentContains('ROLE_ADMIN') } void testCurrentAuth() { when: - go 'securityInfo/currentAuth' + browser.go('securityInfo/currentAuth') then: - assertContentContains 'Details WebAuthenticationDetails' - assertContentContains '__grails.anonymous.user__' + assertContentContains('Details WebAuthenticationDetails') + assertContentContains('__grails.anonymous.user__') } void testUsercache() { @@ -47,11 +47,11 @@ class DefaultSecurityInfoSpec extends AbstractSecuritySpec { userCache.putUserInCache(new User('testuser', 'pw', [])) when: - go 'securityInfo/usercache' + browser.go('securityInfo/usercache') then: - assertContentContains 'UserCache class: org.ehcache.jsr107.Eh107Cache' - assertContentContains 'testuser' + assertContentContains('UserCache class: org.ehcache.jsr107.Eh107Cache') + assertContentContains('testuser') cleanup: userCache.removeUserFromCache('testuser') @@ -59,67 +59,66 @@ class DefaultSecurityInfoSpec extends AbstractSecuritySpec { void testEmptyUsercache() { when: - go 'securityInfo/usercache' + browser.go('securityInfo/usercache') then: - assertContentContains 'UserCache class: org.ehcache.jsr107.Eh107Cache' - assertContentDoesNotContain'testuser' + assertContentContains('UserCache class: org.ehcache.jsr107.Eh107Cache') + assertContentDoesNotContain('testuser') } void testFilterChains() { when: - go 'securityInfo/filterChains' + browser.go('securityInfo/filterChains') then: - assertContentContains '/assets/**' - assertContentContains '/**/js/**' - assertContentContains '/**/css/**' - assertContentContains '/**/images/**' - assertContentContains '/**/favicon.ico' - assertContentContains '/**' - assertContentContains 'grails.plugin.springsecurity.web.SecurityRequestHolderFilter' - assertContentContains 'org.springframework.security.web.access.channel.ChannelProcessingFilter' - assertContentContains 'org.springframework.security.web.context.SecurityContextPersistenceFilter' - assertContentContains 'org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter' - assertContentContains 'grails.plugin.springsecurity.web.filter.GrailsRememberMeAuthenticationFilter' - assertContentContains 'grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter' - assertContentContains 'org.springframework.security.web.access.intercept.FilterSecurityInterceptor' - assertContentContains 'grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter' - assertContentContains 'grails.plugin.springsecurity.web.authentication.GrailsUsernamePasswordAuthenticationFilter' - assertContentContains 'org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter' - assertContentContains 'grails.plugin.springsecurity.web.filter.GrailsRememberMeAuthenticationFilter' - assertContentContains 'grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter' - //assertContentContains 'org.springframework.security.web.access.ExceptionTranslationFilter' - assertContentContains 'org.springframework.security.web.access.intercept.FilterSecurityInterceptor' - assertContentContains 'org.springframework.security.web.authentication.switchuser.SwitchUserFilter' + assertContentContains('/assets/**') + assertContentContains('/**/js/**') + assertContentContains('/**/css/**') + assertContentContains('/**/images/**') + assertContentContains('/**/favicon.ico') + assertContentContains('/**') + assertContentContains('grails.plugin.springsecurity.web.SecurityRequestHolderFilter') + assertContentContains('org.springframework.security.web.access.channel.ChannelProcessingFilter') + assertContentContains('org.springframework.security.web.context.SecurityContextPersistenceFilter') + assertContentContains('org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter') + assertContentContains('grails.plugin.springsecurity.web.filter.GrailsRememberMeAuthenticationFilter') + assertContentContains('grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter') + assertContentContains('org.springframework.security.web.access.intercept.FilterSecurityInterceptor') + assertContentContains('grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter') + assertContentContains('grails.plugin.springsecurity.web.authentication.GrailsUsernamePasswordAuthenticationFilter') + assertContentContains('org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter') + assertContentContains('grails.plugin.springsecurity.web.filter.GrailsRememberMeAuthenticationFilter') + assertContentContains('grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter') + assertContentContains('org.springframework.security.web.access.intercept.FilterSecurityInterceptor') + assertContentContains('org.springframework.security.web.authentication.switchuser.SwitchUserFilter') } void testLogoutHandlers() { when: - go 'securityInfo/logoutHandlers' + browser.go('securityInfo/logoutHandlers') then: - assertContentContains 'org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices' - assertContentContains 'org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler' + assertContentContains('org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices') + assertContentContains('org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler') } void testVoters() { when: - go 'securityInfo/voters' + browser.go('securityInfo/voters') then: - assertContentContains 'org.springframework.security.access.vote.AuthenticatedVoter' - assertContentContains 'org.springframework.security.access.vote.RoleHierarchyVoter' - assertContentContains 'grails.plugin.springsecurity.web.access.expression.WebExpressionVoter' + assertContentContains('org.springframework.security.access.vote.AuthenticatedVoter') + assertContentContains('org.springframework.security.access.vote.RoleHierarchyVoter') + assertContentContains('grails.plugin.springsecurity.web.access.expression.WebExpressionVoter') } void testProviders() { when: - go 'securityInfo/providers' + browser.go('securityInfo/providers') then: - assertContentContains 'org.springframework.security.authentication.dao.DaoAuthenticationProvider' - assertContentContains 'grails.plugin.springsecurity.authentication.GrailsAnonymousAuthenticationProvider' - assertContentContains 'org.springframework.security.authentication.RememberMeAuthenticationProvider' + assertContentContains('org.springframework.security.authentication.dao.DaoAuthenticationProvider') + assertContentContains('grails.plugin.springsecurity.authentication.GrailsAnonymousAuthenticationProvider') + assertContentContains('org.springframework.security.authentication.RememberMeAuthenticationProvider') } } diff --git a/examples/simple/src/integration-test/groovy/spec/RegisterSpec.groovy b/examples/simple/src/integration-test/groovy/spec/RegisterSpec.groovy index f18b0979..5c33f278 100644 --- a/examples/simple/src/integration-test/groovy/spec/RegisterSpec.groovy +++ b/examples/simple/src/integration-test/groovy/spec/RegisterSpec.groovy @@ -1,19 +1,15 @@ package spec import grails.testing.mixin.integration.Integration -import org.springframework.test.annotation.DirtiesContext import page.register.ForgotPasswordPage import page.register.RegisterPage +import page.register.ResetPasswordPage import page.user.UserEditPage import page.user.UserSearchPage import com.dumbster.smtp.SimpleSmtpServer import com.dumbster.smtp.SmtpMessage -import spock.lang.PendingFeature -import spock.lang.Stepwise -@DirtiesContext(classMode=DirtiesContext.ClassMode.BEFORE_CLASS) -@Stepwise @Integration class RegisterSpec extends AbstractSecuritySpec { @@ -29,78 +25,82 @@ class RegisterSpec extends AbstractSecuritySpec { void testRegisterValidation() { when: - to RegisterPage - submit() + def registerPage = browser.to(RegisterPage).tap { + submit() + } then: - assertContentContains 'Username is required' - assertContentContains 'Email is required' - assertContentContains 'Password is required' + assertContentContains('Username is required') + assertContentContains('Email is required') + assertContentContains('Password is required') when: - username = 'admin' - email = 'foo' - $('#password') << 'abcdefghijk' - $('#password2') << 'mnopqrstuwzy' - submit() + registerPage.with { + username = 'admin' + email = 'foo' + password = 'abcdefghijk' + password2 = 'mnopqrstuwzy' + submit() + } then: - assertContentContains 'The username is taken' - assertContentContains 'Please provide a valid email address' - assertContentContains 'Password must have at least one letter, number, and special character: !@#$%^&' - assertContentContains 'Passwords do not match' + assertContentContains('The username is taken') + assertContentContains('Please provide a valid email address') + assertContentContains('Password must have at least one letter, number, and special character: !@#$%^&') + assertContentContains('Passwords do not match') when: - username = 'abcdef123' - email = 'abcdef@abcdef.com' - $('#password') << 'aaaaaaaa' - $('#password2') << 'aaaaaaaa' - submit() + registerPage.with { + username = 'abcdef123' + email = 'abcdef@abcdef.com' + password = 'aaaaaaaa' + password2 = 'aaaaaaaa' + submit() + } then: - assertContentContains 'Password must have at least one letter, number, and special character: !@#$%^&' + assertContentContains('Password must have at least one letter, number, and special character: !@#$%^&') } void testForgotPasswordValidation() { when: - to ForgotPasswordPage - submit() + def forgotPasswordPage = browser.to(ForgotPasswordPage).tap { + submit() + } then: - assertContentContains 'Please enter your username' + assertContentContains('Please enter your username') when: - username = '1111' - submit() + forgotPasswordPage.username = '1111' + forgotPasswordPage.submit() then: - assertContentContains 'No user was found with that username' + assertContentContains('No user was found with that username') } - // FIXME - @DirtiesContext - @PendingFeature(reason="test is failing at resetPassword stage") void testRegisterAndForgotPassword() { - given: - String un = 'test_user_abcdef' + System.currentTimeMillis() + String un = "test_user_abcdef${System.currentTimeMillis()}" when: - to RegisterPage + def registerPage = browser.to(RegisterPage) then: - at RegisterPage + browser.at(RegisterPage) when: - username = un - email = un + '@abcdef.com' - $('#password') << 'aaaaaa1#' - $('#password2') << 'aaaaaa1#' - submit() + registerPage.with { + username = un + email = "$un@abcdef.com" + password = 'aaaaaa1#' + password2 = 'aaaaaa1#' + submit() + } then: - assertContentContains 'Your account registration email was sent - check your mail!' - assert 1 == server.receivedEmailSize + assertContentContains('Your account registration email was sent - check your mail!') + 1 == server.receivedEmailSize when: def email = currentEmail @@ -112,29 +112,35 @@ class RegisterSpec extends AbstractSecuritySpec { String body = email.body then: - body.contains 'Hi ' + un + body.contains("Hi $un") when: String code = findCode(body, 'verifyRegistration') - go 'register/verifyRegistration?t=' + code then: - assertHtmlContains 'Your registration is complete' + code ==~ /^[a-f0-9]{32}$/ + + when: + browser.go("register/verifyRegistration?t=$code") + + then: + assertHtmlContains('Your registration is complete') when: logout() - go '' + browser.go('') then: - assertContentContains 'Log in' + assertContentContains('Log in') when: - to ForgotPasswordPage - username = un - submit() + browser.to(ForgotPasswordPage).with { + username = un + submit() + } then: - assertContentContains 'Your password reset email was sent - check your mail!' + assertContentContains('Your password reset email was sent - check your mail!') 2 == server.receivedEmailSize when: @@ -147,90 +153,85 @@ class RegisterSpec extends AbstractSecuritySpec { body = email.body then: - body.contains('Hi ' + un) + body.contains("Hi $un") when: code = findCode(body, 'resetPassword') - go 'register/resetPassword?t=123' + browser.go('register/resetPassword?t=123') then: - assertHtmlContains 'Sorry, we have no record of that request, or it has expired' + assertHtmlContains('Sorry, we have no record of that request, or it has expired') + code ==~ /^[a-f0-9]{32}$/ when: - go 'register/resetPassword?t=' + code + browser.go("register/resetPassword?t=$code") then: - assertContentContains 'Reset Password' + def resetPasswordPage = browser.at(ResetPasswordPage) when: - submit() + resetPasswordPage.submit() then: - assertContentContains 'Password is required' + assertContentContains('Password is required') when: - go 'register/resetPassword?t=' + code - $('#password') << 'abcdefghijk' - $('#password2') << 'mnopqrstuwzy' - submit() + browser.go("register/resetPassword?t=$code") + resetPasswordPage.enterNewPassword('abcdefghijk', 'mnopqrstuwzy') then: - assertContentContains 'Password must have at least one letter, number, and special character: !@#$%^&' - assertContentContains 'Passwords do not match' + assertContentContains('Password must have at least one letter, number, and special character: !@#$%^&') + assertContentContains('Passwords do not match') when: - go 'register/resetPassword?t=' + code - $('#password') << 'aaaaaaaa' - $('#password2') << 'aaaaaaaa' - submit() + browser.go("register/resetPassword?t=$code") + resetPasswordPage.enterNewPassword('aaaaaaaa', 'aaaaaaaa') then: - assertContentContains 'Password must have at least one letter, number, and special character: !@#$%^&' + assertContentContains('Password must have at least one letter, number, and special character: !@#$%^&') when: - go 'register/resetPassword?t=' + code - $('#password') << 'aaaaaa1#' - $('#password2') << 'aaaaaa1#' - submit() + browser.go("register/resetPassword?t=$code") + resetPasswordPage.enterNewPassword('aaaaaa1#', 'aaaaaa1#') then: - assertHtmlContains 'Your password was successfully changed' + assertHtmlContains('Your password was successfully changed') when: logout() - go '' + browser.go('') then: - assertContentContains 'Log in' + assertContentContains('Log in') // delete the user so it doesn't affect other tests when: - go 'user/edit?username=' + un + browser.go("user/edit?username=$un") then: - at UserEditPage - username == un + def userEditPage = browser.at(UserEditPage) + userEditPage.username.text == un when: - delete() + userEditPage.delete() then: - at UserSearchPage + browser.at(UserSearchPage) when: - go 'user/edit?username=' + un + browser.go("user/edit?username=$un") then: - assertHtmlContains 'User not found' + assertHtmlContains('User not found') } private SmtpMessage getCurrentEmail() { def received = server.receivedEmail - def email + def email = null while (received.hasNext()) { email = received.next() } - email + return email as SmtpMessage } private String findCode(String body, String action) { @@ -241,22 +242,19 @@ class RegisterSpec extends AbstractSecuritySpec { } private void startMailServer() { - int port = 1025 while (true) { try { new ServerSocket(port).close() break } - catch (IOException e) { + catch (IOException ignored) { port++ assert port < 2000, 'cannot find open port' } } - server = SimpleSmtpServer.start(port) - - go 'testData/updateMailSenderPort?port=' + port - assertContentContains 'OK: ' + port + browser.go("testData/updateMailSenderPort?port=$port") + assertContentContains("OK: $port") } } diff --git a/examples/simple/src/integration-test/groovy/spec/RegistrationCodeSpec.groovy b/examples/simple/src/integration-test/groovy/spec/RegistrationCodeSpec.groovy index f6e4a26f..9de3e07e 100644 --- a/examples/simple/src/integration-test/groovy/spec/RegistrationCodeSpec.groovy +++ b/examples/simple/src/integration-test/groovy/spec/RegistrationCodeSpec.groovy @@ -3,80 +3,80 @@ package spec import grails.testing.mixin.integration.Integration import page.registrationCode.RegistrationCodeEditPage import page.registrationCode.RegistrationCodeSearchPage -import spock.lang.Stepwise -@Stepwise @Integration class RegistrationCodeSpec extends AbstractSecuritySpec { void testFindAll() { when: - to RegistrationCodeSearchPage + def registrationCodeSearchPage = browser.to(RegistrationCodeSearchPage) then: - assertNotSearched() + registrationCodeSearchPage.assertNotSearched() when: - submit() + registrationCodeSearchPage.submit() then: - at RegistrationCodeSearchPage - assertResults 1, 10, 14 - assertContentContains 'registration_test_2' - assertContentContains '0a154624f36d42e4aa68991a9477bd04' + browser.at(RegistrationCodeSearchPage) + registrationCodeSearchPage.assertResults(1, 10, 14) + assertContentContains('registration_test_2') + assertContentContains('0a154624f36d42e4aa68991a9477bd04') } void testFindByToken() { when: - to RegistrationCodeSearchPage - token = '4a7f88afec3746f7aab2f5d0d8df6d8e' - submit() + def registrationCodeSearchPage = browser.to(RegistrationCodeSearchPage) + registrationCodeSearchPage.token = '4a7f88afec3746f7aab2f5d0d8df6d8e' + registrationCodeSearchPage.submit() then: - at RegistrationCodeSearchPage - assertResults 1, 1, 1 - assertContentContains 'registration_test_1' - assertContentContains '4a7f88afec3746f7aab2f5d0d8df6d8e' + browser.at(RegistrationCodeSearchPage) + registrationCodeSearchPage.assertResults(1, 1, 1) + assertContentContains('registration_test_1') + assertContentContains('4a7f88afec3746f7aab2f5d0d8df6d8e') } void testFindByUsername() { when: - to RegistrationCodeSearchPage - username = 'registration_test_3' - submit() + def registrationCodeSearchPage = browser.to(RegistrationCodeSearchPage) + registrationCodeSearchPage.username = 'registration_test_3' + registrationCodeSearchPage.submit() then: - at RegistrationCodeSearchPage - assertResults 1, 5, 5 - assertContentContains 'registration_test_3' - assertContentContains '89f9bbc658b14808ae4c77c6e17e551a' + browser.at(RegistrationCodeSearchPage) + registrationCodeSearchPage.assertResults(1, 5, 5) + assertContentContains('registration_test_3') + assertContentContains('89f9bbc658b14808ae4c77c6e17e551a') } void testEdit() { when: - go 'registrationCode/edit/4' + browser.go('registrationCode/edit/4') then: - at RegistrationCodeEditPage - username == 'registration_test_1' - token == 'a50e061e0e2f424fb7fbc2ff3dae597d' + def registrationCodeEditPage = browser.at(RegistrationCodeEditPage) + registrationCodeEditPage.username.text == 'registration_test_1' + registrationCodeEditPage.token.text == 'a50e061e0e2f424fb7fbc2ff3dae597d' when: - username = 'new_user' - token = 'new_token' - submit() + registrationCodeEditPage.with { + username = 'new_user' + token = 'new_token' + submit() + } then: - at RegistrationCodeEditPage - username == 'new_user' - token == 'new_token' + browser.at(RegistrationCodeEditPage) + registrationCodeEditPage.username.text == 'new_user' + registrationCodeEditPage.token.text == 'new_token' when: - go 'registrationCode/edit/4' + browser.go('registrationCode/edit/4') then: - at RegistrationCodeEditPage - username == 'new_user' - token == 'new_token' + browser.at(RegistrationCodeEditPage) + registrationCodeEditPage.username.text == 'new_user' + registrationCodeEditPage.token.text == 'new_token' } } diff --git a/examples/simple/src/integration-test/groovy/spec/RequestmapSpec.groovy b/examples/simple/src/integration-test/groovy/spec/RequestmapSpec.groovy index 1d745abd..2dbd0b8d 100644 --- a/examples/simple/src/integration-test/groovy/spec/RequestmapSpec.groovy +++ b/examples/simple/src/integration-test/groovy/spec/RequestmapSpec.groovy @@ -4,117 +4,122 @@ import grails.testing.mixin.integration.Integration import page.requestmap.RequestmapCreatePage import page.requestmap.RequestmapEditPage import page.requestmap.RequestmapSearchPage -import spock.lang.Stepwise -@Stepwise @Integration class RequestmapSpec extends AbstractSecuritySpec { void testFindAll() { when: - to RequestmapSearchPage + def requestmapSearchPage = browser.to(RequestmapSearchPage) then: - assertNotSearched() + requestmapSearchPage.assertNotSearched() when: - submit() + requestmapSearchPage.submit() then: - at RequestmapSearchPage - assertResults 1, 3, 3 - assertContentContains '/secure/**' - assertContentContains 'ROLE_ADMIN' - assertContentContains '/j_spring_security_switch_user' - assertContentContains 'ROLE_RUN_AS' - assertContentContains '/**' - assertContentContains 'permitAll' + browser.at(RequestmapSearchPage) + requestmapSearchPage.assertResults(1, 3, 3) + assertContentContains('/secure/**') + assertContentContains('ROLE_ADMIN') + assertContentContains('/j_spring_security_switch_user') + assertContentContains('ROLE_RUN_AS') + assertContentContains('/**') + assertContentContains('permitAll') } void testFindByConfigAttribute() { when: - to RequestmapSearchPage - configAttribute = 'run' - submit() + def requestmapSearchPage = browser.to(RequestmapSearchPage).tap { + configAttribute = 'run' + submit() + } then: - at RequestmapSearchPage - assertResults 1, 1, 1 - assertContentContains '/j_spring_security_switch_user' - assertContentContains 'ROLE_RUN_AS' + browser.at(RequestmapSearchPage) + requestmapSearchPage.assertResults(1, 1, 1) + assertContentContains('/j_spring_security_switch_user') + assertContentContains('ROLE_RUN_AS') } void testFindByUrl() { when: - to RequestmapSearchPage - urlPattern = 'secure' - submit() + def requestmapSearchPage = browser.to(RequestmapSearchPage).tap { + urlPattern = 'secure' + submit() + } then: - at RequestmapSearchPage - assertResults 1, 1, 1 - assertContentContains '/secure/**' - assertContentContains 'ROLE_ADMIN' + browser.at(RequestmapSearchPage) + requestmapSearchPage.assertResults(1, 1, 1) + assertContentContains('/secure/**') + assertContentContains('ROLE_ADMIN') } void testUniqueUrl() { when: - to RequestmapCreatePage - urlPattern = '/secure/**' - configAttribute = 'ROLE_FOO' - submit() + def requestmapCreatePage = browser.to(RequestmapCreatePage).tap { + urlPattern = '/secure/**' + configAttribute = 'ROLE_FOO' + submit() + } then: - at RequestmapCreatePage - assertNotUnique() + browser.at(RequestmapCreatePage) + requestmapCreatePage.assertNotUnique() } void testCreateAndEdit() { given: - String newPattern = '/foo/' + UUID.randomUUID() + String newPattern = "/foo/${UUID.randomUUID()}" // make sure it doesn't exist when: - to RequestmapSearchPage - urlPattern = newPattern - submit() + def requestmapSearchPage = browser.to(RequestmapSearchPage).tap { + urlPattern = newPattern + submit() + } then: - assertNoResults() + requestmapSearchPage.assertNoResults() // create when: - to RequestmapCreatePage - urlPattern = newPattern - configAttribute = 'ROLE_FOO' - submit() + def requestmapCreatePage = browser.to(RequestmapCreatePage).tap { + urlPattern = newPattern + configAttribute = 'ROLE_FOO' + submit() + } then: - at RequestmapEditPage - urlPattern == newPattern + def requestmapEditPage = browser.at(RequestmapEditPage) + requestmapEditPage.urlPattern.text == newPattern // edit when: - urlPattern = newPattern + '/new' - submit() + requestmapEditPage.with { + urlPattern = "$newPattern/new" + submit() + } then: - at RequestmapEditPage - urlPattern == newPattern + '/new' + browser.at(RequestmapEditPage) + requestmapEditPage.urlPattern.text == "$newPattern/new" // delete when: - delete() + requestmapEditPage.delete() then: - at RequestmapSearchPage + browser.at(RequestmapSearchPage) when: - urlPattern = newPattern + '/new' - submit() + requestmapSearchPage.urlPattern = "$newPattern/new" + requestmapSearchPage.submit() then: - at RequestmapSearchPage - assertNoResults() + browser.at(RequestmapSearchPage) + requestmapSearchPage.assertNoResults() } } diff --git a/examples/simple/src/integration-test/groovy/spec/RoleSpec.groovy b/examples/simple/src/integration-test/groovy/spec/RoleSpec.groovy index 8f17ba1d..68c3b90e 100644 --- a/examples/simple/src/integration-test/groovy/spec/RoleSpec.groovy +++ b/examples/simple/src/integration-test/groovy/spec/RoleSpec.groovy @@ -4,92 +4,94 @@ import grails.testing.mixin.integration.Integration import page.role.RoleCreatePage import page.role.RoleEditPage import page.role.RoleSearchPage -import spock.lang.Stepwise @Integration -@Stepwise class RoleSpec extends AbstractSecuritySpec { void testFindAll() { when: - to RoleSearchPage + def roleSearchPage = browser.to(RoleSearchPage) then: - assertNotSearched() + roleSearchPage.assertNotSearched() when: - submit() + roleSearchPage.submit() then: - at RoleSearchPage - assertResults 1, 10, 12 - assertContentContains 'ROLE_COFFEE' + browser.at(RoleSearchPage) + roleSearchPage.assertResults(1, 10, 12) + assertContentContains('ROLE_COFFEE') } void testFindByAuthority() { when: - to RoleSearchPage - search 'ad' + def roleSearchPage = browser.to(RoleSearchPage).tap { + search('ad') + } then: - at RoleSearchPage - assertResults 1, 2, 2 + browser.at(RoleSearchPage) + roleSearchPage.assertResults(1, 2, 2) - assertContentContains 'ROLE_ADMIN' - assertContentContains 'ROLE_INSTEAD' + assertContentContains('ROLE_ADMIN') + assertContentContains('ROLE_INSTEAD') } void testUniqueName() { when: - to RoleCreatePage - create 'ROLE_ADMIN' + def roleCreatePage = browser.to(RoleCreatePage).tap { + create('ROLE_ADMIN') + } then: - at RoleCreatePage - assertNotUnique() + browser.at(RoleCreatePage) + roleCreatePage.assertNotUnique() } void testCreateAndEdit() { given: - String newName = 'ROLE_NEW_TEST' + UUID.randomUUID() + String newName = "ROLE_NEW_TEST${UUID.randomUUID()}" // make sure it doesn't exist when: - to RoleSearchPage - search newName + def roleSearchPage = browser.to(RoleSearchPage).tap { + search(newName) + } then: - assertNoResults() + roleSearchPage.assertNoResults() // create when: - to RoleCreatePage - create newName + def roleCreatePage = browser.to(RoleCreatePage).tap { + create(newName) + } then: - at RoleEditPage - authority == newName + def roleEditPage = browser.at(RoleEditPage) + roleEditPage.authority.text == newName // edit when: - update newName + '_new' + roleEditPage.update("${newName}_new") then: - at RoleEditPage - authority == newName + '_new' + browser.at(RoleEditPage) + roleEditPage.authority.text == "${newName}_new" // delete when: - delete() + roleEditPage.delete() then: - at RoleSearchPage + browser.at(RoleSearchPage) when: - search newName + '_new' + roleSearchPage.search("${newName}_new") then: - at RoleSearchPage - assertNoResults() + browser.at(RoleSearchPage) + roleSearchPage.assertNoResults() } } diff --git a/examples/simple/src/integration-test/groovy/spec/UserSimpleSpec.groovy b/examples/simple/src/integration-test/groovy/spec/UserSimpleSpec.groovy index 540e37a4..0b521f83 100644 --- a/examples/simple/src/integration-test/groovy/spec/UserSimpleSpec.groovy +++ b/examples/simple/src/integration-test/groovy/spec/UserSimpleSpec.groovy @@ -5,251 +5,264 @@ import page.user.UserCreatePage import page.user.UserEditPage import page.user.UserSearchPage import spock.lang.Issue -import spock.lang.Stepwise -@Stepwise @Integration class UserSimpleSpec extends AbstractSecuritySpec { void testFindAll() { when: - to UserSearchPage + def userSearchPage = browser.to(UserSearchPage) then: - assertNotSearched() + userSearchPage.assertNotSearched() when: - submit() + userSearchPage.submit() then: - at UserSearchPage - assertResults 1, 10, 22 + browser.at(UserSearchPage) + userSearchPage.assertResults(1, 10, 22) } void testFindByUsername() { when: - to UserSearchPage - - username = 'foo' - submit() + def userSearchPage = browser.to(UserSearchPage).tap { + username = 'foo' + submit() + } then: - at UserSearchPage - assertResults 1, 3, 3 + browser.at(UserSearchPage) + userSearchPage.assertResults(1, 3, 3) - assertContentContains 'foon_2' - assertContentContains 'foolkiller' - assertContentContains 'foostra' + assertContentContains('foon_2') + assertContentContains('foolkiller') + assertContentContains('foostra') } void testFindByDisabled() { when: - to UserSearchPage + def userSearchPage = browser.to(UserSearchPage) - enabled.checked = '-1' - submit() + // Temporary workaround for problem with Geb RadioButtons module + //userSearchPage.enabled.checked = '-1' + browser.$('input', type: 'radio', name: 'enabled', value: '-1').click() + userSearchPage.submit() then: - at UserSearchPage - assertResults 1, 1, 1 - assertContentContains 'billy9494' + browser.at(UserSearchPage) + userSearchPage.assertResults(1, 1, 1) + assertContentContains('billy9494') } void testFindByAccountExpired() { when: - to UserSearchPage - - accountExpired.checked = '1' + def userSearchPage = browser.to(UserSearchPage) - submit() + // Temporary workaround for problem with Geb RadioButtons module + //userSearchPage.accountExpired.checked = '1' + browser.$('input', type: 'radio', name: 'accountExpired', value: '1').click() + userSearchPage.submit() then: - at UserSearchPage - assertResults 1, 3, 3 - assertContentContains 'maryrose' - assertContentContains 'ratuig' - assertContentContains 'rome20c' + browser.at(UserSearchPage) + userSearchPage.assertResults(1, 3, 3) + assertContentContains('maryrose') + assertContentContains('ratuig') + assertContentContains('rome20c') } void testFindByAccountLocked() { when: - to UserSearchPage - - accountLocked.checked = '1' + def userSearchPage = browser.to(UserSearchPage) - submit() + // Temporary workaround for problem with Geb RadioButtons module + //userSearchPage.accountLocked.checked = '1' + browser.$('input', type: 'radio', name: 'accountLocked', value: '1').click() + userSearchPage.submit() then: - at UserSearchPage - assertResults 1, 3, 3 - assertContentContains 'aaaaaasd' - assertContentContains 'achen' - assertContentContains 'szhang1999' + browser.at(UserSearchPage) + userSearchPage.assertResults(1, 3, 3) + assertContentContains('aaaaaasd') + assertContentContains('achen') + assertContentContains('szhang1999') } void testFindByPasswordExpired() { when: - to UserSearchPage + def userSearchPage = browser.to(UserSearchPage) - passwordExpired.checked = '1' - - submit() + // Temporary workaround for problem with Geb RadioButtons module + //userSearchPage.passwordExpired.checked = '1' + browser.$('input', type: 'radio', name: 'passwordExpired', value: '1').click() + userSearchPage.submit() then: - at UserSearchPage - assertResults 1, 3, 3 - assertContentContains 'hhheeeaaatt' - assertContentContains 'mscanio' - assertContentContains 'kittal' + browser.at(UserSearchPage) + userSearchPage.assertResults(1, 3, 3) + assertContentContains('hhheeeaaatt') + assertContentContains('mscanio') + assertContentContains('kittal') } void testCreateAndEdit() { given: - String newUsername = 'newuser' + UUID.randomUUID() + String newUsername = "newuser${UUID.randomUUID()}" // make sure it doesn't exist when: - to UserSearchPage - - username = newUsername - submit() + def userSearchPage = browser.to(UserSearchPage).tap { + username = newUsername + submit() + } then: - at UserSearchPage - assertNoResults() + browser.at(UserSearchPage) + userSearchPage.assertNoResults() // create when: - to UserCreatePage - - username = newUsername - $('#password') << 'password' - enabled.check() - submit() + browser.to(UserCreatePage).with { + username = newUsername + password = 'password' + enabled.check() + submit() + } then: - at UserEditPage - username == newUsername - enabled.checked - !accountExpired.checked - !accountLocked.checked - !passwordExpired.checked + def userEditPage = browser.at(UserEditPage) + userEditPage.username.text == newUsername + userEditPage.enabled.checked + !userEditPage.accountExpired.checked + !userEditPage.accountLocked.checked + !userEditPage.passwordExpired.checked // edit when: - String updatedName = newUsername + '_updated' - username = updatedName - enabled.uncheck() - accountExpired.check() - accountLocked.check() - passwordExpired.check() - submit() - - then: - at UserEditPage - username == updatedName - !enabled.checked - accountExpired.checked - accountLocked.checked - passwordExpired.checked + String updatedName = "${newUsername}_updated" + userEditPage.with { + username = updatedName + enabled.uncheck() + accountExpired.check() + accountLocked.check() + passwordExpired.check() + submit() + } + + then: + browser.at(UserEditPage) + userEditPage.username.text == updatedName + !userEditPage.enabled.checked + userEditPage.accountExpired.checked + userEditPage.accountLocked.checked + userEditPage.passwordExpired.checked // delete when: - delete() + userEditPage.delete() then: - at UserSearchPage + browser.at(UserSearchPage) when: - username = updatedName - submit() + userSearchPage.with { + username = updatedName + submit() + } then: - at UserSearchPage - assertNoResults() + browser.at(UserSearchPage) + userSearchPage.assertNoResults() } - @Issue("https://github.com/grails-plugins/grails-spring-security-ui/issues/89") + @Issue('https://github.com/grails-plugins/grails-spring-security-ui/issues/89') void testUserRoleAssociationsAreNotRemoved() { - when: "edit user 1" - go 'user/edit/1' + when: 'edit user 1' + browser.go('user/edit/1') then: - at UserEditPage - - when: "select Roles tab" - rolesTab.select() - - then: "12 roles are listed and 1 is enabled" - assert rolesTab.totalRoles() == 12 - assert rolesTab.totalEnabledRoles() == 1 - assert rolesTab.hasEnabledRole('ROLE_USER') - - when: "ROLE_ADMIN is enabled and the changes are saved" - rolesTab.enableRole "ROLE_ADMIN" - submit() - rolesTab.select() - - then: "12 roles are listed and 2 are enabled" - assert rolesTab.totalEnabledRoles() == 2 - assert rolesTab.hasEnabledRoles(['ROLE_USER', 'ROLE_ADMIN']) - assert rolesTab.totalRoles() == 12 + def userEditPage = browser.at(UserEditPage) + + when: 'select Roles tab' + userEditPage.rolesTab.select() + + then: '12 roles are listed and 1 is enabled' + userEditPage.rolesTab.totalRoles() == 12 + userEditPage.rolesTab.totalEnabledRoles() == 1 + userEditPage.rolesTab.hasEnabledRole('ROLE_USER') + + when: 'ROLE_ADMIN is enabled and the changes are saved' + userEditPage.with { + rolesTab.enableRole 'ROLE_ADMIN' + submit() + rolesTab.select() + } + + then: '12 roles are listed and 2 are enabled' + userEditPage.rolesTab.totalEnabledRoles() == 2 + userEditPage.rolesTab.hasEnabledRoles(['ROLE_USER', 'ROLE_ADMIN']) + userEditPage.rolesTab.totalRoles() == 12 } - @Issue("https://github.com/grails-plugins/grails-spring-security-ui/issues/106") + @Issue('https://github.com/grails-plugins/grails-spring-security-ui/issues/106') void testUserRoleAssociationsAreRemoved() { - when: "edit user 2" - go 'user/edit/2' + when: 'edit user 2' + browser.go('user/edit/2') then: - at UserEditPage + def userEditPage = browser.at(UserEditPage) - when: "select Roles tab" - rolesTab.select() + when: 'select Roles tab' + userEditPage.rolesTab.select() - then: "12 roles are listed and 1 is enabled" - assert rolesTab.totalRoles() == 12 - assert rolesTab.totalEnabledRoles() == 1 - assert rolesTab.hasEnabledRole('ROLE_USER') + then: '12 roles are listed and 1 is enabled' + userEditPage.rolesTab.totalRoles() == 12 + userEditPage.rolesTab.totalEnabledRoles() == 1 + userEditPage.rolesTab.hasEnabledRole('ROLE_USER') - when: "ROLE_ADMIN is enabled and the changes are saved" - rolesTab.enableRole "ROLE_ADMIN" - submit() - rolesTab.select() + when: 'ROLE_ADMIN is enabled and the changes are saved' + userEditPage.with { + rolesTab.enableRole('ROLE_ADMIN') + submit() + rolesTab.select() + } - then: "12 roles are listed and 2 are enabled" - assert rolesTab.totalEnabledRoles() == 2 - assert rolesTab.hasEnabledRoles(['ROLE_USER', 'ROLE_ADMIN']) - assert rolesTab.totalRoles() == 12 + then: '12 roles are listed and 2 are enabled' + userEditPage.rolesTab.totalEnabledRoles() == 2 + userEditPage.rolesTab.hasEnabledRoles(['ROLE_USER', 'ROLE_ADMIN']) + userEditPage.rolesTab.totalRoles() == 12 - when: "edit user 2" - go 'user/edit/2' + when: 'edit user 2' + browser.go('user/edit/2') then: - at UserEditPage + browser.at(UserEditPage) - when: "select Roles tab" - rolesTab.select() + when: 'select Roles tab' + userEditPage.rolesTab.select() - then: "12 roles are listed and 2 are enabled" - assert rolesTab.totalRoles() == 12 - assert rolesTab.totalEnabledRoles() == 2 - assert rolesTab.hasEnabledRole('ROLE_USER') + then: '12 roles are listed and 2 are enabled' + userEditPage.rolesTab.totalRoles() == 12 + userEditPage.rolesTab.totalEnabledRoles() == 2 + userEditPage.rolesTab.hasEnabledRole('ROLE_USER') - when: "ROLE_ADMIN is disabled and the changes are saved" - rolesTab.disableRole "ROLE_ADMIN" - submit() - go 'user/edit/2' + when: 'ROLE_ADMIN is disabled and the changes are saved' + userEditPage.with { + rolesTab.disableRole('ROLE_ADMIN') + submit() + } + browser.go('user/edit/2') then: - at UserEditPage + browser.at(UserEditPage) - when: "select Roles tab" - rolesTab.select() + when: 'select Roles tab' + userEditPage.rolesTab.select() - then: "12 roles are listed and 1 is enabled" - assert rolesTab.totalEnabledRoles() == 1 - assert rolesTab.hasEnabledRoles(['ROLE_USER']) - assert rolesTab.totalRoles() == 12 + then: '12 roles are listed and 1 is enabled' + userEditPage.rolesTab.totalEnabledRoles() == 1 + userEditPage.rolesTab.hasEnabledRoles(['ROLE_USER']) + userEditPage.rolesTab.totalRoles() == 12 } } diff --git a/gradle/integrationTestVerbose.gradle b/gradle/integrationTestVerbose.gradle index 70974c5a..855302d0 100644 --- a/gradle/integrationTestVerbose.gradle +++ b/gradle/integrationTestVerbose.gradle @@ -27,4 +27,5 @@ tasks.withType(Test) { } } } + //systemProperty('grails.geb.recording.mode', 'RECORD_FAILING') }