From ac47d5ddc69b4a210821374467c0e175148fd1af Mon Sep 17 00:00:00 2001 From: Mavlushechka Date: Wed, 16 Nov 2022 14:54:25 +0500 Subject: Remove LoggerUtils class --- .../a1qa/framework/utils/IntegerUtils.java | 4 +- .../a1qa/framework/utils/LoggerUtils.java | 46 ---------------------- .../com/mavlushechka/a1qa/framework/BaseTest.java | 2 - .../com/mavlushechka/a1qa/project/TestCase1.java | 11 +++--- 4 files changed, 8 insertions(+), 55 deletions(-) delete mode 100644 src/main/java/com/mavlushechka/a1qa/framework/utils/LoggerUtils.java diff --git a/src/main/java/com/mavlushechka/a1qa/framework/utils/IntegerUtils.java b/src/main/java/com/mavlushechka/a1qa/framework/utils/IntegerUtils.java index 5b6b7da..0c31639 100644 --- a/src/main/java/com/mavlushechka/a1qa/framework/utils/IntegerUtils.java +++ b/src/main/java/com/mavlushechka/a1qa/framework/utils/IntegerUtils.java @@ -1,5 +1,7 @@ package com.mavlushechka.a1qa.framework.utils; +import aquality.selenium.browser.AqualityServices; + import java.util.OptionalInt; import java.util.Random; @@ -14,7 +16,7 @@ public class IntegerUtils { if (randomNumber.isPresent()) { return randomNumber.getAsInt(); } - LoggerUtils.error("Incorrect min and max arguments."); + AqualityServices.getLogger().error("Incorrect min and max arguments."); throw new IllegalArgumentException("Incorrect min and max arguments."); } diff --git a/src/main/java/com/mavlushechka/a1qa/framework/utils/LoggerUtils.java b/src/main/java/com/mavlushechka/a1qa/framework/utils/LoggerUtils.java deleted file mode 100644 index 8675d92..0000000 --- a/src/main/java/com/mavlushechka/a1qa/framework/utils/LoggerUtils.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.mavlushechka.a1qa.framework.utils; - -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.config.ConfigurationSource; -import org.apache.logging.log4j.core.config.Configurator; -import org.apache.logging.log4j.core.config.xml.XmlConfiguration; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; - -public class LoggerUtils { - - private final static File CONFIGURATION_FILE = new File("src/main/resources/log4j2.xml"); - private static Logger logger; - private static int step = 0; - - - private LoggerUtils() { - } - - public static void initialize() { - try { - Configurator.initialize(new XmlConfiguration(null, new ConfigurationSource(new FileInputStream(CONFIGURATION_FILE)))); - } catch (IOException ioException) { - throw new RuntimeException(ioException); - } - logger = LogManager.getLogger(); - } - - public static void step(String text) { - step++; - info("Step %d: %s".formatted(step, text)); - } - - public static void info(String text) { - logger.log(Level.INFO, text); - } - - public static void error(String text) { - logger.log(Level.ERROR, text); - } - -} diff --git a/src/test/java/com/mavlushechka/a1qa/framework/BaseTest.java b/src/test/java/com/mavlushechka/a1qa/framework/BaseTest.java index bd4ab47..e1a2bfc 100644 --- a/src/test/java/com/mavlushechka/a1qa/framework/BaseTest.java +++ b/src/test/java/com/mavlushechka/a1qa/framework/BaseTest.java @@ -2,7 +2,6 @@ package com.mavlushechka.a1qa.framework; import aquality.selenium.browser.AqualityServices; import com.mavlushechka.a1qa.framework.utils.JsonParser; -import com.mavlushechka.a1qa.framework.utils.LoggerUtils; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeSuite; @@ -10,7 +9,6 @@ public abstract class BaseTest { @BeforeSuite public void setUp() { - LoggerUtils.initialize(); AqualityServices.getBrowser().goTo(JsonParser.parseData("config", "browser.url")); } diff --git a/src/test/java/com/mavlushechka/a1qa/project/TestCase1.java b/src/test/java/com/mavlushechka/a1qa/project/TestCase1.java index 0bc1d61..d827f04 100644 --- a/src/test/java/com/mavlushechka/a1qa/project/TestCase1.java +++ b/src/test/java/com/mavlushechka/a1qa/project/TestCase1.java @@ -3,7 +3,6 @@ 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; @@ -25,13 +24,13 @@ 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."); + AqualityServices.getLogger().info("Step 1:", "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." + AqualityServices.getLogger().info("Step 2:", "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())); @@ -39,7 +38,7 @@ public class TestCase1 extends BaseTest { 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."); + AqualityServices.getLogger().info("Step 3:", "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())); @@ -56,7 +55,7 @@ public class TestCase1 extends BaseTest { 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." + AqualityServices.getLogger().info("Step 4:", "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(); @@ -77,7 +76,7 @@ public class TestCase1 extends BaseTest { 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)."); + AqualityServices.getLogger().info("Step 5:", "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( -- cgit v1.2.3