1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
package com.mavlushechka.a1qa.project;
import aquality.selenium.browser.AqualityServices;
import com.mavlushechka.a1qa.framework.BaseTest;
import com.mavlushechka.a1qa.framework.utils.JsonParser;
import com.mavlushechka.a1qa.framework.utils.LoggerUtils;
import com.mavlushechka.a1qa.project.constants.Project;
import com.mavlushechka.a1qa.project.models.User;
import com.mavlushechka.a1qa.project.pages.ProjectsPage;
import com.mavlushechka.a1qa.project.pages.TestsPage;
import com.mavlushechka.a1qa.project.utils.SiteApiUtils;
import org.openqa.selenium.Cookie;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class TestCase1 extends BaseTest {
@Test
public void test1() throws IOException {
LoggerUtils.step("Query the api to retrieve the token according to the variant number.");
int variant = Integer.parseInt(JsonParser.parseData("testData", "variant"));
String token = SiteApiUtils.generateToken(variant);
Assert.assertNotEquals(token, null, "The token is null.");
ProjectsPage projectsPage = new ProjectsPage();
LoggerUtils.step("Go to the website. Complete the necessary authorisation."
+ "Transfer the token (parameter token) generated in step 1 using a cookie. Refresh the page.");
projectsPage.performAuthorization(JsonParser.convertToObject(JsonParser.parseObject("testData", "user"), User.class));
Assert.assertTrue(projectsPage.state().waitForDisplayed(), "The %s page is not opened.".formatted(projectsPage.getName()));
AqualityServices.getBrowser().getDriver().manage().addCookie(new Cookie("token", token));
AqualityServices.getBrowser().refresh();
Assert.assertEquals(projectsPage.getVersion(), variant, "The variant is not correct.");
LoggerUtils.step("Go to the Nexage project page. Query the api to get a list of tests in JSON/XML format.");
projectsPage.openProject(Project.NEXAGE);
TestsPage testsPage = new TestsPage();
Assert.assertTrue(testsPage.state().waitForDisplayed(), "The %s page is not opened.".formatted(testsPage.getName()));
List<com.mavlushechka.a1qa.project.models.Test> allRunningTestsOnSite = testsPage.getAllRunningTests();
List<com.mavlushechka.a1qa.project.models.Test> descendingSortedAllRunningTestsOnSite = new ArrayList<>(allRunningTestsOnSite);
descendingSortedAllRunningTestsOnSite.sort(Collections.reverseOrder());
Assert.assertEquals(allRunningTestsOnSite, descendingSortedAllRunningTestsOnSite, "Tests are not sorted in descending order.");
Object[] objects = JsonParser.convertArray(SiteApiUtils.getTestsJson(Project.NEXAGE.id), com.mavlushechka.a1qa.project.models.Test.class);
ArrayList<com.mavlushechka.a1qa.project.models.Test> allRunningTestsReceivedByApi = new ArrayList<>();
for (Object object : objects) {
allRunningTestsReceivedByApi.add((com.mavlushechka.a1qa.project.models.Test) object);
}
Assert.assertTrue(allRunningTestsReceivedByApi.containsAll(allRunningTestsOnSite),
"All running tests received by API not contains all running tests on site.");
}
}
|