#103 code refactoring

This commit is contained in:
Nightblade73 2019-05-13 20:13:53 +04:00
parent 451e7e5d04
commit 1f8722e3ff
3 changed files with 42 additions and 35 deletions

View File

@ -48,9 +48,7 @@ public class IndexConferenceTest extends TestTemplate {
conferencePage.setName(newConferenceName); conferencePage.setName(newConferenceName);
conferencePage.clickSaveBut(); conferencePage.clickSaveBut();
Assert.assertTrue(conferencesPage.getConferencesList() Assert.assertTrue(conferencesPage.checkNameInList(newConferenceName));
.stream()
.anyMatch(webElement -> webElement.getText().equals(newConferenceName)));
} }
@Test @Test
@ -61,15 +59,13 @@ public class IndexConferenceTest extends TestTemplate {
ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey());
ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
conferencesPage.getConferenceFirst(); conferencesPage.getFirstConference();
String newConferenceName = "test " + (new Date()).getTime(); String newConferenceName = "test " + (new Date()).getTime();
conferencePage.clearName(); conferencePage.clearName();
conferencePage.setName(newConferenceName); conferencePage.setName(newConferenceName);
conferencePage.clickSaveBut(); conferencePage.clickSaveBut();
Assert.assertTrue(conferencesPage.getConferencesList() Assert.assertTrue(conferencesPage.checkNameInList(newConferenceName));
.stream()
.anyMatch(webElement -> webElement.getText().equals(newConferenceName)));
} }
@Test @Test
@ -80,7 +76,7 @@ public class IndexConferenceTest extends TestTemplate {
ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey());
ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
conferencesPage.getConferenceFirst(); conferencesPage.getFirstConference();
String conferenceId = conferencePage.getId(); String conferenceId = conferencePage.getId();
Integer deadlineCount = conferencePage.getDeadlineCount(); Integer deadlineCount = conferencePage.getDeadlineCount();
@ -94,12 +90,7 @@ public class IndexConferenceTest extends TestTemplate {
getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId));
Assert.assertTrue(conferencePage.getDeadlineList() Assert.assertTrue(conferencePage.checkDeadline(description, dateValue));
.stream()
.anyMatch(webElement -> {
return webElement.findElement(By.className("deadline-text")).getAttribute("value").equals(description)
&& webElement.findElement(By.cssSelector("input[type=\"date\"]")).getAttribute("value").equals(dateValue);
}));
} }
@Test @Test
@ -110,7 +101,7 @@ public class IndexConferenceTest extends TestTemplate {
ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey());
ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
conferencesPage.getConferenceFirst(); conferencesPage.getFirstConference();
String conferenceId = conferencePage.getId(); String conferenceId = conferencePage.getId();
Integer membersCount = conferencePage.getMemberCount(); Integer membersCount = conferencePage.getMemberCount();
@ -120,7 +111,7 @@ public class IndexConferenceTest extends TestTemplate {
getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId));
Assert.assertTrue(membersCount + 1 == conferencePage.getMemberCount() Assert.assertTrue(membersCount + 1 == conferencePage.getMemberCount()
&& conferencePage.getTakePartButDisabledValue().equals("true")); && conferencePage.isTakePartButDisabledValueTrue());
} }
@Test @Test
@ -131,7 +122,7 @@ public class IndexConferenceTest extends TestTemplate {
ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey());
ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
conferencesPage.getConferenceFirst(); conferencesPage.getFirstConference();
String conferenceId = conferencePage.getId(); String conferenceId = conferencePage.getId();
Integer deadlineCount = conferencePage.getDeadlineCount(); Integer deadlineCount = conferencePage.getDeadlineCount();
@ -151,7 +142,7 @@ public class IndexConferenceTest extends TestTemplate {
ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey());
ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
conferencesPage.getConferenceFirst(); conferencesPage.getFirstConference();
String conferenceId = conferencePage.getId(); String conferenceId = conferencePage.getId();
Integer paperCount = conferencePage.getArticlesCount(); Integer paperCount = conferencePage.getArticlesCount();
@ -163,12 +154,7 @@ public class IndexConferenceTest extends TestTemplate {
getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId));
Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount() Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount()
&& conferencePage.getArticles() && conferencePage.checkArticle(paperName));
.stream()
.anyMatch(webElement -> webElement
.findElements(By.tagName("input"))
.get(1).getAttribute("value")
.equals(paperName)));
} }
@Test @Test
@ -179,7 +165,7 @@ public class IndexConferenceTest extends TestTemplate {
ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey());
ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
conferencesPage.getConferenceFirst(); conferencesPage.getFirstConference();
String conferenceId = conferencePage.getId(); String conferenceId = conferencePage.getId();
Integer paperCount = conferencePage.getArticlesCount(); Integer paperCount = conferencePage.getArticlesCount();
@ -191,12 +177,7 @@ public class IndexConferenceTest extends TestTemplate {
getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId));
Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount() Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount()
&& conferencePage.getArticles() && conferencePage.checkArticle(paperName));
.stream()
.anyMatch(webElement -> webElement
.findElements(By.tagName("input"))
.get(1).getAttribute("value")
.equals(paperName)));
} }
@Test @Test
@ -207,7 +188,7 @@ public class IndexConferenceTest extends TestTemplate {
ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey());
ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
conferencesPage.getConferenceFirst(); conferencesPage.getFirstConference();
String conferenceId = conferencePage.getId(); String conferenceId = conferencePage.getId();
Integer paperCount = conferencePage.getArticlesCount(); Integer paperCount = conferencePage.getArticlesCount();

View File

@ -56,8 +56,8 @@ public class ConferencePage extends PageObject {
driver.findElement(By.id("take-part")).click(); driver.findElement(By.id("take-part")).click();
} }
public String getTakePartButDisabledValue() { public Boolean isTakePartButDisabledValueTrue() {
return driver.findElement(By.id("take-part")).getAttribute("disabled"); return driver.findElement(By.id("take-part")).getAttribute("disabled").equals("true");
} }
public Integer getMemberCount() { public Integer getMemberCount() {
@ -94,4 +94,23 @@ public class ConferencePage extends PageObject {
public void clickUndockArticleBut() { public void clickUndockArticleBut() {
driver.findElement(By.name("removePaper")).click(); driver.findElement(By.name("removePaper")).click();
} }
public boolean checkDeadline(String description, String dateValue) {
return getDeadlineList()
.stream()
.anyMatch(webElement -> {
return webElement.findElement(By.className("deadline-text")).getAttribute("value").equals(description)
&& webElement.findElement(By.cssSelector("input[type=\"date\"]")).getAttribute("value").equals(dateValue);
});
}
public boolean checkArticle(String paperName) {
return getArticles()
.stream()
.anyMatch(webElement -> webElement
.findElements(By.tagName("input"))
.get(1).getAttribute("value")
.equals(paperName));
}
} }

View File

@ -16,7 +16,7 @@ public class ConferencesPage extends PageObject {
return driver.findElements(By.cssSelector("span.h6.float-left.m-2")); return driver.findElements(By.cssSelector("span.h6.float-left.m-2"));
} }
public void getConferenceFirst() { public void getFirstConference() {
driver.findElement(By.xpath("//*[@id=\"conferences\"]/div/div[2]/div[1]/div[1]/div/a")).click(); driver.findElement(By.xpath("//*[@id=\"conferences\"]/div/div[2]/div[1]/div[1]/div/a")).click();
} }
@ -37,4 +37,11 @@ public class ConferencesPage extends PageObject {
public void clickConfirm() { public void clickConfirm() {
driver.findElement(By.id("deleteConference")).click(); driver.findElement(By.id("deleteConference")).click();
} }
public boolean checkNameInList(String newConferenceName) {
return getConferencesList()
.stream()
.anyMatch(webElement -> webElement.getText().equals(newConferenceName));
}
} }