From 4bf6614ab5fc9015c48f1b17bf7a631aaf54e258 Mon Sep 17 00:00:00 2001 From: Mavlushechka Date: Mon, 17 Oct 2022 22:27:51 +0500 Subject: Divide test case classes into 2 packages: framework and project --- src/test/java/com/mavlushechka/a1qa/BaseTest.java | 22 ------- src/test/java/com/mavlushechka/a1qa/TestCase1.java | 73 --------------------- .../com/mavlushechka/a1qa/framework/BaseTest.java | 22 +++++++ .../com/mavlushechka/a1qa/project/TestCase1.java | 74 ++++++++++++++++++++++ 4 files changed, 96 insertions(+), 95 deletions(-) delete mode 100644 src/test/java/com/mavlushechka/a1qa/BaseTest.java delete mode 100644 src/test/java/com/mavlushechka/a1qa/TestCase1.java create mode 100644 src/test/java/com/mavlushechka/a1qa/framework/BaseTest.java create mode 100644 src/test/java/com/mavlushechka/a1qa/project/TestCase1.java diff --git a/src/test/java/com/mavlushechka/a1qa/BaseTest.java b/src/test/java/com/mavlushechka/a1qa/BaseTest.java deleted file mode 100644 index 8db4cf2..0000000 --- a/src/test/java/com/mavlushechka/a1qa/BaseTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.mavlushechka.a1qa; - -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; - -public class BaseTest { - - @BeforeSuite - public void setUp() { - LoggerUtils.initialize(); - AqualityServices.getBrowser().goTo(JsonParser.parseData("config", "browser.url")); - } - - @AfterTest - public void tearDown() { - AqualityServices.getBrowser().quit(); - } - -} diff --git a/src/test/java/com/mavlushechka/a1qa/TestCase1.java b/src/test/java/com/mavlushechka/a1qa/TestCase1.java deleted file mode 100644 index 289ea56..0000000 --- a/src/test/java/com/mavlushechka/a1qa/TestCase1.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.mavlushechka.a1qa; - -import aquality.selenium.browser.AqualityServices; -import com.mavlushechka.a1qa.project.models.Attachment; -import com.mavlushechka.a1qa.project.models.Comment; -import com.mavlushechka.a1qa.project.models.Post; -import com.mavlushechka.a1qa.project.models.User; -import com.mavlushechka.a1qa.project.pages.FeedPage; -import com.mavlushechka.a1qa.project.pages.HomePage; -import com.mavlushechka.a1qa.project.pages.ProfilePage; -import com.mavlushechka.a1qa.project.pages.SignInPage; -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.utils.VkApiUtils; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.io.IOException; - -public class TestCase1 extends BaseTest { - - @Test - public void test1() throws IOException { - HomePage homePage = new HomePage(); - Assert.assertTrue(homePage.isOpened(), "This is not the " + homePage.getName() + " page."); - LoggerUtils.step("[UI] Authorize."); - homePage.performAuthorization(JsonParser.parseData("testData", "vkontakte.account.login")); - - SignInPage signInPage = new SignInPage(); - Assert.assertTrue(signInPage.isOpened(), "This is not the " + signInPage.getName() + " page."); - signInPage.performAuthorization(JsonParser.parseData("testData", "vkontakte.account.password")); - - FeedPage feedPage = new FeedPage(); - Assert.assertTrue(feedPage.isOpened(), "This is not the " + feedPage.getName() + " page."); - AqualityServices.getBrowser().waitForPageToLoad(); - LoggerUtils.step("[UI] Go to \"My profile\"."); - feedPage.clickMyProfileButton(); - - ProfilePage profilePage = new ProfilePage(); - Assert.assertTrue(profilePage.isOpened(), "This is not the " + profilePage.getName() + " page."); - User user = VkApiUtils.getCurrentUser(); - int textLettersLowerBound = Integer.parseInt(JsonParser.parseData("config", "randomTextGenerator.lettersLowerBound")); - int textLettersUpperBound = Integer.parseInt(JsonParser.parseData("config", "randomTextGenerator.lettersUpperBound")); - int textLength = Integer.parseInt(JsonParser.parseData("config", "randomTextGenerator.length")); - String postRandomText = StringUtils.generateRandomText(textLettersLowerBound, textLettersUpperBound, textLength); - LoggerUtils.step("[API] Create post on the wall with randomly generated text using API-request and save id of the post from the API-response."); - Post post = new Post(VkApiUtils.createPost(postRandomText), user, postRandomText, null); - LoggerUtils.step("[UI] Check that post with the sent text from the correct user appeared on the wall without refreshing the page."); - Assert.assertTrue(profilePage.containsPost(post), "This is not the correct post."); - Attachment picture = new Attachment(com.mavlushechka.a1qa.project.constants.Attachment.PHOTO, user.getId(), Integer.parseInt(JsonParser.parseData("testData", "vkontakte.photoFromAlbum.id"))); - LoggerUtils.step("[API] Edit the added post using API-request - change text and add(upload) a picture."); - Post editedPost = new Post(post.id(), user, post.message() + "[edited]", picture); - VkApiUtils.editPost(post, editedPost); - profilePage.waitForPostUpdate(editedPost); - LoggerUtils.step("[UI] Check that text was updated and the picture was uploaded(make sure that pictures are the same) without refreshing the page."); - Assert.assertTrue(profilePage.containsPost(editedPost), "This is not the correct post."); - String commentRandomText = StringUtils.generateRandomText(textLettersLowerBound, textLettersUpperBound, textLength); - LoggerUtils.step("[API] Add a comment to the post with the randomly generated text using API-request."); - Comment comment = new Comment(VkApiUtils.createComment(editedPost.id(), commentRandomText), user, editedPost, commentRandomText); - LoggerUtils.step("[UI] Check that comment from the correct user was added to the post without refreshing the page."); - Assert.assertTrue(profilePage.containsComment(comment), "This is not the correct comment."); - LoggerUtils.step("[UI] Like the post using UI."); - profilePage.clickPostLikeButton(post); - LoggerUtils.step("[API] Check that the post received like from the correct user using API-request."); - Assert.assertTrue(VkApiUtils.containsLike(editedPost, user), "The post did not receive like from the correct user."); - LoggerUtils.step("[API] Delete the post using API-request."); - VkApiUtils.deletePost(editedPost); - profilePage.waitForPostDelete(editedPost); - Assert.assertTrue(profilePage.notContainsPost(editedPost), "The post is not deleted."); - } - -} diff --git a/src/test/java/com/mavlushechka/a1qa/framework/BaseTest.java b/src/test/java/com/mavlushechka/a1qa/framework/BaseTest.java new file mode 100644 index 0000000..c4240d5 --- /dev/null +++ b/src/test/java/com/mavlushechka/a1qa/framework/BaseTest.java @@ -0,0 +1,22 @@ +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; + +public class BaseTest { + + @BeforeSuite + public void setUp() { + LoggerUtils.initialize(); + AqualityServices.getBrowser().goTo(JsonParser.parseData("config", "browser.url")); + } + + @AfterTest + public void tearDown() { + AqualityServices.getBrowser().quit(); + } + +} 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..b482f1a --- /dev/null +++ b/src/test/java/com/mavlushechka/a1qa/project/TestCase1.java @@ -0,0 +1,74 @@ +package com.mavlushechka.a1qa.project; + +import aquality.selenium.browser.AqualityServices; +import com.mavlushechka.a1qa.framework.BaseTest; +import com.mavlushechka.a1qa.project.models.Attachment; +import com.mavlushechka.a1qa.project.models.Comment; +import com.mavlushechka.a1qa.project.models.Post; +import com.mavlushechka.a1qa.project.models.User; +import com.mavlushechka.a1qa.project.pages.FeedPage; +import com.mavlushechka.a1qa.project.pages.HomePage; +import com.mavlushechka.a1qa.project.pages.ProfilePage; +import com.mavlushechka.a1qa.project.pages.SignInPage; +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.utils.VkApiUtils; +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.io.IOException; + +public class TestCase1 extends BaseTest { + + @Test + public void test1() throws IOException { + HomePage homePage = new HomePage(); + Assert.assertTrue(homePage.isOpened(), "This is not the " + homePage.getName() + " page."); + LoggerUtils.step("[UI] Authorize."); + homePage.performAuthorization(JsonParser.parseData("testData", "vkontakte.account.login")); + + SignInPage signInPage = new SignInPage(); + Assert.assertTrue(signInPage.isOpened(), "This is not the " + signInPage.getName() + " page."); + signInPage.performAuthorization(JsonParser.parseData("testData", "vkontakte.account.password")); + + FeedPage feedPage = new FeedPage(); + Assert.assertTrue(feedPage.isOpened(), "This is not the " + feedPage.getName() + " page."); + AqualityServices.getBrowser().waitForPageToLoad(); + LoggerUtils.step("[UI] Go to \"My profile\"."); + feedPage.clickMyProfileButton(); + + ProfilePage profilePage = new ProfilePage(); + Assert.assertTrue(profilePage.isOpened(), "This is not the " + profilePage.getName() + " page."); + User user = VkApiUtils.getCurrentUser(); + int textLettersLowerBound = Integer.parseInt(JsonParser.parseData("config", "randomTextGenerator.lettersLowerBound")); + int textLettersUpperBound = Integer.parseInt(JsonParser.parseData("config", "randomTextGenerator.lettersUpperBound")); + int textLength = Integer.parseInt(JsonParser.parseData("config", "randomTextGenerator.length")); + String postRandomText = StringUtils.generateRandomText(textLettersLowerBound, textLettersUpperBound, textLength); + LoggerUtils.step("[API] Create post on the wall with randomly generated text using API-request and save id of the post from the API-response."); + Post post = new Post(VkApiUtils.createPost(postRandomText), user, postRandomText, null); + LoggerUtils.step("[UI] Check that post with the sent text from the correct user appeared on the wall without refreshing the page."); + Assert.assertTrue(profilePage.containsPost(post), "This is not the correct post."); + Attachment picture = new Attachment(com.mavlushechka.a1qa.project.constants.Attachment.PHOTO, user.getId(), Integer.parseInt(JsonParser.parseData("testData", "vkontakte.photoFromAlbum.id"))); + LoggerUtils.step("[API] Edit the added post using API-request - change text and add(upload) a picture."); + Post editedPost = new Post(post.id(), user, post.message() + "[edited]", picture); + VkApiUtils.editPost(post, editedPost); + profilePage.waitForPostUpdate(editedPost); + LoggerUtils.step("[UI] Check that text was updated and the picture was uploaded(make sure that pictures are the same) without refreshing the page."); + Assert.assertTrue(profilePage.containsPost(editedPost), "This is not the correct post."); + String commentRandomText = StringUtils.generateRandomText(textLettersLowerBound, textLettersUpperBound, textLength); + LoggerUtils.step("[API] Add a comment to the post with the randomly generated text using API-request."); + Comment comment = new Comment(VkApiUtils.createComment(editedPost.id(), commentRandomText), user, editedPost, commentRandomText); + LoggerUtils.step("[UI] Check that comment from the correct user was added to the post without refreshing the page."); + Assert.assertTrue(profilePage.containsComment(comment), "This is not the correct comment."); + LoggerUtils.step("[UI] Like the post using UI."); + profilePage.clickPostLikeButton(post); + LoggerUtils.step("[API] Check that the post received like from the correct user using API-request."); + Assert.assertTrue(VkApiUtils.containsLike(editedPost, user), "The post did not receive like from the correct user."); + LoggerUtils.step("[API] Delete the post using API-request."); + VkApiUtils.deletePost(editedPost); + profilePage.waitForPostDelete(editedPost); + Assert.assertTrue(profilePage.notContainsPost(editedPost), "The post is not deleted."); + } + +} -- cgit v1.2.3