-
Notifications
You must be signed in to change notification settings - Fork 584
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2172 Add sample usage for "step" method
"step" feature was released in Selenide 6.14.0, see https://selenide.org/2023/05/08/selenide-6.14.0/#add-step-method
- Loading branch information
Showing
5 changed files
with
118 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package integration; | ||
|
||
import com.codeborne.selenide.logevents.EventsCollector; | ||
import com.codeborne.selenide.logevents.LogEvent; | ||
import com.codeborne.selenide.logevents.SelenideLogger; | ||
import com.codeborne.selenide.logevents.SimpleReport; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import javax.annotation.CheckReturnValue; | ||
import javax.annotation.Nonnull; | ||
import javax.annotation.ParametersAreNonnullByDefault; | ||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
import static com.codeborne.selenide.Condition.text; | ||
import static com.codeborne.selenide.Selenide.$; | ||
import static com.codeborne.selenide.Selenide.open; | ||
import static com.codeborne.selenide.SetValueOptions.withDate; | ||
import static com.codeborne.selenide.logevents.SelenideLogger.step; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class StepsTest extends IntegrationTest { | ||
private final EventsCollector events = new EventsCollector(); | ||
|
||
@Test | ||
void canUseInnerSteps() { | ||
step("Edit CV", () -> { | ||
String previousBirthday = step("open CV page", () -> { | ||
openFile("page_with_date_input.html"); | ||
return $("#birthday").val(); | ||
}); | ||
|
||
step("invalid birthday", () -> { | ||
$("#birthday").setValue(withDate(LocalDate.parse("2099-01-01"))); | ||
$("#user-summary").shouldHave(text("User birthday: 2099-01-01")); | ||
}); | ||
|
||
step("valid birthday", () -> { | ||
$("#birthday").setValue(withDate(LocalDate.parse(previousBirthday))); | ||
$("#user-summary").shouldHave(text("User birthday: " + previousBirthday)); | ||
}); | ||
}); | ||
|
||
List<String> steps = stepsFromReport(); | ||
|
||
assertThat(steps).containsExactly( | ||
"| Element |", | ||
"| Edit CV |", | ||
"| open CV page |", | ||
"| open |", | ||
"| #birthday |", | ||
"| invalid birthday |", | ||
"| #birthday |", | ||
"| #user-summary |", | ||
"| valid birthday |", | ||
"| #birthday |", | ||
"| #user-summary |" | ||
); | ||
} | ||
|
||
@Nonnull | ||
@CheckReturnValue | ||
private List<String> stepsFromReport() { | ||
String report = SimpleReportTester.report(events.events()); | ||
|
||
return report.lines() | ||
.filter(line -> line.startsWith("|")) | ||
.map(line -> line.replaceFirst("(\\|.+?\\|).*", "$1")) | ||
.toList(); | ||
} | ||
|
||
@ParametersAreNonnullByDefault | ||
private static class SimpleReportTester extends SimpleReport { | ||
@Nonnull | ||
@CheckReturnValue | ||
static String report(List<LogEvent> events) { | ||
return new SimpleReportTester().generateReport("", events); | ||
} | ||
} | ||
|
||
@BeforeEach | ||
void setUp() { | ||
open(); | ||
SelenideLogger.addListener("StepsTest.listener", events); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
SelenideLogger.removeListener("StepsTest.listener"); | ||
} | ||
} |