summaryrefslogtreecommitdiff
path: root/src/test/java/com/mavlushechka/a1qa
diff options
context:
space:
mode:
authorMavlushechka <mavlushechka@gmail.com>2022-10-07 23:46:46 +0500
committerMavlushechka <mavlushechka@gmail.com>2022-10-07 23:46:46 +0500
commitf8501d374dbd39a66078bad11384ea241848acc6 (patch)
tree41deb41375982e3db1d4071117dcf22377145ab8 /src/test/java/com/mavlushechka/a1qa
parent4495c73482a9fb3bdb87a75816974602e833278e (diff)
Solve 1st test case
Diffstat (limited to 'src/test/java/com/mavlushechka/a1qa')
-rw-r--r--src/test/java/com/mavlushechka/a1qa/BaseTest.java10
-rw-r--r--src/test/java/com/mavlushechka/a1qa/TestCase1.java119
2 files changed, 58 insertions, 71 deletions
diff --git a/src/test/java/com/mavlushechka/a1qa/BaseTest.java b/src/test/java/com/mavlushechka/a1qa/BaseTest.java
index 2bfdd4b..9ba4ce4 100644
--- a/src/test/java/com/mavlushechka/a1qa/BaseTest.java
+++ b/src/test/java/com/mavlushechka/a1qa/BaseTest.java
@@ -1,7 +1,7 @@
package com.mavlushechka.a1qa;
-import com.mavlushechka.a1qa.driverUtils.WebDriverUtils;
-import com.mavlushechka.a1qa.utils.JSONParser;
+import aquality.selenium.browser.AqualityServices;
+import com.mavlushechka.a1qa.utils.JsonParser;
import com.mavlushechka.a1qa.utils.LoggerUtils;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
@@ -11,14 +11,12 @@ public class BaseTest {
@BeforeSuite
public void setUp() {
LoggerUtils.initialize();
- LoggerUtils.step("Go to home page.");
- WebDriverUtils.goToAddress(JSONParser.parseData("config", "browser.url"));
+ AqualityServices.getBrowser().goTo(JsonParser.parseData("config", "browser.url"));
}
@AfterTest
public void tearDown() {
- LoggerUtils.info("Quiting the webdriver.");
- WebDriverUtils.quit();
+ AqualityServices.getBrowser().quit();
}
}
diff --git a/src/test/java/com/mavlushechka/a1qa/TestCase1.java b/src/test/java/com/mavlushechka/a1qa/TestCase1.java
index d641dc2..c6b3b2d 100644
--- a/src/test/java/com/mavlushechka/a1qa/TestCase1.java
+++ b/src/test/java/com/mavlushechka/a1qa/TestCase1.java
@@ -1,84 +1,73 @@
package com.mavlushechka.a1qa;
-import com.mavlushechka.a1qa.constants.Endpoint;
-import com.mavlushechka.a1qa.constants.RequestMethod;
-import com.mavlushechka.a1qa.constants.Status;
+import aquality.selenium.browser.AqualityServices;
+import com.mavlushechka.a1qa.models.Attachment;
+import com.mavlushechka.a1qa.models.Comment;
import com.mavlushechka.a1qa.models.Post;
import com.mavlushechka.a1qa.models.User;
-import com.mavlushechka.a1qa.utils.*;
+import com.mavlushechka.a1qa.pages.FeedPage;
+import com.mavlushechka.a1qa.pages.HomePage;
+import com.mavlushechka.a1qa.pages.ProfilePage;
+import com.mavlushechka.a1qa.pages.SignInPage;
+import com.mavlushechka.a1qa.utils.JsonParser;
+import com.mavlushechka.a1qa.utils.LoggerUtils;
+import com.mavlushechka.a1qa.utils.StringUtils;
+import com.mavlushechka.a1qa.utils.VkApiUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.io.IOException;
-import java.util.List;
public class TestCase1 extends BaseTest {
@Test
public void test1() throws IOException {
- int postsResponseCode = JSONPlaceholderAPIManager.getPostsResponseCode(RequestMethod.GET);
- Assert.assertEquals(postsResponseCode, Status.OK.code, "Response code is not correct.");
- LoggerUtils.step("Send GET Request to get all posts (/posts).");
- String postsJson = URLConnectionManager.get(Endpoint.POSTS.spec);
- Assert.assertTrue(JSONParser.isJson(postsJson), "Response is not json.");
- List<Post> postsList = JSONPlaceholderAPIManager.getPosts();
- Assert.assertTrue(Posts.isPostsAscending(postsList), "Posts are not sorted ascending.");
+ 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"));
- int post99Id = Integer.parseInt(JSONParser.parseData("testData", "testCases[0].steps[1].post.id"));
- int post99ResponseCode = JSONPlaceholderAPIManager.getPostResponseCode(post99Id, RequestMethod.GET);
- Assert.assertEquals(post99ResponseCode, Status.OK.code, "Response code is not correct.");
- LoggerUtils.step("Send GET request to get post with id=99 (/posts/99).");
- Post post99 = JSONPlaceholderAPIManager.getPost(post99Id);
- Assert.assertEquals(post99.id, JSONParser.parseData("testData", "testCases[0].steps[1].post.id"), "Post id is not correct.");
- Assert.assertEquals(post99.userId, JSONParser.parseData("testData", "testCases[0].steps[1].post.userId"), "Post user id is not correct.");
- Assert.assertEquals(post99.title.isEmpty(), Boolean.parseBoolean(JSONParser.parseData("testData", "testCases[0].steps[1].post.isTitleEmpty")), "Post title is not correct.");
- Assert.assertEquals(post99.body.isEmpty(), Boolean.parseBoolean(JSONParser.parseData("testData", "testCases[0].steps[1].post.isBodyEmpty")), "Post body is not correct.");
+ SignInPage signInPage = new SignInPage();
+ Assert.assertTrue(signInPage.isOpened(), "This is not the " + signInPage.getName() + " page.");
+ signInPage.performAuthorization(JsonParser.parseData("testData", "vkontakte.account.password"));
- int post150Id = Integer.parseInt(JSONParser.parseData("testData", "testCases[0].steps[2].post.id"));
- int post150ResponseCode = JSONPlaceholderAPIManager.getPostResponseCode(post150Id, RequestMethod.GET);
- Assert.assertEquals(post150ResponseCode, Status.NOT_FOUND.code, "Response code is not correct.");
- LoggerUtils.step("Send GET request to get post with id=150 (/posts/150).");
- String post150Json;
- try {
- post150Json = URLConnectionManager.get(Endpoint.POSTS.spec + "/" + post150Id);
- } catch (IOException ioException) {
- post150Json = "{}";
- }
- Assert.assertEquals(JSONParser.isBodyEmpty(post150Json), Boolean.parseBoolean(JSONParser.parseData("testData", "testCases[0].steps[2].isResponseBodyEmpty")), "Response body is not correct.");
+ 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();
- int randomTextLettersLowerBound = Integer.parseInt(JSONParser.parseData("config", "randomTextGenerator.lettersLowerBound"));
- int randomTextLettersUpperBound = Integer.parseInt(JSONParser.parseData("config", "randomTextGenerator.lettersUpperBound"));
- int randomTextLength = Integer.parseInt(JSONParser.parseData("config", "randomTextGenerator.length"));
- Post post = new Post(
- String.valueOf(postsList.size()+1),
- StringUtils.generateRandomText(randomTextLettersLowerBound, randomTextLettersUpperBound, randomTextLength),
- StringUtils.generateRandomText(randomTextLettersLowerBound, randomTextLettersUpperBound, randomTextLength),
- JSONParser.parseData("testData", "testCases[0].steps[3].post.userId")
- );
- int postResponseCode = JSONPlaceholderAPIManager.getPostsResponseCode(RequestMethod.POST);
- Assert.assertEquals(postResponseCode, Status.CREATED.code, "Response code is not correct.");
- LoggerUtils.step("Send POST request to create post with userId=1 and random body and random title (/posts).");
- Assert.assertEquals(post, JSONPlaceholderAPIManager.postPost(post), "Post information is not correct.");
-
- int usersResponseCode = JSONPlaceholderAPIManager.getUsersResponseCode(RequestMethod.GET);
- Assert.assertEquals(usersResponseCode, Status.OK.code, "Response code is not correct.");
- LoggerUtils.step("Send GET request to get users (/users).");
- List<User> users = JSONPlaceholderAPIManager.getUsers();
- User user = null;
- for (User userObject : users) {
- if (Integer.parseInt(userObject.id) == Integer.parseInt(JSONParser.parseData("testData", "testCases[0].steps[4].user.id"))) {
- user = userObject;
- break;
- }
- }
- Assert.assertEquals(JSONParser.convertToObject(JSONParser.parseObject("testData", "testCases[0].steps[4].user"), User.class), user, "User information is not correct.");
-
- int user5Id = Integer.parseInt(JSONParser.parseData("testData", "testCases[0].steps[5].user.id"));
- int user5ResponseCode = JSONPlaceholderAPIManager.getPostResponseCode(user5Id, RequestMethod.GET);
- Assert.assertEquals(user5ResponseCode, Status.OK.code, "Response code is not correct.");
- LoggerUtils.step("Send GET request to get user with id=5 (/users/5).");
- User user5 = JSONPlaceholderAPIManager.getUser(Integer.parseInt(JSONParser.parseData("testData", "testCases[0].steps[5].user.id")));
- Assert.assertEquals(user, user5, "User information is not correct.");
+ 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.contains(post), "This is not the correct post.");
+ Attachment picture = new Attachment(com.mavlushechka.a1qa.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.contains(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.contains(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.notContains(editedPost), "The post is not deleted.");
}
}