Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/user-search
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Aug 14, 2015
2 parents 95b8ac6 + 72292b2 commit 27edf75
Show file tree
Hide file tree
Showing 12 changed files with 332 additions and 140 deletions.
6 changes: 3 additions & 3 deletions testing/selenidetest/pom.xml
Expand Up @@ -6,12 +6,12 @@
<name>Selenide tests</name>
<groupId>com.evolveum.midpoint.testing</groupId>
<artifactId>selenidetest</artifactId>
<version>3.2-SNAPSHOT</version>
<version>3.3-SNAPSHOT</version>

<parent>
<artifactId>testing</artifactId>
<groupId>com.evolveum.midpoint</groupId>
<version>3.2-SNAPSHOT</version>
<version>3.3-SNAPSHOT</version>
</parent>
<scm>
<connection>https://github.com/Evolveum/midpoint.git</connection>
Expand Down Expand Up @@ -52,7 +52,7 @@
<!--<dependency>-->
<!--<groupId>com.evolveum.midpoint.infra</groupId>-->
<!--<artifactId>util</artifactId>-->
<!--<version>3.2-SNAPSHOT</version>-->
<!--<version>3.3-SNAPSHOT</version>-->
<!--<scope>test</scope>-->
<!--</dependency>-->
<dependency>
Expand Down
@@ -1,54 +1,20 @@
package com.evolveum.midpoint.testing.selenide.tests;

import org.openqa.selenium.By;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import org.testng.ITestContext;
import org.testng.annotations.BeforeClass;

import static com.codeborne.selenide.Condition.enabled;
import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.open;

/**
* Created by Kate on 09.08.2015.
* Created by Kate on 13.08.2015.
*/
@ContextConfiguration(locations = {"classpath:spring-module.xml"})
public class BaseTest extends AbstractTestNGSpringContextTests {
private static final String PARAM_SITE_URL = "site.url";
private static final String PARAM_USER_LOGIN = "user.login";
private static final String PARAM_USER_PASSWORD = "user.password";

public String siteUrl;
public String userLogin;
public String userPassword;


public BaseTest(){
public BaseTest() {
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
}

@BeforeClass(alwaysRun = true)
public void beforeClass(ITestContext context) {
siteUrl = context.getCurrentXmlTest().getParameter(PARAM_SITE_URL);
userLogin = context.getCurrentXmlTest().getParameter(PARAM_USER_LOGIN);
userPassword = context.getCurrentXmlTest().getParameter(PARAM_USER_PASSWORD);
}

public void login(String siteUrl, String username, String password) {
//opens login page
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();
}


}
@@ -1,24 +1,99 @@
package com.evolveum.midpoint.testing.selenide.tests;

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.*;

/**
* Created by Kate on 07.08.2015.
*/
@Component
public class LoginTest extends BaseTest{

@Autowired
Util util;

@Autowired
BaseTest baseTest;

/**
* Log in to system as administrator/5ecr3t
*/
@Test
public void loginWithCorrectCredentialsTest(){
open(util.getSiteUrl());
//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"));

close();
}

/**
* Log in to system with incorrect username
*/
@Test
public void loginWithIncorrectUsernameTest(){
open(util.getSiteUrl());
//perform login
login(util.getSiteUrl(), "incorrectUserName", util.getAdminUserPassword());

//check if error message appears
$(By.xpath("/html/body/div[4]/div/div[2]/div[1]/ul/li/div/div/div/span")).shouldHave(text("Invalid username and/or password."));

close();
}

/**
* Log in to system with incorrect password
*/
@Test
public void loginWithIncorrectPasswordTest(){
open(util.getSiteUrl());
//perform login
login(util.getSiteUrl(), util.getAdminUserLogin(), "incorrectPassword");

//check if error message appears
$(By.xpath("/html/body/div[4]/div/div[2]/div[1]/ul/li/div/div/div/span")).shouldHave(text("Invalid username and/or password."));

close();
}


/**
* open browser window with the specified siteUrl
*/
@Test
public void loginAndStay(){
open(util.getSiteUrl());
//perform login
login(siteUrl, userLogin, userPassword);
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 siteUrl, String username, String password) {
//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();
}

}
@@ -0,0 +1,69 @@
package com.evolveum.midpoint.testing.selenide.tests;

import com.codeborne.selenide.SelenideElement;
import org.openqa.selenium.By;
import org.springframework.stereotype.Component;
import org.testng.annotations.Test;

import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.close;
import static com.codeborne.selenide.Selenide.open;

/**
* Created by Kate on 13.08.2015.
*/
@Component
public class Util {
private String siteUrl;
private String adminUserLogin;
private String adminUserPassword;



/**
*close browser window
*/
@Test
public void closeTest(){
close();
}
/**
* Looks for the element with specified searchText
* and returns the first element from the search results
* @param searchText
* @return
*/
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;
}

public void setSiteUrl(String siteUrl) {
this.siteUrl = siteUrl;
}

public String getAdminUserLogin() {
return adminUserLogin;
}

public void setAdminUserLogin(String adminUserLogin) {
this.adminUserLogin = adminUserLogin;
}

public String getAdminUserPassword() {
return adminUserPassword;
}

public void setAdminUserPassword(String adminUserPassword) {
this.adminUserPassword = adminUserPassword;
}

}
Expand Up @@ -5,6 +5,8 @@
*/

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 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.UserUtil;
Expand All @@ -17,38 +19,46 @@
import static com.codeborne.selenide.Selenide.$;

@Component
public class CreateAccountTest extends BaseTest{
public class CreateAccountTest extends BaseTest {

@Autowired
LoginTest loginTest;

@Autowired
UserUtil userUtil;

@Autowired
ResourceUtil resourceUtil;
Util util;

@Autowired
ImportResourceTest importResourceTest;
ResourceUtil resourceUtil;

@Autowired
BaseTest baseTest;
ImportResourceTest importResourceTest;

/**
* Prerequirement: Test user is to be created (see CreateUserTest.createUserTest())
*/
@Test
public void createOpendjAccountForUser(){
public void createAccountForUserTest(){
//open Users page
userUtil.openListUsersPage();

//search for user in users list
userUtil.searchForUser(userUtil.getTestUserName()).shouldBe(visible).click();
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();

//click on the menu icon in the Accounts section
$(By.xpath("/html/body/div[4]/div/form/div[3]/div[2]/div[1]/div/div[2]/ul/li/a")).shouldBe(visible).click();
//click on the Add account menu item
$(By.linkText("Add account")).shouldBe(visible).click();

//search for OpenDJ resource in resources list in the opened Select resource(s) window
resourceUtil.searchForOpendjResource(resourceUtil.getTestResourceName(), "/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[2]/div");
//search for resource in resources list in the opened Select resource(s) window
util.searchForElement(resourceUtil.getTestResourceName(),
"/html/body/div[6]/form/div/div[2]/div/div/div/div[2]/div/div/div/div/div/div[1]/form/span/a");
$(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[2]/div"))
.shouldHave(text(resourceUtil.getTestResourceName()));

//select check box in the first row for "Localhost OpenDJ (no extension schema)" resource
$(By.name("resourcePopup:content:table:table:body:rows:4:cells:1:cell:check")).shouldBe(visible).click();
Expand All @@ -68,7 +78,9 @@ public void createOpendjAccountForUser(){
$(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
userUtil.searchForUser(userUtil.getTestUserName()).shouldBe(visible).click();
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();

//check if the created account is displayed in the Accounts section
$(By.linkText(resourceUtil.getTestResourceName())).shouldBe(visible);
Expand Down
@@ -1,38 +1,45 @@
package com.evolveum.midpoint.testing.selenide.tests.resource;

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.title;

/**
* Created by Kate on 09.08.2015.
*/
@Component
public class CheckResourceConnectionTest extends BaseTest{
public class CheckResourceConnectionTest extends BaseTest {

@Autowired
ImportResourceTest importResourceTest;

@Autowired
BaseTest baseTest;
LoginTest loginTest;

@Autowired
Util util;

@Autowired
ResourceUtil resourceUtil;

@Test
public void checkOpendjResourceConnectionTest(){
public void checkResourceConnectionTest(){
//open Resources -> List Resources
$(By.xpath("/html/body/div[3]/div/div[2]/ul[1]/li[4]/a")).shouldHave(text("Resources")).click();
$(By.linkText("List resources")).click();

//search for OpenDJ resource in resources list
resourceUtil.searchForOpendjResource(resourceUtil.getTestResourceName(), "/html/body/div[4]/div/form[2]/div[2]/table/tbody/tr/td[2]/div/a/span").click();
//search for resource in resources list
util.searchForElement(resourceUtil.getTestResourceName(), "/html/body/div[4]/div/form[1]/span/a");
$(By.xpath("/html/body/div[4]/div/form[2]/div[2]/table/tbody/tr/td[2]/div/a/span")).click();
//click on resource link
$(By.linkText(resourceUtil.getTestResourceName())).click();

//click Test connection button
$(By.xpath("/html/body/div[4]/div/form/div[4]/a[1]")).should(appear).click();
Expand Down

0 comments on commit 27edf75

Please sign in to comment.