Skip to content

Commit

Permalink
Added textOf() helper methods to the PageObject API
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed May 8, 2021
1 parent 8716de5 commit 27df7b7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<javassist.version>3.21.0-GA</javassist.version>
<xchart.version>3.5.2</xchart.version>
<!-- Kotlin config -->
<kotlin.version>1.4.31</kotlin.version>
<kotlin.version>1.4.32</kotlin.version>
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,6 @@ public void shouldNotBeVisible(final By byCriteria) {
}
}

private long waitForTimeoutInSecondsWithAMinimumOfOneSecond() {
return (getWaitForTimeout().getSeconds() < 1) ? 1 : (getWaitForTimeout().getSeconds());
}

public long waitForTimeoutInMilliseconds() {
return getWaitForTimeout().toMillis();
}
Expand Down Expand Up @@ -1008,6 +1004,22 @@ private String nameOf(WebElement webElement) {
return element(bySelector);
}

/**
* Return the text value of a given element
*/
public String textOf(WithLocator locator) { return $(locator).getText(); }
public String textOf(WithByLocator locator) { return $(locator).getText(); }
public String textOf(String xpathOrCssSelector, Object... arguments) { return $(xpathOrCssSelector, arguments).getText(); }
public String textOf(By bySelector) { return $(bySelector).getText(); }

/**
* Return the text value of a given element
*/
public String textContentOf(WithLocator locator) { return $(locator).getTextContent(); }
public String textContentOf(WithByLocator locator) { return $(locator).getTextContent(); }
public String textContentOf(String xpathOrCssSelector, Object... arguments) { return $(xpathOrCssSelector, arguments).getTextContent(); }
public String textContentOf(By bySelector) { return $(bySelector).getTextContent(); }

public ListOfWebElementFacades $$(String xpathOrCssSelector, Object... arguments) {
return findAll(xpathOrCssSelector, arguments);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ private void notifyStepSkippedFor(final Method method, final Object[] args) {
private void notifyOfStepFailure(final Object object, final Method method, final Object[] args,
final Throwable cause) throws Throwable {
ExecutedStepDescription description = ExecutedStepDescription.of(testStepClass, getTestNameFrom(method, args), args)
.withDisplayedFields(fieldValuesIn(object));
.withDisplayedFields(fieldValuesIn(object));

StepFailure failure = new StepFailure(description, cause);
StepEventBus.getEventBus().stepFailed(failure);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ExecutedStepDescription implements Cloneable {
private final List<Object> argumentsList;
private final List<String> convertedArgumentsList;
private final Map<String, Object> displayedFields;
// private final Object subject;
private boolean isAGroup;

private final static Map<String,Object> NO_FIELDS = new HashMap();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package net.serenitybdd.reports.model

import net.thucydides.core.model.DataTableRow
import net.thucydides.core.model.TestOutcome
import net.thucydides.core.model.TestResult.*
import net.thucydides.core.reports.TestOutcomes
import net.thucydides.core.reports.html.ReportNameProvider
import net.thucydides.core.requirements.ParentRequirementProvider
Expand All @@ -27,7 +25,7 @@ class UnstableFeaturesBuilder(val testOutcomes: TestOutcomes) {

fun withMaxOf(maxEntries: Int): List<UnstableFeature> {
return testOutcomes.unsuccessfulTests.outcomes
.groupBy { outcome -> defaultStoryNameOr(outcome.userStory?.displayName) }
.groupBy { outcome -> defaultStoryNameOr(outcome.userStory.displayName) }
.map { (userStoryName, outcomes) ->
UnstableFeature(userStoryName,
outcomes.size,
Expand All @@ -39,20 +37,7 @@ class UnstableFeaturesBuilder(val testOutcomes: TestOutcomes) {
.take(maxEntries)
}

private fun defaultStoryNameOr(displayName: String?): String = if (displayName != null) displayName else "Undefined Story"

private fun unsuccessfulOutcomesIn(testOutcomes: TestOutcomes) : Int {
return testOutcomes.outcomes.map { unsuccessfulOutcomesIn(it) }.sum()
}

private fun unsuccessfulOutcomesIn(outcome : TestOutcome) : Int {
if (outcome.isDataDriven) {
return outcome.dataTable.rows.count(this::isUnsuccessful)
}
return if (outcome.isError || outcome.isCompromised || outcome.isFailure) 1 else 0
}

private fun isUnsuccessful(row: DataTableRow) = row.result == FAILURE || row.result == ERROR || row.result == COMPROMISED
private fun defaultStoryNameOr(displayName: String?): String = displayName ?: "Undefined Story"

private fun percentageFailures(failingScenarios: Int, userStoryName: String, testOutcomes: TestOutcomes): Int {
val totalScenarios = TestOutcomes.of(testOutcomes.outcomes.filter {
Expand Down

0 comments on commit 27df7b7

Please sign in to comment.