From c5c4cb77ef876ebaebd5af66d9709e86abfb4fc4 Mon Sep 17 00:00:00 2001 From: honchar Date: Mon, 17 Aug 2015 13:42:35 +0200 Subject: [PATCH] Selenide tests code refactoring, new automation tests (tests for user with assigned Superuser role) --- testing/selenidetest/pom.xml | 2 +- .../testing/selenide/tests/LoginTest.java | 23 +- .../midpoint/testing/selenide/tests/Util.java | 3 +- .../tests/account/CreateAccountTest.java | 8 +- .../selenide/tests/user/CreateUserTest.java | 58 ---- .../selenide/tests/user/SimpleUserTests.java | 276 ++++++++++++++++++ .../selenide/tests/user/SuperUserTests.java | 196 +++++++++++++ .../testing/selenide/tests/user/UserUtil.java | 18 -- .../src/test/resources/spring-module.xml | 9 +- testing/selenidetest/testng.xml | 76 +---- 10 files changed, 506 insertions(+), 163 deletions(-) delete mode 100644 testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/user/CreateUserTest.java create mode 100644 testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/user/SimpleUserTests.java create mode 100644 testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/user/SuperUserTests.java diff --git a/testing/selenidetest/pom.xml b/testing/selenidetest/pom.xml index 63794eca5f9..e883975f35f 100644 --- a/testing/selenidetest/pom.xml +++ b/testing/selenidetest/pom.xml @@ -43,7 +43,7 @@ classes false 1 - alphabetical + filesystem diff --git a/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/LoginTest.java b/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/LoginTest.java index 5a7e8c06af9..3ebb55096b0 100644 --- a/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/LoginTest.java +++ b/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/LoginTest.java @@ -3,8 +3,6 @@ import org.openqa.selenium.By; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.web.context.support.SpringBeanAutowiringSupport; import org.testng.annotations.Test; import static com.codeborne.selenide.Selenide.*; import static com.codeborne.selenide.Condition.*; @@ -68,32 +66,27 @@ public void loginWithIncorrectPasswordTest(){ /** - * open browser window with the specified siteUrl + * Log in to MidPoint as administrator */ - @Test - public void loginAndStay(){ - open(util.getSiteUrl()); + public void login(){ //perform login login(util.getSiteUrl(), util.getAdminUserLogin(), util.getAdminUserPassword()); - - //check if welcome message appears after user logged in - $(By.cssSelector("html.no-js body div.mp-main-container div.row.mainContainer div.page-header h1 small")).shouldHave(text("welcome to midPoint")); } - /** - * Log in to MidPoint as administrator - */ - public void loginAsAdmin(){ - login(util.getSiteUrl(), util.getAdminUserLogin(), util.getAdminUserPassword()); + public void login(String username, String password){ + //perform login + login(util.getSiteUrl(), username, password); } public void login(String siteUrl, String username, String password) { + open(siteUrl); //enter login value $(By.name("username")).shouldBe(visible).setValue(username); //enter password value $(By.name("password")).shouldBe(visible).setValue(password); //click Sign in button - $(By.cssSelector("html.no-js body div.mp-main-container div.row.mainContainer div.row div.col-md-offset-2.col-md-8.col-lg-offset-4.col-lg-4 div.panel.panel-default div.panel-body form#id6.form-horizontal input.btn.btn-primary.pull-right")).shouldBe(enabled).click(); + $(By.xpath("/html/body/div[4]/div/div[3]/div/div/div/form/input")).shouldBe(enabled).click(); + } } diff --git a/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/Util.java b/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/Util.java index d90e80a4e74..7d417bc4256 100644 --- a/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/Util.java +++ b/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/Util.java @@ -39,9 +39,8 @@ public void searchForElement(String searchText, String searchButtonXpath){ //search for element in search form $(By.name("basicSearch:searchText")).shouldBe(visible).setValue(searchText); $(By.xpath(searchButtonXpath)).shouldHave(text("Search")).click(); -// $(By.xpath("/html/body/div[4]/div/form[1]/span/a")).shouldHave(text("Search")).click(); -// /html/body/div[4]/div/div[4]/form/span/a } + public String getSiteUrl() { return siteUrl; } diff --git a/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/account/CreateAccountTest.java b/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/account/CreateAccountTest.java index b5c1bdc7a64..274e29ccc25 100644 --- a/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/account/CreateAccountTest.java +++ b/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/account/CreateAccountTest.java @@ -9,6 +9,7 @@ import com.evolveum.midpoint.testing.selenide.tests.Util; import com.evolveum.midpoint.testing.selenide.tests.resource.ImportResourceTest; import com.evolveum.midpoint.testing.selenide.tests.resource.ResourceUtil; +import com.evolveum.midpoint.testing.selenide.tests.user.SimpleUserTests; import com.evolveum.midpoint.testing.selenide.tests.user.UserUtil; import org.openqa.selenium.By; import org.springframework.beans.factory.annotation.Autowired; @@ -24,6 +25,9 @@ public class CreateAccountTest extends BaseTest { @Autowired LoginTest loginTest; + @Autowired + SimpleUserTests simpleUserTests; + @Autowired UserUtil userUtil; @@ -45,7 +49,7 @@ public void createAccountForUserTest(){ userUtil.openListUsersPage(); //search for user in users list - util.searchForElement(userUtil.getSimpleTestUserName(), "/html/body/div[4]/div/div[4]/form/span/a"); + util.searchForElement(simpleUserTests.SIMPLE_USER_NAME, "/html/body/div[4]/div/div[4]/form/span/a"); $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tbody/tr/td[3]/div/a/span")) .shouldBe(visible).click(); @@ -78,7 +82,7 @@ public void createAccountForUserTest(){ $(By.xpath("/html/body/div[4]/div/div[2]/div[1]/ul/li/div/div[1]/div[1]/span")).shouldHave(text("Success")); //search for user in users list - util.searchForElement(userUtil.getSimpleTestUserName(), "/html/body/div[4]/div/div[4]/form/span/a"); + util.searchForElement(simpleUserTests.SIMPLE_USER_NAME, "/html/body/div[4]/div/div[4]/form/span/a"); $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tbody/tr/td[3]/div/a/span")) .shouldBe(visible).click(); diff --git a/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/user/CreateUserTest.java b/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/user/CreateUserTest.java deleted file mode 100644 index 634f078e97f..00000000000 --- a/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/user/CreateUserTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.evolveum.midpoint.testing.selenide.tests.user; - -import com.evolveum.midpoint.testing.selenide.tests.BaseTest; -import com.evolveum.midpoint.testing.selenide.tests.Util; -import org.openqa.selenium.By; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.testng.annotations.Test; - -import static com.codeborne.selenide.Selenide.$; -import static com.codeborne.selenide.Condition.*; - -/** - * Created by Kate on 09.08.2015. - */ -@Component -public class CreateUserTest extends BaseTest { - - @Autowired - UserUtil userUtil; - - @Autowired - Util util; - - /** - * Create user test. - */ - @Test - public void createUserTest(){ - //create user - userUtil.createUser(userUtil.getSimpleTestUserName()); - //search for the created in users list - util.searchForElement(userUtil.getSimpleTestUserName(), "/html/body/div[4]/div/div[4]/form/span/a"); - $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tbody/tr/td[3]/div/a/span")) - .shouldBe(visible).click(); - } - - /** - * Create user with assigned Superuser role. - */ - @Test - public void createSuperUserTest(){ - //create user - userUtil.createUser(userUtil.getSuperUserName()); - //search for the created in users list - util.searchForElement(userUtil.getSuperUserName(), "/html/body/div[4]/div/div[4]/form/span/a"); - $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tbody/tr/td[3]/div/a/span")) - .shouldBe(visible).click(); - //click on the menu icon next to Assignments section - $(By.xpath("/html/body/div[4]/div/form/div[3]/div[2]/div[2]/div[1]/div[2]/ul/li/a")).shouldBe(visible).click(); - //click Assign role menu item - $(By.linkText("Assign role")).shouldBe(visible).click(); - - - } - - -} diff --git a/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/user/SimpleUserTests.java b/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/user/SimpleUserTests.java new file mode 100644 index 00000000000..b9e7c1c61f0 --- /dev/null +++ b/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/user/SimpleUserTests.java @@ -0,0 +1,276 @@ +package com.evolveum.midpoint.testing.selenide.tests.user; + +import com.evolveum.midpoint.testing.selenide.tests.BaseTest; +import com.evolveum.midpoint.testing.selenide.tests.LoginTest; +import com.evolveum.midpoint.testing.selenide.tests.Util; +import org.openqa.selenium.By; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.testng.annotations.Test; + +import static com.codeborne.selenide.Condition.*; +import static com.codeborne.selenide.Selenide.$; +import static com.codeborne.selenide.Selenide.close; + +/** + * Created by Kate on 14.08.2015. + */ +@Component +public class SimpleUserTests extends BaseTest { + + @Autowired + UserUtil userUtil; + + @Autowired + LoginTest loginTest; + + @Autowired + Util util; + + //test data + public static final String UPDATED_STRING = "_updated"; + public static final String USER_DESCRIPTION = "description"; + public static final String USER_FULL_NAME = "full name"; + public static final String USER_GIVEN_NAME = "given name"; + public static final String USER_FAMILY_NAME = "family name"; + public static final String USER_NICKNAME = "nickname"; + public static final String SIMPLE_USER_NAME = "SimpleUserName"; + + + /** + * Create user test. + */ + @Test (priority = 1) + public void createUserWithUserNameOnlyTest() { + close(); + loginTest.login(); + + //check if welcome message appears after user logged in + $(By.cssSelector("html.no-js body div.mp-main-container div.row.mainContainer div.page-header h1 small")) + .shouldHave(text("welcome to midPoint")); + + //create user with filled user name only + userUtil.createUser(SIMPLE_USER_NAME); + + //check if Success message appears after user saving + $(By.xpath("/html/body/div[4]/div/div[2]/div[1]/ul/li/div/div[1]/div[1]/span")).shouldHave(text("Success")); + + //search for the created in users list + util.searchForElement(SIMPLE_USER_NAME, "/html/body/div[4]/div/div[4]/form/span/a"); + $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tbody/tr/td[3]/div/a/span")) + .shouldBe(visible).click(); + + close(); + } + + /** + * Updating user fields + */ + @Test(dependsOnMethods = {"createUserWithUserNameOnlyTest"}, priority = 3) + public void editUserTest() { + close(); + loginTest.login(); + //check if welcome message appears after user logged in + $(By.cssSelector("html.no-js body div.mp-main-container div.row.mainContainer div.page-header h1 small")) + .shouldHave(text("welcome to midPoint")); + + //open Users -> List users + userUtil.openListUsersPage(); + + //search for user in users list + util.searchForElement(SIMPLE_USER_NAME, "/html/body/div[4]/div/div[4]/form/span/a"); + //click on the found user link + $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tbody/tr/td[3]/div/a/span")) + .shouldBe(visible).click(); + + //click on the menu icon in the User details section + $(By.xpath("/html/body/div[4]/div/form/div[3]/div[1]/div/div/div/div[2]/div[2]/ul/li/a")).shouldBe(visible).click(); + //click on Show empty fields menu item + $(By.linkText("Show empty fields")).shouldBe(visible).click(); + + //update Name field + $(By.name("userForm:body:containers:0:container:properties:0:property:values:0:value:valueContainer:input:input")) + .shouldBe(visible).clear(); + $(By.name("userForm:body:containers:0:container:properties:0:property:values:0:value:valueContainer:input:input")) + .shouldBe(visible).setValue(SIMPLE_USER_NAME + "_updated"); + //update Description field + $(By.name("userForm:body:containers:0:container:properties:1:property:values:0:value:valueContainer:input:input")) + .shouldBe(visible).setValue(USER_DESCRIPTION + UPDATED_STRING); + //update Full Name field + $(By.name("userForm:body:containers:0:container:properties:2:property:values:0:value:valueContainer:input:input")) + .shouldBe(visible).setValue(USER_FULL_NAME + UPDATED_STRING); + //update Given Name field + $(By.name("userForm:body:containers:0:container:properties:3:property:values:0:value:valueContainer:input:input")) + .shouldBe(visible).setValue(USER_GIVEN_NAME + UPDATED_STRING); + //update Family Name field + $(By.name("userForm:body:containers:0:container:properties:4:property:values:0:value:valueContainer:input:input")) + .shouldBe(visible).setValue(USER_FAMILY_NAME + UPDATED_STRING); + //update Nickname field + $(By.name("userForm:body:containers:0:container:properties:6:property:values:0:value:valueContainer:input:input")) + .shouldBe(visible).setValue(USER_NICKNAME + UPDATED_STRING); + + //click Save button + $(By.xpath("/html/body/div[4]/div/form/div[6]/a[2]")).shouldHave(text("Save")).click(); + + //check if Success message appears after user saving + $(By.xpath("/html/body/div[4]/div/div[2]/div[1]/ul/li/div/div[1]/div[1]/span")).shouldHave(text("Success")); + + //search for user in users list + util.searchForElement(SIMPLE_USER_NAME + UPDATED_STRING, "/html/body/div[4]/div/div[4]/form/span/a"); + + //check if updated values are displayed in the users list + $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tbody/tr[1]/td[3]/div")) + .shouldHave(text(SIMPLE_USER_NAME + UPDATED_STRING)); + $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tbody/tr[1]/td[4]/div")) + .shouldHave(text(USER_GIVEN_NAME + UPDATED_STRING)); + $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tbody/tr[1]/td[5]/div")) + .shouldHave(text(USER_FAMILY_NAME + UPDATED_STRING)); + $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tbody/tr[1]/td[6]/div")) + .shouldHave(text(USER_FULL_NAME + UPDATED_STRING)); + + //click on the user link + $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tbody/tr/td[3]/div/a/span")) + .shouldBe(visible).click(); + + //check if updated values are displayed on the user's Edit page + $(By.name("userForm:body:containers:0:container:properties:0:property:values:0:value:valueContainer:input:input")) + .shouldBe(visible).shouldHave(value(SIMPLE_USER_NAME + "_updated")); + $(By.name("userForm:body:containers:0:container:properties:1:property:values:0:value:valueContainer:input:input")) + .shouldHave(value(USER_DESCRIPTION + UPDATED_STRING)); + $(By.name("userForm:body:containers:0:container:properties:2:property:values:0:value:valueContainer:input:input")) + .shouldHave(value(USER_FULL_NAME + UPDATED_STRING)); + $(By.name("userForm:body:containers:0:container:properties:3:property:values:0:value:valueContainer:input:input")) + .shouldHave(value(USER_GIVEN_NAME + UPDATED_STRING)); + $(By.name("userForm:body:containers:0:container:properties:4:property:values:0:value:valueContainer:input:input")) + .shouldHave(value(USER_FAMILY_NAME + UPDATED_STRING)); + $(By.name("userForm:body:containers:0:container:properties:6:property:values:0:value:valueContainer:input:input")) + .shouldHave(value(USER_NICKNAME + UPDATED_STRING)); + + close(); + } + + /** + * Cancelling of user update + */ + @Test(dependsOnMethods = {"createUserWithUserNameOnlyTest"}, priority = 2) + public void cancelUserUpdateTest() { + close(); + loginTest.login(); + //check if welcome message appears after user logged in + $(By.cssSelector("html.no-js body div.mp-main-container div.row.mainContainer div.page-header h1 small")) + .shouldHave(text("welcome to midPoint")); + + //open Users -> List users + userUtil.openListUsersPage(); + + //search for user in users list + util.searchForElement(SIMPLE_USER_NAME, "/html/body/div[4]/div/div[4]/form/span/a"); + //click on the found user link + $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tbody/tr/td[3]/div/a/span")) + .shouldBe(visible).click(); + + //click on the menu icon in the User details section + $(By.xpath("/html/body/div[4]/div/form/div[3]/div[1]/div/div/div/div[2]/div[2]/ul/li/a")).shouldBe(visible).click(); + //click on Show empty fields menu item + $(By.linkText("Show empty fields")).shouldBe(visible).click(); + + //update Name field + $(By.name("userForm:body:containers:0:container:properties:0:property:values:0:value:valueContainer:input:input")) + .shouldBe(visible).clear(); + $(By.name("userForm:body:containers:0:container:properties:0:property:values:0:value:valueContainer:input:input")) + .shouldBe(visible).setValue(SIMPLE_USER_NAME + "_updated"); + + //click Save button + $(By.xpath("/html/body/div[4]/div/form/div[6]/span/a")).shouldHave(text("Back")).click(); + + //search for user in users list + util.searchForElement(SIMPLE_USER_NAME, "/html/body/div[4]/div/div[4]/form/span/a"); + + //check if user name wasn't updated + $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tbody/tr[1]/td[3]/div")) + .shouldHave(text(SIMPLE_USER_NAME)); + $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tbody/tr[1]/td[3]/div")) + .shouldHave(not(text(UPDATED_STRING))); + close(); + } + + /** + * Attempt to create user with all empty fields + */ + @Test(alwaysRun = true, priority = 4) + public void createUserWithEmptyFields() { + close(); + loginTest.login(); + //create user with all empty fields + userUtil.createUser(""); + + //check if error message appears after user saving + $(By.xpath("/html/body/div[4]/div/div[2]/div[1]/ul/li/div/div[1]")).shouldHave(text("No name in new object")); + close(); + } + + /** + * Attempt to create user with existing name + */ + @Test(alwaysRun = true, priority = 5) + public void createUserWithExistingName() { + close(); + loginTest.login(); + //check if welcome message appears after user logged in + $(By.cssSelector("html.no-js body div.mp-main-container div.row.mainContainer div.page-header h1 small")) + .shouldHave(text("welcome to midPoint")); + + //create user + String userName = "Existing name"; + userUtil.createUser(userName); + //check if Success message appears after user saving + $(By.xpath("/html/body/div[4]/div/div[2]/div[1]/ul/li/div/div[1]/div[1]/span")).shouldHave(text("Success")); + //try to create user with the same name + userUtil.createUser(userName); + //check if error message appears + $(By.xpath("/html/body/div[4]/div/div[2]/div[1]/ul/li/div/div[1]/div[1]/span")).shouldBe(visible) + .shouldHave(text("Error processing focus")); + + close(); + } + + @Test(alwaysRun = true, priority = 6) + public void deleteUser() { + close(); + loginTest.login(); + //check if welcome message appears after user logged in + $(By.cssSelector("html.no-js body div.mp-main-container div.row.mainContainer div.page-header h1 small")) + .shouldHave(text("welcome to midPoint")); + + //open Users -> List users + userUtil.openListUsersPage(); + + //search for user in users list + util.searchForElement(SIMPLE_USER_NAME + UPDATED_STRING, "/html/body/div[4]/div/div[4]/form/span/a"); + + //select checkbox next to the found user + $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tbody/tr/td[1]/div/input")).shouldBe(visible).click(); + + //click on the menu icon in the upper right corner of the users list + $(By.xpath("/html/body/div[4]/div/form/div[2]/table/thead/tr/th[9]/div/span[1]/ul/li/a")).shouldBe(visible).click(); + //click on Delete menu item + $(By.linkText("Delete")).shouldBe(visible).click(); + + //click on Yes button in the opened "Confirm delete" window + $(By.xpath("/html/body/div[6]/form/div/div[2]/div/div/div/div[2]/div/div/div/div/p[2]/a[1]")).shouldBe(visible).click(); + + //check if operation success message appears + $(By.xpath("/html/body/div[4]/div/div[2]/div[1]/ul/li/div/div[1]/div[1]/span")).shouldHave(text("Success")); + $(By.xpath("/html/body/div[4]/div/div[2]/div[1]/ul/li/div/div[1]/div[2]/ul/li/div/span")) + .shouldHave(text("Delete users (Gui)")); + + //search for user in users list + util.searchForElement(SIMPLE_USER_NAME + UPDATED_STRING, "/html/body/div[4]/div/div[4]/form/span/a"); + //check the user was not found during user search + $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tfoot/tr/td")).shouldBe(visible) + .shouldHave(text("No matching result found.")); + close(); + } + + +} diff --git a/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/user/SuperUserTests.java b/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/user/SuperUserTests.java new file mode 100644 index 00000000000..a506676d698 --- /dev/null +++ b/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/user/SuperUserTests.java @@ -0,0 +1,196 @@ +package com.evolveum.midpoint.testing.selenide.tests.user; + +import com.evolveum.midpoint.testing.selenide.tests.BaseTest; +import com.evolveum.midpoint.testing.selenide.tests.LoginTest; +import com.evolveum.midpoint.testing.selenide.tests.Util; +import org.openqa.selenium.By; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.testng.annotations.Test; + +import static com.codeborne.selenide.Selenide.$; +import static com.codeborne.selenide.Condition.*; +import static com.codeborne.selenide.Selenide.close; +import static com.codeborne.selenide.Selenide.title; + +/** + * Created by Kate on 09.08.2015. + */ +@Component +public class SuperUserTests extends BaseTest { + + @Autowired + UserUtil userUtil; + + @Autowired + LoginTest loginTest; + + @Autowired + Util util; + + public static final String SUPER_ROLE_NAME = "Superuser"; + public static final String USER_PASSWORD = "password"; + public static final String SUPER_USER_NAME = "SuperUser"; + + /** + * Create user with assigned Superuser role. + */ + @Test(priority = 0) + public void createSuperUserTest() { + close(); + //log in to midPoint + loginTest.login(); + //check if welcome message appears after user logged in + $(By.cssSelector("html.no-js body div.mp-main-container div.row.mainContainer div.page-header h1 small")) + .shouldHave(text("welcome to midPoint")); + //create user + userUtil.createUser(SUPER_USER_NAME); + //search for the created user in users list + util.searchForElement(SUPER_USER_NAME, "/html/body/div[4]/div/div[4]/form/span/a"); + //click on the found user link + $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tbody/tr/td[3]/div/a/span")) + .shouldBe(visible).click(); + + //click on the menu icon in the User details section + $(By.xpath("/html/body/div[4]/div/form/div[3]/div[1]/div/div/div/div[2]/div[2]/ul/li/a")).shouldBe(visible).click(); + //click on Show empty fields menu item + $(By.linkText("Show empty fields")).shouldBe(visible).click(); + //set Password fields with value + $(By.name("userForm:body:containers:7:container:properties:0:property:values:0:value:valueContainer:input:password2")) + .shouldBe(visible).setValue(USER_PASSWORD); + $(By.name("userForm:body:containers:7:container:properties:0:property:values:0:value:valueContainer:input:password1")) + .shouldBe(visible).setValue(USER_PASSWORD); + + + //click on the menu icon next to Assignments section + $(By.xpath("/html/body/div[4]/div/form/div[3]/div[2]/div[2]/div[1]/div[2]/ul/li/a")).shouldBe(visible).click(); + //click Assign role menu item + $(By.linkText("Assign role")).shouldBe(visible).click(); + //search for Superuser role in the opened Select object(s) window + util.searchForElement(SUPER_ROLE_NAME, "/html/body/div[6]/form/div/div[2]/div/div/div/div[2]/div/div/div/div/div/div[1]/form[2]/span/a"); + //check if Superuser role is found during the search + $(By.xpath("/html/body/div[6]/form/div/div[2]/div/div/div/div[2]/div/div/div/div/div/div[2]/div/table/tbody/tr")) + .shouldBe(visible).shouldHave(text(SUPER_ROLE_NAME)); + //select checkbox for the Superuser role + $(By.xpath("/html/body/div[6]/form/div/div[2]/div/div/div/div[2]/div/div/div/div/div/div[2]/div/table/tbody/tr/td[1]/div/input")) + .shouldBe(visible).click(); + //click Assign button + $(By.xpath("/html/body/div[6]/form/div/div[2]/div/div/div/div[2]/div/div/div/div/div/p/a")) + .shouldBe(visible).click(); + + //click Save button + $(By.xpath("/html/body/div[4]/div/form/div[6]/a[2]")).shouldHave(text("Save")).click(); + + //check if Success message appears after user saving + $(By.xpath("/html/body/div[4]/div/div[2]/div[1]/ul/li/div/div[1]/div[1]/span")).shouldHave(text("Success")); + + //search for the created user in users list + util.searchForElement(SUPER_USER_NAME, "/html/body/div[4]/div/div[4]/form/span/a"); + //click on the found user link + $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tbody/tr/td[3]/div/a/span")) + .shouldBe(visible).click(); + + //check if assigned role is displayed in the Assignments section + $(By.xpath("/html/body/div[4]/div/form/div[3]/div[2]/div[2]/div[2]/div/div[1]/div[1]/a/span")).shouldBe(visible) + .shouldHave(text("Superuser")); + + close(); + } + + @Test(dependsOnMethods = {"createSuperUserTest"}, priority = 1) + public void loginAsSuperuserTest() { + close(); + loginTest.login(SUPER_USER_NAME, USER_PASSWORD); + //check if welcome message appears after user logged in + $(By.cssSelector("html.no-js body div.mp-main-container div.row.mainContainer div.page-header h1 small")) + .shouldHave(text("welcome to midPoint")); + + } + + @Test(dependsOnMethods = {"createSuperUserTest"}, priority = 2) + public void disableSuperuserAndLogin() { + close(); + loginTest.login(); + //check if welcome message appears after user logged in + $(By.cssSelector("html.no-js body div.mp-main-container div.row.mainContainer div.page-header h1 small")) + .shouldHave(text("welcome to midPoint")); + //open Users list page + userUtil.openListUsersPage(); + //search for the super user in users list + util.searchForElement(SUPER_USER_NAME, "/html/body/div[4]/div/div[4]/form/span/a"); + //check if super user was found during the search + $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tbody/tr[1]/td[3]/div/a/span")) + .shouldBe(visible).shouldHave(text(SUPER_USER_NAME)); + //select checkbox next to the found user + $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tbody/tr[1]/td[1]/div/input")) + .shouldBe(visible).click(); + //click on the menu icon in the upper right corner of the users list + $(By.xpath("/html/body/div[4]/div/form/div[2]/table/thead/tr/th[9]/div/span[1]/ul/li/a")).shouldBe(visible).click(); + //click on Disable menu item + $(By.linkText("Disable")).shouldBe(visible).click(); + //check if success operation messages are shown + $(By.xpath("/html/body/div[4]/div/div[2]/div[1]/ul/li/div/div[1]/div[1]/span")) + .shouldBe(visible).shouldHave(text("Success")); + $(By.xpath("/html/body/div[4]/div/div[2]/div[1]/ul/li/div/div[1]/div[2]/ul/li/div/span")) + .shouldBe(visible).shouldHave(text("Disable users (Gui)")); + + //click administrator menu in the upper right corner of the window + $(By.xpath("/html/body/div[3]/div/div[2]/ul[2]/li/a")) + .shouldBe(visible).click(); + //click on Log out menu item + $(By.linkText("Log out")).shouldBe(visible).click(); + + //try to log in to the system with disabled super user + loginTest.login(SUPER_USER_NAME, USER_PASSWORD); + + //check if error message is shown for disabled user + $(By.xpath("/html/body/div[4]/div/div[2]/div[1]/ul/li/div/div/div/span")) + .shouldBe(visible).shouldHave(text("User is disabled.")); + } + + @Test(dependsOnMethods = {"createSuperUserTest"}, priority = 3) + public void enableSuperuserAndLogin() { + close(); + loginTest.login(); + //check if welcome message appears after user logged in + $(By.cssSelector("html.no-js body div.mp-main-container div.row.mainContainer div.page-header h1 small")) + .shouldHave(text("welcome to midPoint")); + //open Users list page + userUtil.openListUsersPage(); + //search for the super user in users list + util.searchForElement(SUPER_USER_NAME, "/html/body/div[4]/div/div[4]/form/span/a"); + //check if super user was found during the search + $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tbody/tr[1]/td[3]/div/a/span")) + .shouldBe(visible).shouldHave(text(SUPER_USER_NAME)); + //select checkbox next to the found user + $(By.xpath("/html/body/div[4]/div/form/div[2]/table/tbody/tr[1]/td[1]/div/input")) + .shouldBe(visible).click(); + //click on the menu icon in the upper right corner of the users list + $(By.xpath("/html/body/div[4]/div/form/div[2]/table/thead/tr/th[9]/div/span[1]/ul/li/a")).shouldBe(visible).click(); + //click on Disable menu item + $(By.linkText("Enable")).shouldBe(visible).click(); + //check if success operation messages are shown + $(By.xpath("/html/body/div[4]/div/div[2]/div[1]/ul/li/div/div[1]/div[1]/span")) + .shouldBe(visible).shouldHave(text("Success")); + $(By.xpath("/html/body/div[4]/div/div[2]/div[1]/ul/li/div/div[1]/div[2]/ul/li/div/span")) + .shouldBe(visible).shouldHave(text("Enable users (Gui)")); + + //click administrator menu in the upper right corner of the window + $(By.xpath("/html/body/div[3]/div/div[2]/ul[2]/li/a")) + .shouldBe(visible).click(); + //click on Log out menu item + $(By.linkText("Log out")).shouldBe(visible).click(); + + //log in to the system after super user was enabled + loginTest.login(SUPER_USER_NAME, USER_PASSWORD); + + //check if welcome message appears after user logged in + $(By.cssSelector("html.no-js body div.mp-main-container div.row.mainContainer div.page-header h1 small")) + .shouldHave(text("welcome to midPoint")); + } + +} + + + + diff --git a/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/user/UserUtil.java b/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/user/UserUtil.java index 37ee7e9a4a5..ccdaf3be20e 100644 --- a/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/user/UserUtil.java +++ b/testing/selenidetest/src/test/java/com/evolveum/midpoint/testing/selenide/tests/user/UserUtil.java @@ -13,8 +13,6 @@ */ @Component public class UserUtil { - private String simpleTestUserName; - private String superUserName; /** * Creates user with userName value @@ -33,8 +31,6 @@ public void createUser(String userName){ //click Save button $(By.xpath("/html/body/div[4]/div/form/div[5]/a[2]")).shouldHave(text("Save")).click(); - //check if Success message appears after user saving - $(By.xpath("/html/body/div[4]/div/div[2]/div[1]/ul/li/div/div[1]/div[1]/span")).shouldHave(text("Success")); } @@ -49,19 +45,5 @@ public void openListUsersPage(){ $(By.cssSelector("html.no-js body div.mp-main-container div.row.mainContainer div.page-header h1")).shouldHave(text("Users in midPoint")); } - public void setSimpleTestUserName(String simpleTestUserName) { - this.simpleTestUserName = simpleTestUserName; - } - - public String getSimpleTestUserName() { - return simpleTestUserName; - } - public String getSuperUserName() { - return superUserName; - } - - public void setSuperUserName(String superUserName) { - this.superUserName = superUserName; - } } diff --git a/testing/selenidetest/src/test/resources/spring-module.xml b/testing/selenidetest/src/test/resources/spring-module.xml index 161a51a95d8..fd4b6e3ed21 100644 --- a/testing/selenidetest/src/test/resources/spring-module.xml +++ b/testing/selenidetest/src/test/resources/spring-module.xml @@ -13,17 +13,16 @@ - + - - - - + diff --git a/testing/selenidetest/testng.xml b/testing/selenidetest/testng.xml index a61255e70f8..b53835642c1 100644 --- a/testing/selenidetest/testng.xml +++ b/testing/selenidetest/testng.xml @@ -17,70 +17,22 @@ --> - - + + + + + + - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - +