Answer the question
In order to leave comments, you need to log in
How to avoid repetition in tests?
Please tell me how to avoid repeated opening of the MainPage page in tests, as here, for example:
@Test
public void IsTheActualTitleEqualledToTheExpectedTitle() {
String command = "git config --global user.name \"New Sheriff in Town\"" +
"\ngit reset $(git commit-tree HEAD^{tree} -m \"Legacy code\")" +
"\ngit push origin master --force";
MainPage mainPage = new MainPage(driver)
.openPage()
.clickNewPasteBtn()
.inputTextArea(command)
.selectPastSyntaxHighlightingFromDropDownList("Bash")
.selectPasteExpirationFromDropDownList("10 Minutes")
.inputTitle("how to gain dominance among developers")
.clickCreateNewPasteBtn();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class = 'info-top']/h1")));
String actualResult = driver.findElement(By.xpath("//div[@class = 'info-top']/h1")).getText();
Assert.assertEquals(actualResult, "how to gain dominance among developers");
}
@Test
public void IsTheActualSyntaxEqualledToTheExpectedSyntax() {
String command = "git config --global user.name \"New Sheriff in Town\"" +
"\ngit reset $(git commit-tree HEAD^{tree} -m \"Legacy code\")" +
"\ngit push origin master --force";
MainPage mainPage = new MainPage(driver)
.openPage()
.clickNewPasteBtn()
.inputTextArea(command)
.selectPastSyntaxHighlightingFromDropDownList("Bash")
.selectPasteExpirationFromDropDownList("10 Minutes")
.inputTitle("how to gain dominance among developers")
.clickCreateNewPasteBtn();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[text() = 'Bash']")));
String actualResult = driver.findElement(By.xpath("//a[text() = 'Bash']")).getText();
Assert.assertEquals(actualResult, "Bash");
}
@Test
public void IsTheActualCommandsEqalledToTheExpectedCommands() {
String command = "git config --global user.name \"New Sheriff in Town\"" +
"\ngit reset $(git commit-tree HEAD^{tree} -m \"Legacy code\")" +
"\ngit push origin master --force";
MainPage mainPage = new MainPage(driver)
.openPage()
.clickNewPasteBtn()
.inputTextArea(command)
.selectPastSyntaxHighlightingFromDropDownList("Bash")
.selectPasteExpirationFromDropDownList("10 Minutes")
.inputTitle("how to gain dominance among developers")
.clickCreateNewPasteBtn();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//ol[@class='bash']")));
String actualResult = driver.findElement(By.xpath("//ol[@class='bash']")).getText();
Assert.assertEquals(command, actualResult);
}
Answer the question
In order to leave comments, you need to log in
In the class, create the field MainPage mainPage.
In the new annotated method , initialize your mainPage. That. before tests, mainPage will be initialized first and you can use it in all tests.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question