Merge branch '103-students-integ-tests' into 'dev'
Resolve "Реализовать интеграционные автотесты для проверки модулей" See merge request romanov73/ng-tracker!100
This commit is contained in:
commit
af09938e66
0
src/main/resources/drivers/chromedriver
Normal file → Executable file
0
src/main/resources/drivers/chromedriver
Normal file → Executable file
0
src/main/resources/drivers/geckodriver
Normal file → Executable file
0
src/main/resources/drivers/geckodriver
Normal file → Executable file
214
src/test/java/IndexTaskTest.java
Normal file
214
src/test/java/IndexTaskTest.java
Normal file
@ -0,0 +1,214 @@
|
|||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import core.PageObject;
|
||||||
|
import core.TestTemplate;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.FixMethodOrder;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.MethodSorters;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
import ru.ulstu.NgTrackerApplication;
|
||||||
|
import ru.ulstu.configuration.ApplicationProperties;
|
||||||
|
import students.TaskPage;
|
||||||
|
import students.TasksDashboardPage;
|
||||||
|
import students.TasksPage;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||||
|
public class IndexTaskTest extends TestTemplate {
|
||||||
|
private final Map<PageObject, List<String>> navigationHolder = ImmutableMap.of(
|
||||||
|
new TasksPage(), Arrays.asList("Список задач", "/students/tasks"),
|
||||||
|
new TasksDashboardPage(), Arrays.asList("Панель управления", "/students/dashboard"),
|
||||||
|
new TaskPage(), Arrays.asList("Создать задачу", "/students/task?id=0")
|
||||||
|
);
|
||||||
|
|
||||||
|
private final String TAG = "ATag";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationProperties applicationProperties;
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testACreateTask() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 2);
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
|
||||||
|
TaskPage taskPage = (TaskPage) getContext().initPage(page.getKey());
|
||||||
|
TasksPage tasksPage = (TasksPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey());
|
||||||
|
String taskName = "Task " + (new Date()).getTime();
|
||||||
|
|
||||||
|
taskPage.setName(taskName);
|
||||||
|
taskPage.addDeadlineDate("01.01.2020", 0);
|
||||||
|
taskPage.addDeadlineDescription("Description", 0);
|
||||||
|
taskPage.save();
|
||||||
|
|
||||||
|
Assert.assertTrue(tasksPage.findTask(taskName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBEditTaskName() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey());
|
||||||
|
TaskPage taskPage = (TaskPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 2).getKey());
|
||||||
|
String taskNewName = "Task " + (new Date()).getTime();
|
||||||
|
|
||||||
|
tasksPage.goToFirstTask();
|
||||||
|
taskPage.removeName();
|
||||||
|
taskPage.setName(taskNewName);
|
||||||
|
taskPage.save();
|
||||||
|
|
||||||
|
Assert.assertTrue(tasksPage.findTask(taskNewName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCDeleteTask() throws InterruptedException {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey());
|
||||||
|
|
||||||
|
Integer size = tasksPage.getTasks().size();
|
||||||
|
tasksPage.deleteFirstTask();
|
||||||
|
Thread.sleep(3000);
|
||||||
|
tasksPage.submit();
|
||||||
|
|
||||||
|
Assert.assertEquals(size - 1, tasksPage.getTasks().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDAddDeadline() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey());
|
||||||
|
TaskPage taskPage = (TaskPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 2).getKey());
|
||||||
|
|
||||||
|
tasksPage.goToFirstTask();
|
||||||
|
String taskId = taskPage.getId();
|
||||||
|
Integer deadnum = taskPage.getDeadNum();
|
||||||
|
|
||||||
|
String descr = "Description";
|
||||||
|
String date = "06.06.2019";
|
||||||
|
String dateValue = "2019-06-06";
|
||||||
|
|
||||||
|
taskPage.clickAddDeadline();
|
||||||
|
taskPage.addDeadlineDescription(descr, deadnum);
|
||||||
|
taskPage.addDeadlineDate(date, deadnum);
|
||||||
|
taskPage.save();
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + String.format("/students/task?id=%s", taskId));
|
||||||
|
|
||||||
|
Assert.assertTrue(taskPage.hasDeadline(descr, dateValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEEditDeadline() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey());
|
||||||
|
TaskPage taskPage = (TaskPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 2).getKey());
|
||||||
|
|
||||||
|
tasksPage.goToFirstTask();
|
||||||
|
String taskId = taskPage.getId();
|
||||||
|
|
||||||
|
String descr = "DescriptionTwo";
|
||||||
|
String date = "12.12.2019";
|
||||||
|
String dateValue = "2019-12-12";
|
||||||
|
|
||||||
|
taskPage.clearDeadlineDate(0);
|
||||||
|
taskPage.clearDeadlineDescription(0);
|
||||||
|
taskPage.addDeadlineDescription(descr, 0);
|
||||||
|
taskPage.addDeadlineDate(date, 0);
|
||||||
|
taskPage.save();
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + String.format("/students/task?id=%s", taskId));
|
||||||
|
|
||||||
|
Assert.assertTrue(taskPage.hasDeadline(descr, dateValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFDeleteDeadline() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey());
|
||||||
|
TaskPage taskPage = (TaskPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 2).getKey());
|
||||||
|
|
||||||
|
tasksPage.goToFirstTask();
|
||||||
|
String taskId = taskPage.getId();
|
||||||
|
Integer deadNum = taskPage.getDeadNum();
|
||||||
|
|
||||||
|
taskPage.deleteDeadline();
|
||||||
|
taskPage.save();
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + String.format("/students/task?id=%s", taskId));
|
||||||
|
|
||||||
|
Assert.assertEquals(deadNum - 1, (int) taskPage.getDeadNum());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGCreateTaskWithTag() throws InterruptedException {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 2);
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
|
||||||
|
TaskPage taskPage = (TaskPage) getContext().initPage(page.getKey());
|
||||||
|
TasksPage tasksPage = (TasksPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey());
|
||||||
|
String taskName = "Task " + (new Date()).getTime();
|
||||||
|
|
||||||
|
taskPage.setName(taskName);
|
||||||
|
taskPage.setTag(TAG);
|
||||||
|
Thread.sleep(1000);
|
||||||
|
taskPage.addDeadlineDate("01.01.2020", 0);
|
||||||
|
taskPage.addDeadlineDescription("Description", 0);
|
||||||
|
taskPage.save();
|
||||||
|
|
||||||
|
Assert.assertTrue(tasksPage.findTaskByTag(taskName, TAG));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHFindTagInFilter() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey());
|
||||||
|
|
||||||
|
|
||||||
|
Assert.assertTrue(tasksPage.findTag(TAG));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIFilterByTag() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey());
|
||||||
|
tasksPage.selectTag(TAG);
|
||||||
|
|
||||||
|
Assert.assertTrue(tasksPage.findTasksByTag(TAG));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testJFilterByStatus() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey());
|
||||||
|
|
||||||
|
tasksPage.selectStatus();
|
||||||
|
Assert.assertTrue(tasksPage.findAllStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
81
src/test/java/students/TaskPage.java
Normal file
81
src/test/java/students/TaskPage.java
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
package students;
|
||||||
|
|
||||||
|
import core.PageObject;
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.Keys;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TaskPage extends PageObject {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSubTitle() {
|
||||||
|
return driver.findElement(By.tagName("h3")).getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
driver.findElement(By.id("title")).sendKeys(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
driver.findElement(By.id("sendMessageButton")).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDeadlineDate(String deadDate, Integer deadNum) {
|
||||||
|
driver.findElement(By.id(String.format("deadlines%d.date", deadNum))).sendKeys(deadDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDeadlineDescription(String deadDescr, Integer deadNum) {
|
||||||
|
driver.findElement(By.id(String.format("deadlines%d.description", deadNum))).sendKeys(deadDescr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeName() {
|
||||||
|
driver.findElement(By.id("title")).clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return driver.findElement(By.id("id")).getAttribute("value");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getDeadNum() {
|
||||||
|
return driver.findElements(By.cssSelector("#task-form .form-group:nth-of-type(5) .row")).size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clickAddDeadline() {
|
||||||
|
driver.findElement(By.cssSelector("#addDeadline")).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WebElement> getDeadlines() {
|
||||||
|
return driver.findElements(By.cssSelector(".form-group:nth-of-type(5) .row"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteDeadline() {
|
||||||
|
driver.findElement(By.xpath("//*[@id=\"task-form\"]/div/div[1]/div[5]/div[1]/div[3]/a")).click();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearDeadlineDate(Integer deadNum) {
|
||||||
|
driver.findElement(By.id(String.format("deadlines%d.date", deadNum))).sendKeys(Keys.DELETE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearDeadlineDescription(Integer deadNum) {
|
||||||
|
driver.findElement(By.id(String.format("deadlines%d.description", deadNum))).clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasDeadline(String deadDescr, String deadValue) {
|
||||||
|
return getDeadlines()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(webElement -> {
|
||||||
|
return webElement.findElement(By.cssSelector("input[type=\"text\"]")).getAttribute("value").equals(deadDescr)
|
||||||
|
&& webElement.findElement(By.cssSelector("input[type=\"date\"]")).getAttribute("value").equals(deadValue);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTag(String tag) {
|
||||||
|
driver.findElement(By.className("input-tag-name")).sendKeys(tag);
|
||||||
|
driver.findElement(By.className("input-tag-name")).sendKeys(Keys.ENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
10
src/test/java/students/TasksDashboardPage.java
Normal file
10
src/test/java/students/TasksDashboardPage.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package students;
|
||||||
|
|
||||||
|
import core.PageObject;
|
||||||
|
|
||||||
|
public class TasksDashboardPage extends PageObject {
|
||||||
|
@Override
|
||||||
|
public String getSubTitle() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
75
src/test/java/students/TasksPage.java
Normal file
75
src/test/java/students/TasksPage.java
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
package students;
|
||||||
|
|
||||||
|
import core.PageObject;
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TasksPage extends PageObject {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSubTitle() {
|
||||||
|
return driver.findElement(By.tagName("h3")).getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WebElement> getTasks() {
|
||||||
|
return driver.findElements(By.cssSelector("span.h6"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WebElement> getTaskRows() {
|
||||||
|
return driver.findElements(By.className("task-row"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void goToFirstTask() {
|
||||||
|
driver.findElement(By.xpath("//*[@id=\"tasks\"]/div/div[2]/div[1]/div/div/a[1]")).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean findTask(String taskName) {
|
||||||
|
return getTasks().stream()
|
||||||
|
.anyMatch(webElement -> webElement.getText().equals(taskName));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteFirstTask() {
|
||||||
|
js.executeScript("$('a[data-confirm]').click();");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void submit() {
|
||||||
|
driver.findElement(By.xpath("//*[@id=\"dataConfirmOK\"]")).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean findTag(String tag) {
|
||||||
|
driver.findElements(By.className("bootstrap-select")).get(2).findElement(By.className("btn")).click();
|
||||||
|
driver.findElement(By.cssSelector(".bs-searchbox input")).sendKeys(tag);
|
||||||
|
return driver.findElement(By.xpath("//*[@id=\"tasks\"]/div/div[2]/div[2]/div[2]/div[2]/div/div[2]/ul")).findElement(By.className("text")).getText().equals(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean findTaskByTag(String name, String tag) {
|
||||||
|
return getTasks().stream()
|
||||||
|
.anyMatch(webElement -> webElement.getText().equals(name)
|
||||||
|
&& webElement.findElement(By.xpath("//*[@id=\"tasks\"]/div/div[2]/div[1]/div/div/a[1]/span[3]")).getText().equals(tag));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean findTasksByTag(String tag) {
|
||||||
|
return getTaskRows().stream()
|
||||||
|
.allMatch(webElement -> webElement.findElement(By.cssSelector("span.text-muted")).getText().equals(tag));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void selectTag(String tag) {
|
||||||
|
driver.findElements(By.className("bootstrap-select")).get(2).findElement(By.className("btn")).click();
|
||||||
|
driver.findElement(By.cssSelector(".bs-searchbox input")).sendKeys(tag);
|
||||||
|
driver.findElement(By.xpath("//*[@id=\"tasks\"]/div/div[2]/div[2]/div[2]/div[2]/div/div[2]/ul/li/a")).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void selectStatus() {
|
||||||
|
driver.findElements(By.className("bootstrap-select")).get(1).findElement(By.className("btn")).click();
|
||||||
|
driver.findElement(By.xpath("//*[@id=\"tasks\"]/div/div[2]/div[2]/div[2]/div[1]/div/div/ul/li[2]/a")).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean findAllStatus() {
|
||||||
|
return getTaskRows().stream()
|
||||||
|
.allMatch(webElement -> webElement.findElement(By.cssSelector("div i.text-primary")).isDisplayed());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user