diff options
author | Mavlushechka <mavlushechka@gmail.com> | 2022-11-16 22:26:39 +0500 |
---|---|---|
committer | Mavlushechka <mavlushechka@gmail.com> | 2022-11-16 22:26:39 +0500 |
commit | 53f1717d130e9fd79ef51f3e6c75fabcbb642b34 (patch) | |
tree | 685b7a75c15f520ca766778236d565b7a5bce957 | |
parent | 82c7d1a7383e7669726f1b64232bbb05de0e2052 (diff) |
Move the authorization logic to the BrowserUtils classexam
3 files changed, 19 insertions, 10 deletions
diff --git a/src/main/java/com/mavlushechka/a1qa/framework/driverUtils/BrowserUtils.java b/src/main/java/com/mavlushechka/a1qa/framework/driverUtils/BrowserUtils.java new file mode 100644 index 0000000..087839d --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/framework/driverUtils/BrowserUtils.java @@ -0,0 +1,17 @@ +package com.mavlushechka.a1qa.framework.driverUtils; + +import aquality.selenium.browser.AqualityServices; +import com.mavlushechka.a1qa.framework.utils.StringUtils; +import com.mavlushechka.a1qa.project.models.User; + +public class BrowserUtils { + + private BrowserUtils() { + } + + public static void performAuthorization(User user, String url) { + AqualityServices.getBrowser().goTo("%s:%s@%s".formatted(user.login(), user.password(), StringUtils.removeHttpProtocol(url))); + AqualityServices.getBrowser().goTo(url); + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/pages/ProjectsPage.java b/src/main/java/com/mavlushechka/a1qa/project/pages/ProjectsPage.java index 042445b..45b6d16 100644 --- a/src/main/java/com/mavlushechka/a1qa/project/pages/ProjectsPage.java +++ b/src/main/java/com/mavlushechka/a1qa/project/pages/ProjectsPage.java @@ -6,9 +6,6 @@ import aquality.selenium.elements.interfaces.IButton; import aquality.selenium.elements.interfaces.ILabel; 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; @@ -22,7 +19,6 @@ public class ProjectsPage extends Form { private final By byProjectLabel = By.xpath("//*[contains(@class,'list-group')]//a[contains(@class,'list-group-item')]"); - private final String url = JsonParser.parseData("config", "browser.url") + "/web/projects"; private final String projectXpath = "//*[contains(@class,'panel')]//a[contains(@class,'list-group-item') and text()='%s']"; @@ -30,11 +26,6 @@ public class ProjectsPage extends Form { 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(versionLabel.getText()); } diff --git a/src/test/java/com/mavlushechka/a1qa/project/TestCase1.java b/src/test/java/com/mavlushechka/a1qa/project/TestCase1.java index 140670b..70a80d1 100644 --- a/src/test/java/com/mavlushechka/a1qa/project/TestCase1.java +++ b/src/test/java/com/mavlushechka/a1qa/project/TestCase1.java @@ -2,6 +2,7 @@ package com.mavlushechka.a1qa.project; import aquality.selenium.browser.AqualityServices; import com.mavlushechka.a1qa.framework.BaseTest; +import com.mavlushechka.a1qa.framework.driverUtils.BrowserUtils; import com.mavlushechka.a1qa.framework.utils.JsonParser; import com.mavlushechka.a1qa.framework.utils.StringUtils; import com.mavlushechka.a1qa.project.models.User; @@ -32,7 +33,7 @@ public class TestCase1 extends BaseTest { ProjectsPage projectsPage = new ProjectsPage(); 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)); + BrowserUtils.performAuthorization(JsonParser.convertToObject(JsonParser.parseObject("testData", "user"), User.class), JsonParser.parseData("config", "browser.url") + "/web/projects"); 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(); |