diff options
Diffstat (limited to 'src')
15 files changed, 642 insertions, 0 deletions
diff --git a/src/main/java/com/mavlushechka/a1qa/framework/utils/Collections.java b/src/main/java/com/mavlushechka/a1qa/framework/utils/Collections.java new file mode 100644 index 0000000..7a1cd1a --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/framework/utils/Collections.java @@ -0,0 +1,20 @@ +package com.mavlushechka.a1qa.framework.utils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class Collections { + + private Collections() { + } + + public static boolean isSortedDescending(List<?> list) { + List<?> descendingSortedList = new ArrayList<>(list); + + descendingSortedList.sort(java.util.Collections.reverseOrder()); + + return Objects.equals(list, descendingSortedList); + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/framework/utils/IntegerUtils.java b/src/main/java/com/mavlushechka/a1qa/framework/utils/IntegerUtils.java new file mode 100644 index 0000000..5b6b7da --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/framework/utils/IntegerUtils.java @@ -0,0 +1,25 @@ +package com.mavlushechka.a1qa.framework.utils; + +import java.util.OptionalInt; +import java.util.Random; + +public class IntegerUtils { + + private IntegerUtils() { + } + + public static int getRandomNumber(int min, int max) { + OptionalInt randomNumber = new Random().ints(min, max).findFirst(); + + if (randomNumber.isPresent()) { + return randomNumber.getAsInt(); + } + LoggerUtils.error("Incorrect min and max arguments."); + throw new IllegalArgumentException("Incorrect min and max arguments."); + } + + public static int parseInt(String text) { + return Integer.parseInt(text.replaceAll("[^0-9.]", "")); + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/framework/utils/StringUtils.java b/src/main/java/com/mavlushechka/a1qa/framework/utils/StringUtils.java new file mode 100644 index 0000000..29323d0 --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/framework/utils/StringUtils.java @@ -0,0 +1,47 @@ +package com.mavlushechka.a1qa.framework.utils; + +import java.util.Random; + +public class StringUtils { + + private StringUtils() { + } + + public static String convertToConstantCase(String text) { + StringBuilder stringBuilder = new StringBuilder(); + String[] words = text.split(" "); + + for (int i = 0; i < words.length; i++) { + stringBuilder.append(words[i].toUpperCase()); + if (i != words.length - 1) { + stringBuilder.append("_"); + } + } + + return stringBuilder.toString(); + } + + public static String capitalizeFirstLetter(String text) { + return text.substring(0, 1).toUpperCase() + text.substring(1); + } + + public static int removeNonDigits(String text) { + return Integer.parseInt(text.replaceAll("[^0-9]+", "")); + } + + public static String generateRandomText(int lettersLowerBound, int lettersUpperBound, int length) { + return new Random().ints(lettersLowerBound, lettersUpperBound + 1) + .limit(length) + .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append) + .toString(); + } + + public static String replaceByStars(String text) { + return "*".repeat(text.length()); + } + + public static String removeHttpProtocol(String url) { + return url.split("http://", 2)[1]; + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/framework/utils/UrlConnectionManager.java b/src/main/java/com/mavlushechka/a1qa/framework/utils/UrlConnectionManager.java new file mode 100644 index 0000000..fd7508b --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/framework/utils/UrlConnectionManager.java @@ -0,0 +1,65 @@ +package com.mavlushechka.a1qa.framework.utils; + +import com.mavlushechka.a1qa.framework.constants.RequestMethod; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; + +public class UrlConnectionManager { + + public static String get(String spec) throws IOException { + StringBuilder stringBuilder = new StringBuilder(); + + try (BufferedReader bufferedReader = new BufferedReader( + new InputStreamReader(HttpUrlConnectionFactory.createHttpUrlConnection(spec, RequestMethod.GET, false).getInputStream())) + ) { + String inputLine; + + while ((inputLine = bufferedReader.readLine()) != null) { + stringBuilder.append(inputLine); + } + } + return stringBuilder.toString(); + } + + public static String post(String spec) throws IOException { + StringBuilder stringBuilder = new StringBuilder(); + + try (BufferedReader bufferedReader = new BufferedReader( + new InputStreamReader(HttpUrlConnectionFactory.createHttpUrlConnection(spec, RequestMethod.POST, false).getInputStream())) + ) { + String inputLine; + + while ((inputLine = bufferedReader.readLine()) != null) { + stringBuilder.append(inputLine); + } + } + return stringBuilder.toString(); + } + + public static String post(String spec, String content) throws IOException { + HttpURLConnection httpUrlConnection = HttpUrlConnectionFactory.createHttpUrlConnection(spec, RequestMethod.POST, true); + StringBuilder stringBuilder = new StringBuilder(); + + try (DataOutputStream dataOutputStream = new DataOutputStream(httpUrlConnection.getOutputStream())) { + dataOutputStream.writeBytes(content); + dataOutputStream.flush(); + } + try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpUrlConnection.getInputStream()))) { + String inputLine; + + while ((inputLine = bufferedReader.readLine()) != null) { + stringBuilder.append(inputLine); + } + } + return stringBuilder.toString(); + } + + public static int getResponseCode(String spec, RequestMethod requestMethod) throws IOException { + return HttpUrlConnectionFactory.createHttpUrlConnection(spec, requestMethod, false).getResponseCode(); + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/constants/Result.java b/src/main/java/com/mavlushechka/a1qa/project/constants/Result.java new file mode 100644 index 0000000..3fea54f --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/constants/Result.java @@ -0,0 +1,7 @@ +package com.mavlushechka.a1qa.project.constants; + +public enum Result { + + FAILED, SKIPPED, IN_PROGRESS, PASSED + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/constants/SiteApiMethod.java b/src/main/java/com/mavlushechka/a1qa/project/constants/SiteApiMethod.java new file mode 100644 index 0000000..f90c85e --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/constants/SiteApiMethod.java @@ -0,0 +1,16 @@ +package com.mavlushechka.a1qa.project.constants; + +public enum SiteApiMethod { + + TOKEN_GET("/token/get"), TEST_GET_JSON("/test/get/json"), TEST_PUT("/test/put"), TEST_PUT_LOG("/test/put/log"), + TEST_PUT_ATTACHMENT("/test/put/attachment"); + + + public final String url; + + + SiteApiMethod(String url) { + this.url = url; + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/models/Test.java b/src/main/java/com/mavlushechka/a1qa/project/models/Test.java new file mode 100644 index 0000000..8011157 --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/models/Test.java @@ -0,0 +1,40 @@ +package com.mavlushechka.a1qa.project.models; + +import com.mavlushechka.a1qa.project.constants.Result; +import org.checkerframework.checker.nullness.qual.NonNull; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Objects; + +public record Test(String name, String method, Result status, String startTime, String endTime, String duration) + implements Comparable<Test> { + + public Test { + if (status == Result.IN_PROGRESS) { + status = null; + } + if (Objects.equals(startTime, "")) { + startTime = null; + } + if (Objects.equals(endTime, "")) { + endTime = null; + } + } + + @Override + public int compareTo(@NonNull Test test) { + if (startTime == null && test.startTime == null) { + return 0; + } + if (startTime == null) { + return -1; + } + if (test.startTime == null) { + return 1; + } + return LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S")) + .compareTo(LocalDateTime.parse(test.startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S"))); + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/models/User.java b/src/main/java/com/mavlushechka/a1qa/project/models/User.java new file mode 100644 index 0000000..b3f3ea2 --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/models/User.java @@ -0,0 +1,4 @@ +package com.mavlushechka.a1qa.project.models; + +public record User(String login, String password) { +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/pages/AddProjectPage.java b/src/main/java/com/mavlushechka/a1qa/project/pages/AddProjectPage.java new file mode 100644 index 0000000..b817d46 --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/pages/AddProjectPage.java @@ -0,0 +1,35 @@ +package com.mavlushechka.a1qa.project.pages; + +import aquality.selenium.browser.AqualityServices; +import aquality.selenium.elements.interfaces.IButton; +import aquality.selenium.elements.interfaces.ILabel; +import aquality.selenium.elements.interfaces.ITextBox; +import aquality.selenium.forms.Form; +import org.openqa.selenium.By; + +public class AddProjectPage extends Form { + + + private final ITextBox projectNameBox = AqualityServices.getElementFactory().getTextBox(By.id("projectName"), "Project name"); + private final IButton saveProjectButton = AqualityServices.getElementFactory().getButton( + By.xpath("//*[@id='addProjectForm']//button[contains(@class, 'btn-primary')]"), "Save project" + ); + private final ILabel projectSavedLabel = AqualityServices.getElementFactory().getLabel( + By.xpath("//*[@id='addProjectForm']//*[contains(@class, 'alert-success')]"), "Project saved" + ); + + + public AddProjectPage() { + super(By.id("addProjectForm"), "Add project"); + } + + public void saveProject(String name) { + projectNameBox.clearAndType(name); + saveProjectButton.click(); + } + + public boolean isProjectSaved(String projectName) { + return projectSavedLabel.state().waitForDisplayed() && projectSavedLabel.getText().contains(projectName); + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/pages/ProjectsPage.java b/src/main/java/com/mavlushechka/a1qa/project/pages/ProjectsPage.java new file mode 100644 index 0000000..bf670fc --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/pages/ProjectsPage.java @@ -0,0 +1,65 @@ +package com.mavlushechka.a1qa.project.pages; + +import aquality.selenium.browser.AqualityServices; +import aquality.selenium.elements.ElementType; +import aquality.selenium.elements.interfaces.IButton; +import aquality.selenium.forms.Form; +import com.mavlushechka.a1qa.framework.utils.IntegerUtils; +import com.mavlushechka.a1qa.framework.utils.JsonParser; +import com.mavlushechka.a1qa.framework.utils.StringUtils; +import com.mavlushechka.a1qa.project.models.User; +import org.openqa.selenium.By; + +import java.util.ArrayList; +import java.util.List; + +public class ProjectsPage extends Form { + + + private final IButton addButton = AqualityServices.getElementFactory().getButton(By.xpath("//*[contains(@class, 'panel-heading')]//a[@href='addProject']"), "Add project"); + + private final String url = JsonParser.parseData("config", "browser.url") + "/web/projects"; + + + public ProjectsPage() { + super(By.xpath("//*[contains(@class, 'panel')]"), "Projects"); + } + + public void performAuthorization(User user) { + AqualityServices.getBrowser().goTo("%s:%s@%s".formatted(user.login(), user.password(), StringUtils.removeHttpProtocol(url))); + AqualityServices.getBrowser().goTo(url); + } + + public int getVersion() { + return IntegerUtils.parseInt( + AqualityServices.getElementFactory().get( + ElementType.LABEL, + By.xpath("//*[contains(@class, 'footer-text')]//span"), + "Version" + ).getText() + ); + } + + public List<String> getProjects() { + List<String> projects = new ArrayList<>(); + + AqualityServices.getElementFactory().findElements( + By.xpath("//*[contains(@class, 'list-group')]//a[contains(@class, 'list-group-item')]"), ElementType.LABEL + ).forEach(element -> projects.add(element.getText())); + + return projects; + } + + public void openProject(String projectName) { + AqualityServices.getElementFactory().get( + ElementType.BUTTON, + By.xpath("//*[contains(@class, 'panel')]//a[contains(@class, 'list-group-item') and text()='%s']".formatted(projectName)), + "Project" + ).clickAndWait(); + } + + public void clickOnAddButton() { + addButton.click(); + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/pages/TestsPage.java b/src/main/java/com/mavlushechka/a1qa/project/pages/TestsPage.java new file mode 100644 index 0000000..6d09203 --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/pages/TestsPage.java @@ -0,0 +1,51 @@ +package com.mavlushechka.a1qa.project.pages; + +import aquality.selenium.browser.AqualityServices; +import aquality.selenium.elements.ElementType; +import aquality.selenium.elements.interfaces.IElement; +import aquality.selenium.forms.Form; +import com.mavlushechka.a1qa.framework.utils.StringUtils; +import com.mavlushechka.a1qa.project.constants.Result; +import com.mavlushechka.a1qa.project.models.Test; +import org.openqa.selenium.By; + +import java.util.ArrayList; +import java.util.List; + +public class TestsPage extends Form { + + + public TestsPage() { + super(By.id("pie"), "Tests"); + } + + public List<Test> getAllRunningTests() { + AqualityServices.getConditionalWait().waitFor( + () -> AqualityServices.getElementFactory().findElements( + By.xpath("//*[contains(@class, 'panel')]//table[contains(@class, 'table')]//tbody//td"), ElementType.LABEL + ).size() > 5 + ); + List<IElement> testsData = AqualityServices.getElementFactory().findElements( + By.xpath("//*[contains(@class, 'panel')]//table[contains(@class, 'table')]//tbody//td"), + ElementType.LABEL + ); + List<Test> runningTests = new ArrayList<>(); + + for (int i = 0; i < testsData.size(); i += 7) { + runningTests.add( + new Test( + testsData.get(i).getText(), + testsData.get(i + 1).getText(), + Result.valueOf(StringUtils.convertToConstantCase(testsData.get(i + 2).getText())), + testsData.get(i + 3).getText(), + testsData.get(i + 4).getText(), + testsData.get(i + 5).getText() + ) + ); + } + + return runningTests; + } + + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/utils/SiteApiUtils.java b/src/main/java/com/mavlushechka/a1qa/project/utils/SiteApiUtils.java new file mode 100644 index 0000000..a739e00 --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/utils/SiteApiUtils.java @@ -0,0 +1,47 @@ +package com.mavlushechka.a1qa.project.utils; + +import com.mavlushechka.a1qa.framework.utils.JsonParser; +import com.mavlushechka.a1qa.framework.utils.UrlConnectionManager; +import com.mavlushechka.a1qa.project.constants.SiteApiMethod; + +import java.io.IOException; +import java.util.Base64; + +public class SiteApiUtils { + + + private static final String url = "%s/api".formatted(JsonParser.parseData("config", "browser.url")); + + + private SiteApiUtils() { + } + + public static String generateToken(int variant) throws IOException { + return UrlConnectionManager.post("%s%s?variant=%d".formatted(url, SiteApiMethod.TOKEN_GET.url, variant)); + } + + public static String getTestsJson(int projectId) throws IOException { + return UrlConnectionManager.post("%s%s?projectId=%d".formatted(url, SiteApiMethod.TEST_GET_JSON.url, projectId)); + } + + public static int putTest(String sid, String projectName, String testName, String methodName, String env) throws IOException { + return Integer.parseInt( + UrlConnectionManager.post( + "%s%s?SID=%s&projectName=%s&testName=%s&methodName=%s&env=%s" + .formatted(url, SiteApiMethod.TEST_PUT.url, sid, projectName, testName, methodName, env) + ) + ); + } + + public static void putLogToTest(int testId, String content) throws IOException { + UrlConnectionManager.post("%s%s?testId=%d&content=%s".formatted(url, SiteApiMethod.TEST_PUT_LOG.url, testId, content)); + } + + public static void putAttachmentToTest(int testId, byte[] content, String contentType) throws IOException { + UrlConnectionManager.post( + "%s%s?testId=%d&content=%s&contentType=%s" + .formatted(url, SiteApiMethod.TEST_PUT_ATTACHMENT.url, testId, Base64.getEncoder().encodeToString(content), contentType) + ); + } + +} diff --git a/src/main/resources/settings.json b/src/main/resources/settings.json new file mode 100644 index 0000000..96027f4 --- /dev/null +++ b/src/main/resources/settings.json @@ -0,0 +1,118 @@ +{ + "browserName" : "firefox", + "isRemote": false, + "remoteConnectionUrl": "http://localhost:4444/wd/hub", + "isElementHighlightEnabled" : true, + + "driverSettings": { + "chrome": { + "webDriverVersion": "latest", + "capabilities": { + }, + "options": { + "intl.accept_languages": "en", + "safebrowsing.enabled": "true", + "profile.default_content_settings.popups": "0", + "disable-popup-blocking": "true", + "download.prompt_for_download": "false", + "download.default_directory": "//home//selenium//downloads" + }, + "pageLoadStrategy": "Normal", + "startArguments": [] + }, + "edge": { + "webDriverVersion": "latest", + "capabilities": { + }, + "options": { + "intl.accept_languages": "en", + "safebrowsing.enabled": "true", + "profile.default_content_settings.popups": "0", + "disable-popup-blocking": "true", + "download.prompt_for_download": "false", + "download.default_directory": "//home//selenium//downloads" + }, + "startArguments": [] + }, + "firefox": { + "webDriverVersion": "latest", + "capabilities": { + }, + "options": { + "intl.accept_languages": "en", + "browser.download.dir": "//home//selenium//downloads", + "browser.download.folderList": 2, + "browser.helperApps.neverAsk.saveToDisk": "application/octet-stream, application/x-debian-package, application/x-www-form-urlencod, application/json, application/x-compressed, application/x-zip-compressed, application/zip, multipart/x-zip, text/plain, text/csv", + "browser.helperApps.alwaysAsk.force": false, + "browser.download.manager.alertOnEXEOpen": false, + "browser.download.manager.focusWhenStarting": false, + "browser.download.useDownloadDir": true, + "browser.download.manager.showWhenStarting": false, + "browser.download.manager.closeWhenDone": true, + "browser.download.manager.showAlertOnComplete": false, + "browser.download.manager.useWindow": false, + "browser.download.panel.shown": false + }, + "startArguments": ["--kiosk"] + }, + "iexplorer": { + "webDriverVersion": "latest", + "systemArchitecture": "X32", + "capabilities": { + "ignoreProtectedModeSettings": true + } + }, + "opera": { + "webDriverVersion": "latest", + "binaryLocation": "%USERPROFILE%\\AppData\\Local\\Programs\\Opera\\launcher.exe", + "capabilities": { + }, + "options": { + "intl.accept_languages": "en", + "safebrowsing.enabled": "true", + "profile.default_content_settings.popups": "0", + "disable-popup-blocking": "true", + "download.prompt_for_download": "false", + "download.default_directory": "./downloads" + }, + "startArguments": ["--remote-debugging-port=9222", "--no-sandbox", "--disable-dev-shm-usage"] + }, + "safari": { + "downloadDir": "/Users/username/Downloads" + }, + "yandex": { + "webDriverVersion": "102.0.5005.61", + "binaryLocation": "%USERPROFILE%\\AppData\\Local\\Yandex\\YandexBrowser\\Application\\browser.exe", + "capabilities": { + }, + "options": { + "intl.accept_languages": "en", + "safebrowsing.enabled": "true", + "profile.default_content_settings.popups": "0", + "disable-popup-blocking": "true", + "download.prompt_for_download": "false", + "download.default_directory": "./downloads" + }, + "startArguments": [] + } + }, + "timeouts": { + "timeoutImplicit" : 0, + "timeoutCondition" : 30, + "timeoutScript" : 10, + "timeoutPageLoad" : 15, + "timeoutPollingInterval": 300, + "timeoutCommand":120 + }, + "retry": { + "number": 2, + "pollingInterval": 300 + }, + "logger": { + "language": "en", + "logPageSource": true + }, + "elementCache": { + "isEnabled": false + } +}
\ No newline at end of file diff --git a/src/main/resources/testData.json b/src/main/resources/testData.json new file mode 100644 index 0000000..3539460 --- /dev/null +++ b/src/main/resources/testData.json @@ -0,0 +1,11 @@ +{ + "variant": "2", + "user": { + "login": "login", + "password": "password" + }, + "project": { + "name": "Nexage", + "id": "1" + } +}
\ No newline at end of file diff --git a/src/test/java/com/mavlushechka/a1qa/project/TestCase1.java b/src/test/java/com/mavlushechka/a1qa/project/TestCase1.java new file mode 100644 index 0000000..0bc1d61 --- /dev/null +++ b/src/test/java/com/mavlushechka/a1qa/project/TestCase1.java @@ -0,0 +1,91 @@ +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.framework.utils.StringUtils; +import com.mavlushechka.a1qa.project.models.User; +import com.mavlushechka.a1qa.project.pages.AddProjectPage; +import com.mavlushechka.a1qa.project.pages.ProjectsPage; +import com.mavlushechka.a1qa.project.pages.TestsPage; +import com.mavlushechka.a1qa.framework.utils.Collections; +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.List; +import java.util.Objects; +import java.util.function.Supplier; + +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(JsonParser.parseData("testData", "project.name")); + 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(); + Assert.assertTrue(Collections.isSortedDescending(allRunningTestsOnSite), "Tests are not sorted in descending order."); + Object[] objectsOfAllRunningTestsReceivedByApi = JsonParser.convertArray( + SiteApiUtils.getTestsJson(Integer.parseInt(JsonParser.parseData("testData", "project.id"))), + com.mavlushechka.a1qa.project.models.Test.class + ); + ArrayList<com.mavlushechka.a1qa.project.models.Test> allRunningTestsReceivedByApi = new ArrayList<>(); + for (Object object : objectsOfAllRunningTestsReceivedByApi) { + 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."); + + LoggerUtils.step("Return to the previous page in the browser (project page). Press +Add. Enter the project name, and save." + + "Call the closePopUp() js-method to close the add project window. Refresh the page."); + AqualityServices.getBrowser().goBack(); + projectsPage.clickOnAddButton(); + AqualityServices.getBrowser().tabs().switchToLastTab(); + AddProjectPage addProjectPage = new AddProjectPage(); + Supplier<String> randomTextGenerator = () -> StringUtils.generateRandomText( + Integer.parseInt(JsonParser.parseData("config", "randomTextGenerator.lettersLowerBound")), + Integer.parseInt(JsonParser.parseData("config", "randomTextGenerator.lettersUpperBound")), + Integer.parseInt(JsonParser.parseData("config", "randomTextGenerator.length")) + ); + String projectName = randomTextGenerator.get(); + addProjectPage.saveProject(projectName); + Assert.assertTrue(addProjectPage.isProjectSaved(projectName), "The project is not saved."); + String currentTabHandle = AqualityServices.getBrowser().tabs().getCurrentTabHandle(); + AqualityServices.getBrowser().tabs().closeTab(); + Assert.assertFalse(AqualityServices.getBrowser().tabs().getTabHandles().contains(currentTabHandle), "The tab is not closed."); + AqualityServices.getBrowser().tabs().switchToLastTab(); + AqualityServices.getBrowser().refresh(); + Assert.assertTrue(projectsPage.getProjects().contains(projectName), "The project is not saved."); + + LoggerUtils.step("Go to the created project page. Add test via API (along with log and screenshot of current page)."); + projectsPage.openProject(projectName); + String testName = randomTextGenerator.get(); + int testId = SiteApiUtils.putTest( + randomTextGenerator.get(), projectName, testName, randomTextGenerator.get(), randomTextGenerator.get() + ); + Assert.assertTrue(testsPage.getAllRunningTests().stream().anyMatch(test -> Objects.equals(test.name(), testName)), "The test is not added."); + SiteApiUtils.putLogToTest(testId, randomTextGenerator.get()); + SiteApiUtils.putAttachmentToTest(testId, AqualityServices.getBrowser().getScreenshot(), "image/png"); + } + +} |