From ae3b16b9b8ed8bff4241ac81faa3addfd056a724 Mon Sep 17 00:00:00 2001 From: Andrey Surzhan Date: Sun, 3 May 2015 18:27:36 +0300 Subject: [PATCH] Add remove existed External links method Add method allows to remove existed and remained External Links in case if tests won't be able to clean up after their execution. This method will be executed before tesing class execution. Update login pattern for w3c tests, make it as in fuctional test --- .../tests/jcommune/ExternalLinksTest.java | 6 ++--- html-w3c-tests/src/test/resources/log4j.xml | 2 +- .../webdriver/action/ExternalLinks.java | 22 ++++++++++++++++++- .../webdriver/page/ExternalLinksDialog.java | 13 +++++++++++ 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/ExternalLinksTest.java b/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/ExternalLinksTest.java index f41372cc..f562cf13 100644 --- a/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/ExternalLinksTest.java +++ b/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/ExternalLinksTest.java @@ -7,10 +7,7 @@ import org.jtalks.tests.jcommune.webdriver.exceptions.ValidationException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; +import org.testng.annotations.*; import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; import static org.jtalks.tests.jcommune.utils.TestStringUtils.randomUrl; @@ -32,6 +29,7 @@ public void signInAsAdmin(String appUrl) { mainPage.logOutIfLoggedIn(driver); try { Users.signIn(User.admin()); + ExternalLinks.removeExistedExternalLinks(); } catch (ValidationException e) { logger.error("Can't login by user [{}]", User.admin().getUsername()); throw new IllegalStateException("Can't login by user " + User.admin().getUsername()); diff --git a/html-w3c-tests/src/test/resources/log4j.xml b/html-w3c-tests/src/test/resources/log4j.xml index f7f169f2..fffc6799 100644 --- a/html-w3c-tests/src/test/resources/log4j.xml +++ b/html-w3c-tests/src/test/resources/log4j.xml @@ -20,7 +20,7 @@ - + diff --git a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/ExternalLinks.java b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/ExternalLinks.java index f5e489ed..cc05549a 100644 --- a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/ExternalLinks.java +++ b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/ExternalLinks.java @@ -1,7 +1,6 @@ package org.jtalks.tests.jcommune.webdriver.action; import junit.framework.AssertionFailedError; -import org.jtalks.tests.jcommune.assertion.Existence; import org.jtalks.tests.jcommune.utils.DriverMethodHelp; import org.jtalks.tests.jcommune.webdriver.JCommuneSeleniumConfig; import org.jtalks.tests.jcommune.webdriver.entity.externallink.ExternalLink; @@ -13,6 +12,7 @@ import org.slf4j.LoggerFactory; import ru.yandex.qatools.allure.annotations.Step; +import java.util.Iterator; import java.util.List; import static org.jtalks.tests.jcommune.utils.ReportNgLogger.info; @@ -158,4 +158,24 @@ private static WebElement getLinkLine(ExternalLink externalLink) { } return null; } + + public static void removeExistedExternalLinks() { + info("Remove existed External links"); + openExternalLinksDialog(); + List links = externalLinksDialog.getExternalLinksFromDialog(); + Iterator iterator = links.iterator(); + if (links.size() != 0) { + LOGGER.info("Going to remove {} links", links.size()); + while (iterator.hasNext()) { + WebElement link = iterator.next(); + externalLinksDialog.clickFistTrashIconButton(); + externalLinksDialog.clickRemoveLinkButton(); + sleep(500); + iterator.remove(); + } + }else { + LOGGER.info("There are no External links. There is nothing to remove"); + externalLinksDialog.closeDialog(); + } + } } diff --git a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/ExternalLinksDialog.java b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/ExternalLinksDialog.java index 4c3d345d..8ba884bf 100644 --- a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/ExternalLinksDialog.java +++ b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/ExternalLinksDialog.java @@ -14,6 +14,7 @@ public class ExternalLinksDialog { public static final String externalLinksFromDialogSel = "//div[@class='modal-body']/table/tbody/tr"; public static final String externalLinksHrefFromDialogSel = "td[@class='link-url']"; + public static final String firstTrachIconSel = "/html/body/form/div[2]/table/tbody/tr[1]/td[5]/a"; //class name public static final String externalLinksRemoveIconFromDialogSel = "icon-trash"; public static final String externalLinksEditIconFromDialogSel = "icon-pencil"; @@ -40,6 +41,8 @@ public class ExternalLinksDialog { private WebElement closeDialogButton; @FindBy(xpath = externalLinksFromDialogSel) private List externalLinksFromDialog; + @FindBy(xpath = firstTrachIconSel) + private WebElement firstTrachIconButton; public ExternalLinksDialog(WebDriver driver) { PageFactory.initElements(driver, this); @@ -90,6 +93,12 @@ public void clickRemoveLinkButton() { removeLinkBut.click(); } + @Step + public void clickFistTrashIconButton() { + info("Clicking First Trash icon button"); + firstTrachIconButton.click(); + } + public List getExternalLinks() { return externalLinks; } @@ -97,4 +106,8 @@ public List getExternalLinks() { public List getExternalLinksFromDialog() { return externalLinksFromDialog; } + + public WebElement getFirstTrachIconButton() { + return firstTrachIconButton; + } }