1 |
1 |
package cz.zcu.kiv.imiger.tests.frontend;
|
2 |
2 |
|
3 |
|
import org.junit.jupiter.api.AfterAll;
|
4 |
|
import org.junit.jupiter.api.Assertions;
|
5 |
|
import org.junit.jupiter.api.BeforeAll;
|
6 |
|
import org.junit.jupiter.api.Test;
|
|
3 |
import org.junit.jupiter.api.*;
|
7 |
4 |
import org.openqa.selenium.By;
|
8 |
|
import org.openqa.selenium.NoSuchElementException;
|
9 |
5 |
import org.openqa.selenium.WebDriver;
|
10 |
6 |
import org.openqa.selenium.WebElement;
|
11 |
7 |
|
... | ... | |
15 |
11 |
public class AutomaticGroupingTest {
|
16 |
12 |
static WebDriver browser;
|
17 |
13 |
|
18 |
|
@BeforeAll
|
19 |
|
public static void initTest() {
|
|
14 |
@BeforeEach
|
|
15 |
public void initTest() {
|
20 |
16 |
SeleniumUtil.prepareConfigFile("automaticGroupingConfigTest.json");
|
21 |
17 |
browser = SeleniumUtil.init();
|
22 |
18 |
SeleniumUtil.loadGraphData("automaticGroupingTest.json");
|
23 |
19 |
}
|
24 |
20 |
|
25 |
21 |
@Test
|
26 |
|
public void groups1(){
|
|
22 |
public void groupIncluded(){
|
27 |
23 |
String groupName = "FirstGroupArchetype";
|
28 |
|
List<String> verticesIds = new ArrayList<>();
|
29 |
|
verticesIds.add("li1");
|
30 |
|
verticesIds.add("li3");
|
|
24 |
checkGroupExist(browser, groupName);
|
|
25 |
}
|
|
26 |
|
|
27 |
@Test
|
|
28 |
public void groupExcluded(){
|
|
29 |
String groupName = "FirstGroupArchetype";
|
|
30 |
List<String> verticesNames = new ArrayList<>();
|
|
31 |
verticesNames.add("First vertex from first group");
|
|
32 |
verticesNames.add("Second vertex from first group");
|
|
33 |
|
|
34 |
excludeFirstGroup(browser);
|
|
35 |
checkExcludedGroup(browser, groupName, verticesNames);
|
|
36 |
}
|
|
37 |
|
|
38 |
private void checkGroupExist(WebDriver browser, String groupName){
|
|
39 |
List<WebElement> groups = browser.findElement(By.cssSelector("[data-id='groups']"))
|
|
40 |
.findElements(By.className("node"));
|
|
41 |
|
|
42 |
Assertions.assertEquals(1, groups.size());
|
|
43 |
|
|
44 |
String actualGroupName = groups.get(0).findElement(By.tagName("foreignObject"))
|
|
45 |
.findElement(By.className("group-name")).getText();
|
31 |
46 |
|
32 |
|
checkGroupExisting(browser, groupName, verticesIds);
|
33 |
|
System.out.println("Group: " + groupName + " was not found.");
|
|
47 |
Assertions.assertEquals(groupName, actualGroupName);
|
34 |
48 |
}
|
35 |
49 |
|
36 |
|
private void checkGroupExisting(WebDriver browser, String groupName, List<String> verticesIds){
|
37 |
|
WebElement group = browser.findElement(By.className("component group_vertices"));
|
38 |
|
System.out.println("Trying to locate vertexes in group");
|
39 |
|
for(String id : verticesIds){
|
40 |
|
group.findElement(By.id(id));
|
|
50 |
private void checkExcludedGroup(WebDriver browser, String groupName, List<String> verticesTexts){
|
|
51 |
List<WebElement> nodes = browser.findElement(By.id("excludedNodeListComponent"))
|
|
52 |
.findElement(By.className("node-list"))
|
|
53 |
.findElements(By.tagName("li"));
|
|
54 |
|
|
55 |
Assertions.assertEquals(3, nodes.size());
|
|
56 |
WebElement group = nodes.get(0);
|
|
57 |
|
|
58 |
String actualGroupName = group.findElement(By.className("group-name")).getText();
|
|
59 |
Assertions.assertEquals(groupName, actualGroupName);
|
|
60 |
|
|
61 |
for(int i = 1; i < nodes.size(); i ++){
|
|
62 |
Assertions.assertTrue(verticesTexts.contains(nodes.get(i).getText()));
|
41 |
63 |
}
|
|
64 |
}
|
|
65 |
|
|
66 |
private void excludeFirstGroup(WebDriver browser){
|
|
67 |
List<WebElement> navList = browser.findElement(By.tagName("nav")).findElements(By.tagName("ul"));
|
42 |
68 |
|
43 |
|
System.out.println("Vertexes found.");
|
|
69 |
for( WebElement item : navList){
|
|
70 |
WebElement form = item.findElement(By.tagName("form"));
|
|
71 |
if (form != null){
|
|
72 |
String formName = form.getAttribute("name");
|
|
73 |
if (formName.equals("actionForm")) {
|
|
74 |
item.findElements(By.tagName("label")).get(1).click();
|
|
75 |
break;
|
|
76 |
}
|
|
77 |
}
|
|
78 |
}
|
|
79 |
|
|
80 |
List<WebElement> groups = browser.findElement(By.cssSelector("[data-id='groups']"))
|
|
81 |
.findElements(By.className("node"));
|
|
82 |
|
|
83 |
groups.get(0).findElement(By.tagName("rect")).click();
|
|
84 |
try {
|
|
85 |
Thread.sleep(1000);
|
|
86 |
} catch (InterruptedException e) {
|
|
87 |
e.printStackTrace();
|
|
88 |
}
|
44 |
89 |
}
|
45 |
90 |
|
46 |
|
@AfterAll
|
47 |
|
public static void finishTest() {
|
|
91 |
@AfterEach
|
|
92 |
public void finishTest() {
|
48 |
93 |
SeleniumUtil.clear();
|
49 |
94 |
}
|
50 |
95 |
}
|
Repaired Seleninum tests - AutomaticGroupingTest