#103 add tests for authors and description
This commit is contained in:
parent
acd58005de
commit
fddc15af5a
@ -10,6 +10,7 @@ import org.junit.FixMethodOrder;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.MethodSorters;
|
import org.junit.runners.MethodSorters;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
@ -24,7 +25,7 @@ import java.util.Map;
|
|||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||||
public class IndexGrantTest extends TestTemplate {
|
public class GrantTest extends TestTemplate {
|
||||||
private final Map<PageObject, List<String>> navigationHolder = ImmutableMap.of(
|
private final Map<PageObject, List<String>> navigationHolder = ImmutableMap.of(
|
||||||
new GrantsPage(), Arrays.asList("ГРАНТЫ", "/grants/grants"),
|
new GrantsPage(), Arrays.asList("ГРАНТЫ", "/grants/grants"),
|
||||||
new GrantPage(), Arrays.asList("РЕДАКТИРОВАНИЕ ГРАНТА", "/grants/grant?id=0"),
|
new GrantPage(), Arrays.asList("РЕДАКТИРОВАНИЕ ГРАНТА", "/grants/grant?id=0"),
|
||||||
@ -35,7 +36,7 @@ public class IndexGrantTest extends TestTemplate {
|
|||||||
private ApplicationProperties applicationProperties;
|
private ApplicationProperties applicationProperties;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createNewGrant() {
|
public void aCreateNewGrant() {
|
||||||
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 1);
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 1);
|
||||||
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
GrantPage grantPage = (GrantPage) getContext().initPage(page.getKey());
|
GrantPage grantPage = (GrantPage) getContext().initPage(page.getKey());
|
||||||
@ -53,7 +54,7 @@ public class IndexGrantTest extends TestTemplate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createBlankGrant() {
|
public void bCreateBlankGrant() {
|
||||||
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 1);
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 1);
|
||||||
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
GrantPage grantPage = (GrantPage) getContext().initPage(page.getKey());
|
GrantPage grantPage = (GrantPage) getContext().initPage(page.getKey());
|
||||||
@ -64,7 +65,7 @@ public class IndexGrantTest extends TestTemplate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateGrantTitle() {
|
public void cUpdateGrantTitle() {
|
||||||
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
||||||
@ -79,18 +80,7 @@ public class IndexGrantTest extends TestTemplate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void deleteGrant() throws InterruptedException {
|
public void dAttachPaper() {
|
||||||
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
|
||||||
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
|
||||||
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
|
||||||
|
|
||||||
Integer size = grantsPage.getGrantsList().size();
|
|
||||||
grantsPage.deleteFirst();
|
|
||||||
Assert.assertEquals(size - 1, grantsPage.getGrantsList().size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void attachPaper() {
|
|
||||||
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
||||||
@ -103,7 +93,7 @@ public class IndexGrantTest extends TestTemplate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void deletePaper() {
|
public void eDeletePaper() {
|
||||||
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
||||||
@ -119,7 +109,7 @@ public class IndexGrantTest extends TestTemplate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addDeadline() {
|
public void fAddDeadline() {
|
||||||
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
||||||
@ -130,8 +120,8 @@ public class IndexGrantTest extends TestTemplate {
|
|||||||
Integer deadlineCount = grantPage.getDeadlineCount();
|
Integer deadlineCount = grantPage.getDeadlineCount();
|
||||||
|
|
||||||
String description = "deadline test";
|
String description = "deadline test";
|
||||||
String date = "09.09.2019";
|
String date = "08.08.2019";
|
||||||
String dateValue = "2019-09-09";
|
String dateValue = "2019-08-08";
|
||||||
grantPage.addDeadline();
|
grantPage.addDeadline();
|
||||||
grantPage.setDeadline(date, deadlineCount, description);
|
grantPage.setDeadline(date, deadlineCount, description);
|
||||||
grantPage.saveGrant();
|
grantPage.saveGrant();
|
||||||
@ -142,7 +132,7 @@ public class IndexGrantTest extends TestTemplate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void deleteDeadline() {
|
public void gDeleteDeadline() {
|
||||||
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
||||||
@ -152,16 +142,6 @@ public class IndexGrantTest extends TestTemplate {
|
|||||||
String grantId = grantPage.getId();
|
String grantId = grantPage.getId();
|
||||||
Integer deadlineCount = grantPage.getDeadlineCount();
|
Integer deadlineCount = grantPage.getDeadlineCount();
|
||||||
|
|
||||||
String description = "deadline test";
|
|
||||||
String date = "09.09.2019";
|
|
||||||
String dateValue = "2019-09-09";
|
|
||||||
grantPage.addDeadline();
|
|
||||||
grantPage.setDeadline(date, deadlineCount, description);
|
|
||||||
grantPage.saveGrant();
|
|
||||||
|
|
||||||
getContext().goTo(applicationProperties.getBaseUrl() + String.format("/grants/grant?id=%s", grantId));
|
|
||||||
deadlineCount = grantPage.getDeadlineCount();
|
|
||||||
|
|
||||||
grantPage.deleteDeadline();
|
grantPage.deleteDeadline();
|
||||||
grantPage.saveGrant();
|
grantPage.saveGrant();
|
||||||
|
|
||||||
@ -169,4 +149,77 @@ public class IndexGrantTest extends TestTemplate {
|
|||||||
Integer newDeadlineCount = grantPage.getDeadlineCount();
|
Integer newDeadlineCount = grantPage.getDeadlineCount();
|
||||||
Assert.assertEquals(deadlineCount - 1, (int) newDeadlineCount);
|
Assert.assertEquals(deadlineCount - 1, (int) newDeadlineCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void hAddAuthor() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
||||||
|
GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||||
|
|
||||||
|
WebElement grant = grantsPage.getFirstGrantWithoutClick();
|
||||||
|
String grantTitle = grantsPage.getGrantTitle(grant);
|
||||||
|
Integer authorsCount = grantsPage.getAuthorsCount(grant);
|
||||||
|
|
||||||
|
grantsPage.getFirstGrant();
|
||||||
|
grantPage.addAuthor();
|
||||||
|
grantPage.saveGrant();
|
||||||
|
|
||||||
|
grant = grantsPage.getGrantByTitle(grantTitle);
|
||||||
|
Integer newAuthorsCount = grantsPage.getAuthorsCount(grant);
|
||||||
|
|
||||||
|
Assert.assertEquals(authorsCount + 1, (int) newAuthorsCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void iDeleteAuthor() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
||||||
|
GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||||
|
|
||||||
|
WebElement grant = grantsPage.getFirstGrantWithoutClick();
|
||||||
|
String grantTitle = grantsPage.getGrantTitle(grant);
|
||||||
|
Integer authorsCount = grantsPage.getAuthorsCount(grant);
|
||||||
|
|
||||||
|
grantsPage.getFirstGrant();
|
||||||
|
grantPage.deleteAuthor();
|
||||||
|
grantPage.saveGrant();
|
||||||
|
|
||||||
|
grant = grantsPage.getGrantByTitle(grantTitle);
|
||||||
|
Integer newAuthorsCount = grantsPage.getAuthorsCount(grant);
|
||||||
|
|
||||||
|
authorsCount = (authorsCount == 0) ? 0 : authorsCount - 1;
|
||||||
|
|
||||||
|
Assert.assertEquals((int) authorsCount, (int) newAuthorsCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void jUpdateGrantDescription() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
||||||
|
GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||||
|
|
||||||
|
String description = "newDescriptionForGrant";
|
||||||
|
grantsPage.getFirstGrant();
|
||||||
|
String grantId = grantPage.getId();
|
||||||
|
grantPage.setDescription(description);
|
||||||
|
grantPage.saveGrant();
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + String.format("/grants/grant?id=%s", grantId));
|
||||||
|
|
||||||
|
Assert.assertTrue(description.equals(grantPage.getDescription()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void kDeleteGrant() throws InterruptedException {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
||||||
|
|
||||||
|
Integer size = grantsPage.getGrantsList().size();
|
||||||
|
grantsPage.deleteFirst();
|
||||||
|
Assert.assertEquals(size - 1, grantsPage.getGrantsList().size());
|
||||||
|
}
|
||||||
}
|
}
|
@ -42,10 +42,7 @@ public class GrantPage extends PageObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkBlankFields() {
|
public boolean checkBlankFields() {
|
||||||
if (driver.findElements(By.className("alert-danger")).size() > 0) {
|
return driver.findElements(By.className("alert-danger")).size() > 0;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<WebElement> getAttachedPapers() {
|
public List<WebElement> getAttachedPapers() {
|
||||||
@ -109,4 +106,44 @@ public class GrantPage extends PageObject {
|
|||||||
public void deleteDeadline() {
|
public void deleteDeadline() {
|
||||||
driver.findElements(By.className("btn-delete-deadline")).get(0).click();
|
driver.findElements(By.className("btn-delete-deadline")).get(0).click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<WebElement> addAuthor() {
|
||||||
|
WebElement selectAuthors = driver.findElement(By.id("authors"));
|
||||||
|
Select select = new Select(selectAuthors);
|
||||||
|
List<WebElement> selectedOptions = select.getAllSelectedOptions();
|
||||||
|
List<WebElement> allOptions = select.getOptions();
|
||||||
|
int i = 0;
|
||||||
|
while (i < selectedOptions.size()) {
|
||||||
|
if (!allOptions.get(i).equals(selectedOptions.get(i))) {
|
||||||
|
select.selectByVisibleText(allOptions.get(i).getText());
|
||||||
|
selectedOptions.add(allOptions.get(i));
|
||||||
|
return selectedOptions;
|
||||||
|
} else {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (selectedOptions.size() != allOptions.size()) {
|
||||||
|
select.selectByVisibleText(allOptions.get(i).getText());
|
||||||
|
selectedOptions.add(allOptions.get(i));
|
||||||
|
}
|
||||||
|
return selectedOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteAuthor() {
|
||||||
|
WebElement selectAuthors = driver.findElement(By.id("authors"));
|
||||||
|
Select select = new Select(selectAuthors);
|
||||||
|
List<WebElement> selectedOptions = select.getAllSelectedOptions();
|
||||||
|
if (selectedOptions.size() != 0) {
|
||||||
|
select.deselectByVisibleText(selectedOptions.get(0).getText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
driver.findElement(By.id("comment")).clear();
|
||||||
|
driver.findElement(By.id("comment")).sendKeys(description);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return driver.findElement(By.id("comment")).getText();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,13 @@ public class GrantsPage extends PageObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<WebElement> getGrantsList() {
|
public List<WebElement> getGrantsList() {
|
||||||
return driver.findElements(By.cssSelector("span.h6"));
|
return driver.findElements(By.className("grant-row"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean findGrantByTitle(String grantTitle) {
|
public boolean findGrantByTitle(String grantTitle) {
|
||||||
return getGrantsList()
|
return getGrantsList()
|
||||||
.stream()
|
.stream()
|
||||||
|
.map(el -> el.findElement(By.cssSelector("span.h6")))
|
||||||
.anyMatch(webElement -> webElement.getText().equals(grantTitle));
|
.anyMatch(webElement -> webElement.getText().equals(grantTitle));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,4 +36,31 @@ public class GrantsPage extends PageObject {
|
|||||||
public void getFirstGrant() {
|
public void getFirstGrant() {
|
||||||
driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div/a[1]")).click();
|
driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div/a[1]")).click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WebElement getFirstGrantWithoutClick() {
|
||||||
|
return driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGrantTitle(WebElement webElement) {
|
||||||
|
return webElement.findElement(By.cssSelector("span.h6")).getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebElement getGrantByTitle(String title) {
|
||||||
|
List<WebElement> list = getGrantsList();
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
if (getGrantTitle(list.get(i)).equals(title)) {
|
||||||
|
return list.get(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getAuthorsCount(WebElement webElement) {
|
||||||
|
String authors = webElement.findElement(By.className("text-muted")).getText();
|
||||||
|
if (!authors.equals("")) {
|
||||||
|
String[] mas = authors.split(",");
|
||||||
|
return mas.length;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user