Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
Add remove existed External links method
Browse files Browse the repository at this point in the history
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 tests
  • Loading branch information
AndreySurzhan committed May 3, 2015
1 parent e940ad0 commit 102ad1f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion html-w3c-tests/src/test/resources/log4j.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
<param name="Encoding" value="utf8"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} [%-5p][%-10.10t][%32.32c] - %m%n"/>
<param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss}][%p][%X{testClass}][%X{testMethod}][%c{3}] - %m%n%n"/>
</layout>
</appender>
<logger name="org.restlet" additivity="false">
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -158,4 +158,24 @@ private static WebElement getLinkLine(ExternalLink externalLink) {
}
return null;
}

public static void removeExistedExternalLinks() {
info("Remove existed External links");
openExternalLinksDialog();
List<WebElement> links = externalLinksDialog.getExternalLinksFromDialog();
Iterator <WebElement> 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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -40,6 +41,8 @@ public class ExternalLinksDialog {
private WebElement closeDialogButton;
@FindBy(xpath = externalLinksFromDialogSel)
private List<WebElement> externalLinksFromDialog;
@FindBy(xpath = firstTrachIconSel)
private WebElement firstTrachIconButton;

public ExternalLinksDialog(WebDriver driver) {
PageFactory.initElements(driver, this);
Expand Down Expand Up @@ -90,11 +93,21 @@ public void clickRemoveLinkButton() {
removeLinkBut.click();
}

@Step
public void clickFistTrashIconButton() {
info("Clicking First Trash icon button");
firstTrachIconButton.click();
}

public List<WebElement> getExternalLinks() {
return externalLinks;
}

public List<WebElement> getExternalLinksFromDialog() {
return externalLinksFromDialog;
}

public WebElement getFirstTrachIconButton() {
return firstTrachIconButton;
}
}

0 comments on commit 102ad1f

Please sign in to comment.