diff options
author | Mavlushechka <mavlushechka@gmail.com> | 2022-10-17 22:18:25 +0500 |
---|---|---|
committer | Mavlushechka <mavlushechka@gmail.com> | 2022-10-17 22:18:25 +0500 |
commit | a32de03308b2246f1e7cd4c970e6f96116b41ea1 (patch) | |
tree | d20f5c41028732cb72b46dda38ec584221f542e3 /src/main/java/com/mavlushechka/a1qa/project | |
parent | b41d2c22bf3e55123a09fae8b1d548dd9548299d (diff) |
Divide classes into 2 packages: framework and project
Diffstat (limited to 'src/main/java/com/mavlushechka/a1qa/project')
17 files changed, 489 insertions, 0 deletions
diff --git a/src/main/java/com/mavlushechka/a1qa/project/constants/Attachment.java b/src/main/java/com/mavlushechka/a1qa/project/constants/Attachment.java new file mode 100644 index 0000000..ada25e8 --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/constants/Attachment.java @@ -0,0 +1,7 @@ +package com.mavlushechka.a1qa.project.constants; + +public enum Attachment { + + PHOTO + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/constants/VkApiMethod.java b/src/main/java/com/mavlushechka/a1qa/project/constants/VkApiMethod.java new file mode 100644 index 0000000..c751bca --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/constants/VkApiMethod.java @@ -0,0 +1,14 @@ +package com.mavlushechka.a1qa.project.constants; + +public enum VkApiMethod { + + WALL_GET_LIKES("wall.getLikes"), WALL_POST("wall.post"), WALL_EDIT("wall.edit"), WALL_DELETE("wall.delete"), + WALL_CREATE_COMMENT("wall.createComment"), USERS_GET("users.get"); + + public final String name; + + VkApiMethod(String name) { + this.name = name; + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/models/Attachment.java b/src/main/java/com/mavlushechka/a1qa/project/models/Attachment.java new file mode 100644 index 0000000..0350d11 --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/models/Attachment.java @@ -0,0 +1,10 @@ +package com.mavlushechka.a1qa.project.models; + +public record Attachment(com.mavlushechka.a1qa.project.constants.Attachment attachment, int ownerId, int mediaId) { + + @Override + public String toString() { + return attachment.name().toLowerCase() + ownerId + "_" + mediaId; + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/models/Comment.java b/src/main/java/com/mavlushechka/a1qa/project/models/Comment.java new file mode 100644 index 0000000..bbbdc0f --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/models/Comment.java @@ -0,0 +1,4 @@ +package com.mavlushechka.a1qa.project.models; + +public record Comment(int id, User user, Post post, String message) { +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/models/Liker.java b/src/main/java/com/mavlushechka/a1qa/project/models/Liker.java new file mode 100644 index 0000000..7f84eba --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/models/Liker.java @@ -0,0 +1,22 @@ +package com.mavlushechka.a1qa.project.models; + +public class Liker { + + private final int uid; + private final int copied; + + + public Liker(int uid, int copied) { + this.uid = uid; + this.copied = copied; + } + + public int getUid() { + return uid; + } + + public int getCopied() { + return copied; + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/models/Post.java b/src/main/java/com/mavlushechka/a1qa/project/models/Post.java new file mode 100644 index 0000000..e7c97b4 --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/models/Post.java @@ -0,0 +1,4 @@ +package com.mavlushechka.a1qa.project.models; + +public record Post(int id, User owner, String message, Attachment attachment) { +} 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..b0089e8 --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/models/User.java @@ -0,0 +1,46 @@ +package com.mavlushechka.a1qa.project.models; + +import com.google.gson.annotations.SerializedName; + +public class User { + + private final int id; + @SerializedName("first_name") + private final String firstName; + @SerializedName("last_name") + private final String lastName; + @SerializedName("can_access_closed") + private final boolean canAccessClosed; + @SerializedName("is_closed") + private final boolean isClosed; + + + public User(int id, String firstName, String lastName, boolean canAccessClosed, boolean isClosed) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + this.canAccessClosed = canAccessClosed; + this.isClosed = isClosed; + } + + public int getId() { + return id; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public boolean isCanAccessClosed() { + return canAccessClosed; + } + + public boolean isClosed() { + return isClosed; + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/pages/CommentForm.java b/src/main/java/com/mavlushechka/a1qa/project/pages/CommentForm.java new file mode 100644 index 0000000..228e34d --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/pages/CommentForm.java @@ -0,0 +1,29 @@ +package com.mavlushechka.a1qa.project.pages; + +import aquality.selenium.browser.AqualityServices; +import aquality.selenium.elements.interfaces.ILabel; +import com.mavlushechka.a1qa.framework.pages.BaseForm; +import com.mavlushechka.a1qa.project.models.Comment; +import org.openqa.selenium.By; + +import java.util.Objects; + +public class CommentForm extends BaseForm { + + private final ILabel commentLabel; + private final ILabel commentText; + + + public CommentForm(Comment comment) { + super(AqualityServices.getElementFactory().getLabel(By.id("post" + comment.user().getId() + "_" + comment.id()), "Comment"), "Comment form"); + String commentXpath = "//*[@id='" + "post" + comment.user().getId() + "_" + comment.id() + "']"; + commentLabel = AqualityServices.getElementFactory().getLabel(By.xpath(commentXpath), "Comment"); + commentText = AqualityServices.getElementFactory().getLabel(By.xpath(commentXpath + "//*[contains(@class, 'wall_reply_text')]"), "Comment"); + } + + public boolean containsComment(Comment comment) { + return Integer.parseInt(commentLabel.getAttribute("data-answering-id")) == comment.user().getId() + && Objects.equals(commentText.getText(), comment.message()); + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/pages/CommentsForm.java b/src/main/java/com/mavlushechka/a1qa/project/pages/CommentsForm.java new file mode 100644 index 0000000..4c022a6 --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/pages/CommentsForm.java @@ -0,0 +1,33 @@ +package com.mavlushechka.a1qa.project.pages; + +import aquality.selenium.browser.AqualityServices; +import aquality.selenium.elements.interfaces.IButton; +import com.mavlushechka.a1qa.framework.pages.BaseForm; +import com.mavlushechka.a1qa.project.models.Comment; +import com.mavlushechka.a1qa.project.models.Post; +import org.openqa.selenium.By; + +public class CommentsForm extends BaseForm { + + private final IButton nextCommentsButton; + + + public CommentsForm(Post post) { + super(AqualityServices.getElementFactory().getLabel(By.id("replies_wrap" + post.owner().getId() + "_" + post.id()), "Comments"), + "Comments form"); + nextCommentsButton = AqualityServices.getElementFactory().getButton( + By.xpath("//*[@id='" + "replies_wrap" + post.owner().getId() + "_" + post.id() + "']//*[contains(@class, 'replies_next')]"), + "Next comments" + ); + } + + public boolean containsComment(Comment comment) { + CommentForm commentForm = new CommentForm(comment); + + if (nextCommentsButton.getElement().isDisplayed()) { + nextCommentsButton.click(); + } + return commentForm.containsComment(comment); + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/pages/FeedPage.java b/src/main/java/com/mavlushechka/a1qa/project/pages/FeedPage.java new file mode 100644 index 0000000..abc0f91 --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/pages/FeedPage.java @@ -0,0 +1,20 @@ +package com.mavlushechka.a1qa.project.pages; + +import aquality.selenium.browser.AqualityServices; +import com.mavlushechka.a1qa.framework.pages.BaseForm; +import org.openqa.selenium.By; + +public class FeedPage extends BaseForm { + + private final SideBarForm sideBarForm = new SideBarForm(); + + + public FeedPage() { + super(AqualityServices.getElementFactory().getLabel(By.id("main_feed"), "Main feed"), "Feed"); + } + + public void clickMyProfileButton() { + sideBarForm.clickMyProfileButton(); + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/pages/HomePage.java b/src/main/java/com/mavlushechka/a1qa/project/pages/HomePage.java new file mode 100644 index 0000000..a4ab95c --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/pages/HomePage.java @@ -0,0 +1,26 @@ +package com.mavlushechka.a1qa.project.pages; + +import aquality.selenium.browser.AqualityServices; +import aquality.selenium.elements.interfaces.IButton; +import aquality.selenium.elements.interfaces.ITextBox; +import com.mavlushechka.a1qa.framework.pages.BaseForm; +import org.openqa.selenium.By; + +public class HomePage extends BaseForm { + + private final ITextBox phoneOrEmailTextBox = AqualityServices.getElementFactory().getTextBox(By.id("index_email"), "Phone or email"); + private final IButton signInButton = AqualityServices.getElementFactory().getButton( + By.xpath("//button[contains(@class, 'VkIdForm__signInButton')]"),"Sign in" + ); + + + public HomePage() { + super(AqualityServices.getElementFactory().getLabel(By.xpath("//*[contains(@class, 'IndexPageContent')]"), "Index page content"), "Home"); + } + + public void performAuthorization(String phoneOrEmail) { + phoneOrEmailTextBox.clearAndType(phoneOrEmail); + signInButton.click(); + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/pages/PostForm.java b/src/main/java/com/mavlushechka/a1qa/project/pages/PostForm.java new file mode 100644 index 0000000..a3f8972 --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/pages/PostForm.java @@ -0,0 +1,68 @@ +package com.mavlushechka.a1qa.project.pages; + +import aquality.selenium.browser.AqualityServices; +import aquality.selenium.elements.interfaces.IButton; +import aquality.selenium.elements.interfaces.ILabel; +import com.mavlushechka.a1qa.framework.pages.BaseForm; +import com.mavlushechka.a1qa.project.models.Comment; +import com.mavlushechka.a1qa.project.models.Post; +import org.openqa.selenium.By; + +import java.util.Objects; + +public class PostForm extends BaseForm { + + private final ILabel authorLabel; + private final ILabel textLabel; + private final ILabel imageLabel; + private final IButton likeButton; + + + public PostForm(Post post) { + super(AqualityServices.getElementFactory().getLabel(By.id("post" + post.owner().getId() + "_" + post.id()), "Post"), "Post form"); + String postXpath = "//*[@id='" + "post" + post.owner().getId() + "_" + post.id() + "']"; + authorLabel = AqualityServices.getElementFactory().getLabel( + By.xpath(postXpath + "//*[contains(@class, 'post_author')]//a[contains(@class, 'author')]"), "Post author" + ); + textLabel = AqualityServices.getElementFactory().getLabel(By.xpath(postXpath + "//*[contains(@class, 'wall_post_text')]"), "Post text"); + imageLabel = AqualityServices.getElementFactory().getLabel( + By.xpath(postXpath + "//*[contains(@class, 'page_post_thumb_wrap')]"), "Post image" + ); + likeButton = AqualityServices.getElementFactory().getButton(By.xpath(postXpath + "//*[@data-reaction-set-id='reactions']"), "Like"); + } + + public boolean containsPost(Post post) { + boolean containsPost = Objects.equals(authorLabel.getText(), post.owner().getFirstName() + " " + post.owner().getLastName()) + && Objects.equals(textLabel.getText(), post.message()); + + if (post.attachment() != null) { + containsPost &= Objects.equals(post.attachment().toString(), imageLabel.getAttribute("href").split("vk.com/")[1]); + } else { + containsPost &= !imageLabel.state().isDisplayed(); + } + + return containsPost; + } + + public boolean containsComment(Comment comment) { + return new CommentsForm(comment.post()).containsComment(comment); + } + + public void clickLikeButton() { + likeButton.getElement().click(); + } + + public void waitForUpdate() { + String text = textLabel.getText(); + AqualityServices.getConditionalWait().waitFor(() -> !Objects.equals(textLabel.getText(), text)); + } + + public void waitForDelete() { + AqualityServices.getConditionalWait().waitFor(() -> !postExists()); + } + + public boolean postExists() { + return authorLabel.state().isDisplayed(); + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/pages/ProfilePage.java b/src/main/java/com/mavlushechka/a1qa/project/pages/ProfilePage.java new file mode 100644 index 0000000..ae99f22 --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/pages/ProfilePage.java @@ -0,0 +1,42 @@ +package com.mavlushechka.a1qa.project.pages; + +import aquality.selenium.browser.AqualityServices; +import com.mavlushechka.a1qa.framework.pages.BaseForm; +import com.mavlushechka.a1qa.project.models.Comment; +import com.mavlushechka.a1qa.project.models.Post; +import org.openqa.selenium.By; + +public class ProfilePage extends BaseForm { + + private final ProfileWallForm profileWallForm = new ProfileWallForm(); + + + public ProfilePage() { + super(AqualityServices.getElementFactory().getLabel(By.id("profile"), "Profile"), "Profile"); + } + + public boolean containsPost(Post post) { + return profileWallForm.containsPost(post); + } + + public boolean containsComment(Comment comment) { + return profileWallForm.containsComment(comment); + } + + public boolean notContainsPost(Post post) { + return profileWallForm.notContainsPost(post); + } + + public void clickPostLikeButton(Post post) { + profileWallForm.clickPostLikeButton(post); + } + + public void waitForPostUpdate(Post post) { + profileWallForm.waitForPostUpdate(post); + } + + public void waitForPostDelete(Post post) { + profileWallForm.waitForPostDelete(post); + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/pages/ProfileWallForm.java b/src/main/java/com/mavlushechka/a1qa/project/pages/ProfileWallForm.java new file mode 100644 index 0000000..120e30f --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/pages/ProfileWallForm.java @@ -0,0 +1,44 @@ +package com.mavlushechka.a1qa.project.pages; + +import aquality.selenium.browser.AqualityServices; +import com.mavlushechka.a1qa.framework.pages.BaseForm; +import com.mavlushechka.a1qa.project.models.Comment; +import com.mavlushechka.a1qa.project.models.Post; +import org.openqa.selenium.By; + +public class ProfileWallForm extends BaseForm { + + public ProfileWallForm() { + super(AqualityServices.getElementFactory().getLabel(By.id("profile_wall"), "Profile wall"), "Profile wall form"); + } + + public boolean containsPost(Post post) { + PostForm postForm = new PostForm(post); + + if (!postForm.isOpened()) { + return false; + } + return postForm.containsPost(post); + } + + public boolean notContainsPost(Post post) { + return !new PostForm(post).postExists(); + } + + public boolean containsComment(Comment comment) { + return new PostForm(comment.post()).containsComment(comment); + } + + public void clickPostLikeButton(Post post) { + new PostForm(post).clickLikeButton(); + } + + public void waitForPostUpdate(Post post) { + new PostForm(post).waitForUpdate(); + } + + public void waitForPostDelete(Post post) { + new PostForm(post).waitForDelete(); + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/pages/SideBarForm.java b/src/main/java/com/mavlushechka/a1qa/project/pages/SideBarForm.java new file mode 100644 index 0000000..01973ec --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/pages/SideBarForm.java @@ -0,0 +1,21 @@ +package com.mavlushechka.a1qa.project.pages; + +import aquality.selenium.browser.AqualityServices; +import aquality.selenium.elements.interfaces.IButton; +import com.mavlushechka.a1qa.framework.pages.BaseForm; +import org.openqa.selenium.By; + +public class SideBarForm extends BaseForm { + + private final IButton myProfileButton = AqualityServices.getElementFactory().getButton(By.id("l_pr"), "My profile"); + + + public SideBarForm() { + super(AqualityServices.getElementFactory().getLabel(By.id("side_bar"), "Side bar"), "Side bar form"); + } + + public void clickMyProfileButton() { + myProfileButton.click(); + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/pages/SignInPage.java b/src/main/java/com/mavlushechka/a1qa/project/pages/SignInPage.java new file mode 100644 index 0000000..872f87f --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/pages/SignInPage.java @@ -0,0 +1,31 @@ +package com.mavlushechka.a1qa.project.pages; + +import aquality.selenium.browser.AqualityServices; +import aquality.selenium.elements.interfaces.IButton; +import aquality.selenium.elements.interfaces.ITextBox; +import com.mavlushechka.a1qa.framework.pages.BaseForm; +import org.openqa.selenium.By; + +public class SignInPage extends BaseForm { + + private final ITextBox passwordTextBox = AqualityServices.getElementFactory().getTextBox( + By.xpath("//input[contains(@name, 'password')]"), "Password" + ); + private final IButton continueButton = AqualityServices.getElementFactory().getButton( + By.xpath("//*[contains(@class, 'vkc__EnterPasswordNoUserInfo__buttonWrap')]//button[contains(@class, 'vkuiButton')]"), "Continue" + ); + + + public SignInPage() { + super( + AqualityServices.getElementFactory().getLabel(By.xpath("//form[contains(@class, 'vkc__EnterPasswordNoUserInfo__content')]"), + "Password form"), "Sign in" + ); + } + + public void performAuthorization(String password) { + passwordTextBox.clearAndType(password); + continueButton.click(); + } + +} diff --git a/src/main/java/com/mavlushechka/a1qa/project/utils/VkApiUtils.java b/src/main/java/com/mavlushechka/a1qa/project/utils/VkApiUtils.java new file mode 100644 index 0000000..a5cd439 --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/project/utils/VkApiUtils.java @@ -0,0 +1,68 @@ +package com.mavlushechka.a1qa.project.utils; + +import com.mavlushechka.a1qa.project.constants.VkApiMethod; +import com.mavlushechka.a1qa.framework.utils.JsonParser; +import com.mavlushechka.a1qa.framework.utils.UrlConnectionManager; +import com.mavlushechka.a1qa.project.models.Liker; +import com.mavlushechka.a1qa.project.models.Post; +import com.mavlushechka.a1qa.project.models.User; +import org.json.JSONObject; + +import java.io.IOException; + +public class VkApiUtils { + + + private final static double apiVersion = 5.131; + private final static String url = "https://api.vk.com/method/%s?v=" + apiVersion + "&%s&access_token=" + JsonParser.parseData("testData", "vkontakte.account.token"); + + + public static User getCurrentUser() throws IOException { + return JsonParser.convertToObject( + new JSONObject(UrlConnectionManager.get(url.formatted(VkApiMethod.USERS_GET.name, ""))) + .getJSONArray("response").get(0).toString(), User.class + ); + } + + public static int createPost(String message) throws IOException { + return new JSONObject(UrlConnectionManager.get(url.formatted(VkApiMethod.WALL_POST.name, "message=" + message))) + .getJSONObject("response").getInt("post_id"); + } + + public static void editPost(Post post, Post editedPost) throws IOException { + UrlConnectionManager.get( + url.formatted( + VkApiMethod.WALL_EDIT.name, + "post_id=" + post.id() + "&message=" + editedPost.message() + "&attachments=" + editedPost.attachment() + ) + ); + } + + public static void deletePost(Post post) throws IOException { + UrlConnectionManager.get(url.formatted(VkApiMethod.WALL_DELETE.name, "post_id=" + post.id())); + } + + public static int createComment(int postId, String message) throws IOException { + return new JSONObject(UrlConnectionManager.get( + url.formatted( + VkApiMethod.WALL_CREATE_COMMENT.name, "post_id=" + postId + "&message=" + message + ) + )).getJSONObject("response").getInt("comment_id"); + } + + public static boolean containsLike(Post post, User user) throws IOException { + Object[] users = JsonParser.convertArray(new JSONObject(UrlConnectionManager.get( + url.formatted(VkApiMethod.WALL_GET_LIKES.name, "post_id=" + post.id()) + )).getJSONObject("response").getJSONArray("users").toString(), + Liker.class + ); + + for (Object userObject : users) { + if (((Liker) userObject).getUid() == user.getId()) { + return true; + } + } + return false; + } + +} |