@MaximIs

Как избежать повторений в тестах?

Подскажите, пожалуйста, как избежать повторений открытия страницы MainPage в тестах, как здесь, например:
@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);
    }


Благодарю за подсказки.
  • Вопрос задан
  • 128 просмотров
Решения вопроса 1
@Vasvaller
В классе создай поле MainPage mainPage.
В новом методе помеченном аннотацией @Before инициализируй свой mainPage. Т.о. перед тестами будет сначала инициализироваться mainPage и ты сможешь исопльзовать его во всех тестах.
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
ApoFis_93
@ApoFis_93
имею верхнее техническое образование,
согласен с Vasvaller
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы