Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Jul 3, 2018
2 parents eb794ea + 3d4654b commit 38c0226
Show file tree
Hide file tree
Showing 15 changed files with 287 additions and 156 deletions.
Expand Up @@ -4,6 +4,13 @@
import com.evolveum.midpoint.schrodinger.component.LoggedUser;
import com.evolveum.midpoint.schrodinger.page.LoginPage;
import org.apache.commons.lang3.Validate;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
* Created by Viliam Repan (lazyman).
*/
Expand All @@ -15,17 +22,24 @@ public class MidPoint {
public static long TIMEOUT_MEDIUM = 6000;
public static long TIMEOUT_LONG = 60000;

public MidPoint(EnvironmentConfiguration environment) {
private static final String SCHRODINGER_PROPERTIES = "./src/test/resources/configuration/schrodinger.properties";

private String webDriver;
private String webdriverLocation;

public MidPoint(EnvironmentConfiguration environment) throws IOException {
Validate.notNull(environment, "Environment configuration must not be null");

this.environment = environment;

init();
}

private void init() {
private void init() throws IOException {
environment.validate();
//System.setProperty("webdriver.chrome.driver", "C:\\Users\\matus\\chromedriver\\chromedriver.exe"); // TODO workaround, find proper way how to resolve
fetchProperties();

System.setProperty(webDriver, webdriverLocation);
System.setProperty("selenide.browser", environment.getDriver().name().toLowerCase());
System.setProperty("selenide.baseUrl", environment.getBaseUrl());

Expand All @@ -36,20 +50,26 @@ public LoginPage login() {
return new LoginPage();
}

// public static FluentWait waitWithIgnoreMissingElement() {
//
// FluentWait wait = new FluentWait(environment.getDriver())
// .withTimeout(TIMEOUT_MEDIUM, MILLISECONDS)
// .pollingEvery(100, MILLISECONDS)
// .ignoring(NoSuchElementException.class).ignoring(org.openqa.selenium.TimeoutException.class);
//
// return wait;
// }


public MidPoint logout() {
new LoggedUser().logout();

return this;
}

private void fetchProperties() throws IOException {

Properties schrodingerProperties = new Properties();
InputStream input = null;

try {
input = new FileInputStream(SCHRODINGER_PROPERTIES);
schrodingerProperties.load(input);

webDriver = schrodingerProperties.getProperty("webdriver");
webdriverLocation = schrodingerProperties.getProperty("webdriverLocation");

} catch (IOException e) {
throw new IOException("An exception was thrown during Schrodinger initialization" + e.getLocalizedMessage());
}
}
}
@@ -1,6 +1,7 @@
package com.evolveum.midpoint.schrodinger.component;

import com.codeborne.selenide.Condition;
import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.SelenideElement;
import com.evolveum.midpoint.schrodinger.MidPoint;
import com.evolveum.midpoint.schrodinger.component.common.DropDown;
Expand All @@ -19,8 +20,17 @@ public FocusSetAssignmentsModal(T parent, SelenideElement parentElement) {
}

public FocusSetAssignmentsModal<T> selectType(String option) {
$(By.name("mainPopup:content:popupBody:type:input"))
.waitUntil(Condition.appears, MidPoint.TIMEOUT_DEFAULT).selectOption(option);
SelenideElement tabElement = $(Schrodinger.byElementValue("a", "class", "tab-label", option))
.waitUntil(Condition.appears, MidPoint.TIMEOUT_DEFAULT);

String classActive = tabElement.attr("class");

tabElement.click();
if (!classActive.contains("active")) {
$(Schrodinger.byElementValue("a", "class", "tab-label", option))
.waitUntil(Condition.attribute("class", classActive + " active"), MidPoint.TIMEOUT_DEFAULT).exists();
}


return this;
}
Expand Down
Expand Up @@ -26,14 +26,7 @@ public PrismForm<AbstractTable<T>> clickByName(String name) {

@Override
public AbstractTable<T> selectCheckboxByName(String name) {
SelenideElement parent = $(Schrodinger.byElementValue(null, "data-s-id", "cell", name))
.waitUntil(Condition.appears, MidPoint.TIMEOUT_DEFAULT).parent();

String row = parent.getAttribute("data-s-id").toString();

System.out.println("The Parent + " + parent.innerHtml() + " The row" + row);

parent.$(Schrodinger.byElementAttributeValue("input", "name", constructCheckBoxIdBasedOnRow(row)))
$(Schrodinger.byAncestorFollowingSiblingElementValue("input", "type", "checkbox", "data-s-id", "3", name))
.waitUntil(Condition.appears, MidPoint.TIMEOUT_DEFAULT).click();

return this;
Expand Down
Expand Up @@ -179,7 +179,7 @@ private SelenideElement findProperty(String name) {

} else {
element = $(By.xpath("//span[@data-s-id=\"label\"][contains(.,\"" + name + "\")]/.."))
.waitUntil(Condition.visible, MidPoint.TIMEOUT_DEFAULT).parent();
.parent().waitUntil(Condition.visible, MidPoint.TIMEOUT_DEFAULT);
}

return element;
Expand Down
Expand Up @@ -26,7 +26,6 @@
import org.openqa.selenium.By;



import static com.codeborne.selenide.Selenide.$;

/**
Expand Down Expand Up @@ -60,21 +59,13 @@ public Table<T> selectAll() {
}

public boolean currentTableContains(String name) {
// Small time out period, might be a problem if table loads for a long time
// TODO Catching the exception in such way might be a problem, find solution with wait+pooling interval


// FluentWait wait = MidPoint.waitWithIgnoreMissingElement();
// Boolean isPresent = (Boolean) wait.until(new Function() {
// @Nullable
// @Override
// public Boolean apply(@Nullable Object o) {
//
// return $(Schrodinger.byElementValue("Span", name)).is(Condition.visible);
// }
// });

return $(Schrodinger.byElementValue("Span", name)).is(Condition.visible);
// TODO replate catch Throwable with some less generic error
try {
return $(Schrodinger.byElementValue("Span", name)).waitUntil(Condition.visible, MidPoint.TIMEOUT_MEDIUM).is(Condition.visible);
} catch (Throwable t) {
return false;
}

}

Expand Down
Expand Up @@ -6,13 +6,22 @@
import com.evolveum.midpoint.schrodinger.util.Schrodinger;
import org.openqa.selenium.By;

//import com.evolveum.midpoint.util.logging.Trace;
//import com.evolveum.midpoint.util.logging.TraceManager;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static com.codeborne.selenide.Selenide.$;

/**
* Created by Viliam Repan (lazyman).
*/
public class AboutPage extends BasicPage {

// public static Trace LOGGER = TraceManager.getTrace(AboutPage.class);

public AboutPage repositorySelfTest() {
$(Schrodinger.byDataResourceKey("PageAbout.button.testRepository")).click();
return this;
Expand Down Expand Up @@ -67,10 +76,56 @@ public String connIdFrameworkVersion() {
return $(Schrodinger.bySchrodingerDataId("provisioningDetailValue")).parent().getText();
}

public List<String> getJVMproperties() {
SelenideElement jvmProperties = $(Schrodinger.byDataId("jvmProperties"));
String jvmPropertiesText = jvmProperties.getText();

List<String> listOfProperties = new ArrayList<>();
if (jvmPropertiesText != null && !jvmPropertiesText.isEmpty()) {
String[] properties = jvmPropertiesText.split("\\r?\\n");

listOfProperties = Arrays.asList(properties);

} else {
// LOGGER.info("JVM properties not found";

}

return listOfProperties;
}

public String getJVMproperty(String property) {

List<String> listOfProperties = getJVMproperties();

if (property != null && !property.isEmpty()) {

for (String keyPair : listOfProperties) {

String[] pairs = keyPair.split("\\=");

if (pairs != null && pairs.length > 1) {
if (pairs[0].equals(property)) {
return pairs[1];
}
} else if (pairs.length == 1) {
if (pairs[0].contains(property)) {
return pairs[0];
}

}
}
}

return "";
}


public FeedbackBox<AboutPage> feedback() {
SelenideElement feedback = $(By.cssSelector("div.feedbackContainer"));

return new FeedbackBox<>(this, feedback);
}

}

21 changes: 21 additions & 0 deletions tools/schrodinger/src/test/java/schrodinger/AboutPageTest.java
Expand Up @@ -15,6 +15,9 @@ public class AboutPageTest extends TestBase {
private static final String CONNID_VERSION_EXPECTED = "1.4.3.11"; // Static value, should be changed each version change.
private static final String REINDEX_REPO_TASK_CATEGORY_EXPECTED = "Utility";
private static final String REINDEX_REPO_TASK_DISPLAY_NAME_EXPECTED = "Reindex repository objects";

private static final String PROPERTY_NAME_XMX = "-Xmx";

private AboutPage aboutPage;

@BeforeMethod
Expand Down Expand Up @@ -95,4 +98,22 @@ public void checkReindexRepositoryObjectsDisplayName() {
.fetchDisplayName()
, REINDEX_REPO_TASK_DISPLAY_NAME_EXPECTED);
}

@Test
public void checkJVMPropertiesMidpointHome(){

Assert.assertTrue(
!aboutPage.getJVMproperty(TestBase.PROPERTY_NAME_MIDPOINT_HOME).isEmpty()
);

}

@Test
public void checkJVMPropertiesXmx(){

Assert.assertTrue(
!aboutPage.getJVMproperty(PROPERTY_NAME_XMX).isEmpty()
);

}
}
55 changes: 51 additions & 4 deletions tools/schrodinger/src/test/java/schrodinger/TestBase.java
Expand Up @@ -21,13 +21,17 @@
import com.evolveum.midpoint.schrodinger.MidPoint;
import com.evolveum.midpoint.schrodinger.page.BasicPage;
import com.evolveum.midpoint.schrodinger.page.LoginPage;
import com.evolveum.midpoint.schrodinger.page.configuration.AboutPage;
import com.evolveum.midpoint.schrodinger.page.configuration.ImportObjectPage;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.*;

import javax.naming.ConfigurationException;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;

/**
Expand All @@ -41,13 +45,16 @@ public abstract class TestBase {
public static final String USERNAME = "administrator";
public static final String PASSWORD = "5ecr3t";

public static final String PROPERTY_NAME_MIDPOINT_HOME = "-Dmidpoint.home";

private static final Logger LOG = LoggerFactory.getLogger(TestBase.class);
protected static File CSV_TARGET_DIR;

protected MidPoint midPoint;
protected BasicPage basicPage;

@BeforeClass
public void beforeClass() {
public void beforeClass() throws IOException {
LOG.info("Starting tests in class {}", getClass().getName());

EnvironmentConfiguration config = new EnvironmentConfiguration();
Expand All @@ -74,11 +81,11 @@ public void afterMethod(Method method) {
LOG.info("Finished test {}.{}", method.getDeclaringClass().getName(), method.getName());
}

protected void importObject(File source,Boolean overrideExistingObject) {
protected void importObject(File source, Boolean overrideExistingObject) {

ImportObjectPage importPage = basicPage.importObject();

if(overrideExistingObject){
if (overrideExistingObject) {
importPage
.checkOverwriteExistingObject();
}
Expand All @@ -93,7 +100,47 @@ protected void importObject(File source,Boolean overrideExistingObject) {
}

protected void importObject(File source) {
importObject(source,false);
importObject(source, false);
}


protected String fetchMidpointHome() throws ConfigurationException {

AboutPage aboutPage = basicPage.aboutPage();
String homeDir = aboutPage.getJVMproperty(PROPERTY_NAME_MIDPOINT_HOME);

if (homeDir != null && !homeDir.isEmpty()) {

return homeDir;
} else {

LOG.error("Midpoint home parameter is empty!");
throw new ConfigurationException("Midpoint home parameter is empty ,please add the -Dmidpoint.home parameter to the jvm configuration");

}

}

protected File initTestDirectory(String dir) throws ConfigurationException, IOException {

String home = fetchMidpointHome();
File parentDir = new File(home, "schrodinger");
parentDir.mkdir();
CSV_TARGET_DIR = new File(parentDir, dir);

if (CSV_TARGET_DIR.mkdir()) {

return CSV_TARGET_DIR;
} else {
if (CSV_TARGET_DIR.exists()) {

FileUtils.cleanDirectory(CSV_TARGET_DIR);
return CSV_TARGET_DIR;
} else {

throw new IOException("Creation of directory \"" + CSV_TARGET_DIR.getName() + "\" unsuccessful");
}
}
}

}

0 comments on commit 38c0226

Please sign in to comment.