Skip to content

Commit

Permalink
Merge pull request telekom#454 from telekom/feature/page-assertions
Browse files Browse the repository at this point in the history
Remove deprecated assertions
  • Loading branch information
martingrossmann authored Sep 25, 2024
2 parents 48526aa + bc47720 commit 89e4ae6
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 321 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,13 @@ private TesterraProperties() {
@Deprecated
public static final String PERF_PAGE_THINKTIME_MS = "tt.perf.page.thinktime.ms";

/**
* If true, screenshot after page is loaded will be taken.
*/
public static final String SCREENSHOT_ON_PAGELOAD = "tt.screenshot.on.pageload";

public static final String SYSTEM_SETTINGS_FILE = "tt.system.settings.file";

public static final String RUNCFG = "tt.runcfg";

public static final String WATCHDOG_ENABLE = "tt.watchdog.enable";
public static final String WATCHDOG_TIMEOUT_SECONDS = "tt.watchdog.timeout.seconds";

public static final String SCREENCASTER_ACTIVE_ON_SUCCESS = "tt.screencaster.active.on.success";
public static final String SCREENCASTER_ACTIVE_ON_FAILED = "tt.screencaster.active.on.failed";

/**
* @deprecated Use {@link Properties#SELENIUM_SERVER_URL} instead
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,19 @@
*/
package eu.tsystems.mms.tic.testframework.pageobjects;

import eu.tsystems.mms.tic.testframework.common.PropertyManager;
import eu.tsystems.mms.tic.testframework.common.Testerra;
import eu.tsystems.mms.tic.testframework.constants.TesterraProperties;
import eu.tsystems.mms.tic.testframework.exceptions.ElementNotFoundException;
import eu.tsystems.mms.tic.testframework.internal.Nameable;
import eu.tsystems.mms.tic.testframework.internal.StopWatch;
import eu.tsystems.mms.tic.testframework.internal.asserts.PropertyAssertionConfig;
import eu.tsystems.mms.tic.testframework.pageobjects.internal.AbstractPage;
import eu.tsystems.mms.tic.testframework.pageobjects.internal.DefaultPageAssertions;
import eu.tsystems.mms.tic.testframework.pageobjects.internal.PageUiElementFinder;
import eu.tsystems.mms.tic.testframework.pageobjects.internal.asserts.PageAssertions;
import eu.tsystems.mms.tic.testframework.report.Report;
import eu.tsystems.mms.tic.testframework.utils.TimerUtils;
import java.util.Random;
import org.openqa.selenium.WebDriver;

/**
* Represents a full web page and provides advanced {@link PageObject}.
*
* @author Peter Lehmann
* @author Mike Reiche
* @todo Should be an interface only
Expand Down Expand Up @@ -128,17 +123,6 @@ public WebDriver getWebDriver() {
// TimerUtils.sleep(timeToWait);
// }

/**
* Waits for a text to be not present.
*
* @return boolean true if success == text is not present. false otherwise.
*/
@Deprecated
public boolean waitForIsNotTextPresentWithDelay(final String text, final int delayInSeconds) {
TimerUtils.sleep(delayInSeconds * 1000);
return waitForIsNotTextPresent(text);
}

protected UiElementFinder getFinder() {
return this.finder;
}
Expand All @@ -153,86 +137,13 @@ protected UiElement findDeep(Locator locator) {
return getFinder().findDeep(locator);
}

/**
* Waits for a text to be not present.
*
* @return boolean true if success == text is not present. false otherwise.
*/
@Deprecated
public boolean waitForIsNotTextDisplayedWithDelay(final String text, final int delayInSeconds) {
TimerUtils.sleep(delayInSeconds * 1000);
return waitForIsNotTextDisplayed(text);
}

@Override
protected void pageLoaded() {
if (PropertyManager.getBooleanProperty(TesterraProperties.SCREENSHOT_ON_PAGELOAD, false)) {
if (Testerra.Properties.SCREENSHOT_ON_PAGELOAD.asBool()) {
this.screenshotToReport();
}
}

/**
* Waits for a text to be not present.
*
* @return boolean true if success == text is not present. false otherwise.
*/
@Deprecated
public boolean waitForIsNotTextPresent(final String text) {
return anyElementContainsText(text).waitFor().present(false);
}

/**
* Waits for a text to be not displayed.
*
* @return boolean true if success == text is not present. false otherwise.
*/
@Deprecated
public boolean waitForIsNotTextDisplayed(final String text) {
return anyElementContainsText(text).waitFor().displayed(false);
}

@Deprecated
public void assertIsTextPresent(String text, String description) {
assertIsTextPresent(text);
}

@Deprecated
public void assertIsTextDisplayed(String text, String description) {
assertIsTextDisplayed(text);
}

@Deprecated
public void assertIsTextPresent(String text) {
anyElementContainsText(text).expect().present().is(true);
}

@Deprecated
public void assertIsTextDisplayed(String text) {
anyElementContainsText(text).expect().displayed().is(true);
}

@Deprecated
public void assertIsNotTextPresent(String text) {
anyElementContainsText(text).expect().present().is(false);
}

@Deprecated
public void assertIsNotTextDisplayed(String text) {
try {
anyElementContainsText(text).expect().displayed().is(false);
} catch (AssertionError error) {
if (error.getCause() instanceof ElementNotFoundException) {
// ignore this
} else {
throw error;
}
}
}

private TestableUiElement anyElementContainsText(String text) {
return this.getFinder().findDeep(XPath.from("*").text().contains(text));
}

@Override
public PageAssertions waitFor(int seconds) {
PropertyAssertionConfig config = new PropertyAssertionConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import eu.tsystems.mms.tic.testframework.annotations.PageOptions;
import eu.tsystems.mms.tic.testframework.common.Testerra;
import eu.tsystems.mms.tic.testframework.enums.CheckRule;
import eu.tsystems.mms.tic.testframework.exceptions.PageFactoryException;
import eu.tsystems.mms.tic.testframework.logging.Loggable;
import eu.tsystems.mms.tic.testframework.pageobjects.AbstractComponent;
import eu.tsystems.mms.tic.testframework.pageobjects.Check;
Expand All @@ -38,78 +37,76 @@
import eu.tsystems.mms.tic.testframework.pageobjects.internal.action.AbstractFieldAction;
import eu.tsystems.mms.tic.testframework.pageobjects.internal.action.GuiElementCheckFieldAction;
import eu.tsystems.mms.tic.testframework.pageobjects.internal.action.SetNameFieldAction;
import eu.tsystems.mms.tic.testframework.pageobjects.internal.asserts.PageAssertions;
import eu.tsystems.mms.tic.testframework.testing.TestControllerProvider;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

/**
* This is an abstract page object used for {@link Page} and {@link AbstractComponent}.
* Provides basic {@link PageObject} related features:
* Supports element {@link Check}
* Supports {@link PageOptions}
* Supports element {@link Check}
* Supports {@link PageOptions}
* Livecycle methods for {@link #checkUiElements(CheckRule)}:
* {@link #checkPagePreparation()}
* {@link #addCustomFieldActions}
* {@link #assertPageIsNotShown()} or {@link #assertPageIsNotShown()}
* {@link #checkPageErrorState(Throwable)}
* @see {https://martinfowler.com/bliki/PageObject.html}
* {@link #checkPagePreparation()}
* {@link #addCustomFieldActions}
* <p>
* {@link #checkPageErrorState(Throwable)}
*
* @author Peter Lehmann
* @author Mike Reiche
* @todo Rename to AbstractPageObject
* @see {https://martinfowler.com/bliki/PageObject.html}
*/
public abstract class AbstractPage<SELF> implements
Loggable,
TestControllerProvider,
PageObject<SELF>,
LocatorFactoryProvider,
PageCreator
{
PageCreator {
protected static final PageFactory pageFactory = Testerra.getInjector().getInstance(PageFactory.class);

abstract protected UiElement find(Locator locator);

abstract protected UiElement findDeep(Locator locator);

protected UiElement findById(Object id) {
return find(LOCATE.by(By.id(id.toString())));
}

protected UiElement findByQa(String qa) {
return find(LOCATE.byQa(qa));
}

protected UiElement find(By by) {
return find(LOCATE.by(by));
}

protected UiElement find(XPath xPath) {
return find(LOCATE.by(xPath));
}
protected UiElement findDeep(XPath xPath) { return findDeep(LOCATE.by(xPath)); }
protected UiElement findDeep(By by) { return findDeep(LOCATE.by(by)); }

protected UiElement findDeep(XPath xPath) {
return findDeep(LOCATE.by(xPath));
}

protected UiElement findDeep(By by) {
return findDeep(LOCATE.by(by));
}

protected UiElement createEmpty() {
return createEmpty(LOCATE.by(By.tagName("empty")));
}

protected UiElement createEmpty(Locator locator) {
return new EmptyUiElement(this, locator);
}

/**
* Calls the assertPageIsShown method.
*/
private void checkAdditional(CheckRule checkRule) {
switch (checkRule) {
case IS_NOT_PRESENT:
case IS_NOT_DISPLAYED:
assertPageIsNotShown();
break;
default:
assertPageIsShown();
}
}

/**
* Package private accessible by {@link PageFactory}
*/
Expand All @@ -121,34 +118,12 @@ void checkUiElements() throws Throwable {
* Package private accessible by {@link PageFactory}
*/
void checkUiElements(CheckRule checkRule) throws Throwable {
pCheckPage(checkRule);
}

/**
* The call of this method is injected into the constructor of every page class or must be called from every page
* class constructor!!!
* If there are several subclasses each calling checkPage, it will be only called from the class of the calling instance.
* @deprecated Don't call this method on your own and use {@link eu.tsystems.mms.tic.testframework.pageobjects.factory.PageFactory#create(Class, WebDriver)} or {@link PageAssertions#displayed(boolean)} instead
*/
@Deprecated
public final void checkPage() {
try {
pCheckPage(CheckRule.DEFAULT);
} catch (Throwable throwable) {
throw new PageFactoryException(this.getClass(), getWebDriver(), throwable);
}
}

public abstract String getName(boolean detailed);

private void pCheckPage(CheckRule checkRule) throws Throwable {
/*
page checks
*/
checkPagePreparation();
try {
checkAnnotatedFields(checkRule);
checkAdditional(checkRule);
} catch (Throwable throwable) {
// call page error state logic
checkPageErrorState(throwable);
Expand All @@ -157,6 +132,8 @@ private void pCheckPage(CheckRule checkRule) throws Throwable {
pageLoaded();
}

public abstract String getName(boolean detailed);

/**
* Allows pages to run code before performing checkpage
*/
Expand All @@ -166,6 +143,7 @@ protected void checkPagePreparation() {
protected void pageLoaded() {

}

/**
* Method entered when checkPage runs into an error (catching any throwable). You can throw a new throwable that
* should be stacked onto the checkpage error (like new RuntimeException("bla", throwable) ).
Expand Down Expand Up @@ -243,25 +221,9 @@ private List<Class<? extends AbstractPage>> collectAllSuperClasses() {
running = false;
}
}
/**
* Revert classes order to bottom up
* @todo Why? There is no reason
*/
//Collections.reverse(allClasses);
return allClasses;
}

/**
* Empty method to be overriden. Can perform some (additional) checks on page objects.
*/
@Deprecated
public void assertPageIsShown() {
}

@Deprecated
public void assertPageIsNotShown() {
}

@Override
abstract public WebDriver getWebDriver();

Expand Down
Loading

0 comments on commit 89e4ae6

Please sign in to comment.