diff --git a/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/QuestionAndAnswersTest.java b/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/QuestionAndAnswersTest.java new file mode 100644 index 00000000..ac73f4b2 --- /dev/null +++ b/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/QuestionAndAnswersTest.java @@ -0,0 +1,87 @@ +package org.jtalks.tests.jcommune; + +import org.jtalks.tests.jcommune.webdriver.action.QuestionAndAnswersTopic; +import org.jtalks.tests.jcommune.webdriver.action.Topics; +import org.jtalks.tests.jcommune.webdriver.action.Users; +import org.jtalks.tests.jcommune.webdriver.entity.topic.QuestionAndAnswers; +import org.jtalks.tests.jcommune.webdriver.entity.user.User; +import org.jtalks.tests.jcommune.webdriver.exceptions.ValidationException; +import org.jtalks.tests.jcommune.webdriver.page.QuestionAndAnswersPage; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; +import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; +import static org.jtalks.tests.jcommune.webdriver.JCommuneSeleniumConfig.driver; +import static org.jtalks.tests.jcommune.webdriver.page.Pages.mainPage; + +public class QuestionAndAnswersTest { + + @BeforeClass(alwaysRun = true) + @Parameters({"appUrl"}) + public void enablingQuestionAndAnswersPlugin (String appUrl) throws Exception { + driver.get(appUrl); + mainPage.logOutIfLoggedIn(driver); + Users.signIn(User.admin()); + mainPage.openPluginsPage(); + mainPage.ensurePlugingEnabled(); + } + + + @BeforeMethod(alwaysRun = true) + @Parameters({"appUrl"}) + public void setupCase(String appUrl) throws ValidationException { + driver.get(appUrl); + mainPage.logOutIfLoggedIn(driver); + } + + + @Test(groups = "ui-tests") + public void userCanCreateQuestionWithValidTitleAndBody_ShouldPass() throws Exception { + Users.signUpAndSignIn(); + QuestionAndAnswers question = new QuestionAndAnswers(); + QuestionAndAnswers createdTopic = QuestionAndAnswersTopic.createQuestionAndAnswers(question); + Assert.assertTrue(Topics.isCreated(createdTopic)); + } + + @Test(groups = "ui-tests") + public void postValidCommentToOwnQuestion_ShouldPass() throws Exception { + Users.signUpAndSignIn(); + QuestionAndAnswers question = new QuestionAndAnswers(); + String comment = (randomAlphanumeric(200)); + QuestionAndAnswersTopic.createQuestionAndAnswers(question); + QuestionAndAnswersTopic.fillCommentToQuestion(question, comment); + } + + @Test(groups = "ui-tests") + public void editCommentToOwnQuestion_ShouldPass() throws Exception { + Users.signUpAndSignIn(); + QuestionAndAnswers question = new QuestionAndAnswers(); + String comment = (randomAlphanumeric(200)); + QuestionAndAnswersTopic.createQuestionAndAnswers(question); + QuestionAndAnswersTopic.fillCommentToQuestion(question, comment); + QuestionAndAnswersTopic.editCommentToQuestion(question, comment); + } + + @Test(groups = "ui-tests") + public void deleteCommentToOwnQuestion_ShouldPass() throws Exception { + Users.signUpAndSignIn(); + QuestionAndAnswers question = new QuestionAndAnswers(); + String comment = (randomAlphanumeric(200)); + QuestionAndAnswersTopic.createQuestionAndAnswers(question); + QuestionAndAnswersTopic.fillCommentToQuestion(question, comment); + QuestionAndAnswersTopic.deleteQAComment(question, comment); + Thread.sleep(100); + Assert.assertFalse(driver.getPageSource().contains(comment), "The comment is still present on the page"); + } + + @Test(groups = "ui-tests") + public void addAnswerToOwnQuestion_ShouldPass() throws Exception { + Users.signUpAndSignIn(); + QuestionAndAnswers question = new QuestionAndAnswers(); + QuestionAndAnswersTopic.createQuestionAndAnswers(question); + QuestionAndAnswersTopic.answerToQuestion(question); + + } +} diff --git a/functional-tests-jcommune/src/test/resources/testng.xml b/functional-tests-jcommune/src/test/resources/testng.xml index e7aa2941..cbfcaabf 100644 --- a/functional-tests-jcommune/src/test/resources/testng.xml +++ b/functional-tests-jcommune/src/test/resources/testng.xml @@ -2,6 +2,7 @@ + @@ -31,12 +32,13 @@ - - - + + + + diff --git a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/QuestionAndAnswersTopic.java b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/QuestionAndAnswersTopic.java new file mode 100644 index 00000000..400700ef --- /dev/null +++ b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/QuestionAndAnswersTopic.java @@ -0,0 +1,120 @@ +package org.jtalks.tests.jcommune.webdriver.action; + +import org.jtalks.tests.jcommune.assertion.Existence; +import org.jtalks.tests.jcommune.webdriver.JCommuneSeleniumConfig; +import org.jtalks.tests.jcommune.webdriver.entity.branch.Branch; +import org.jtalks.tests.jcommune.webdriver.entity.topic.QuestionAndAnswers; +import org.jtalks.tests.jcommune.webdriver.exceptions.CouldNotOpenPageException; +import org.jtalks.tests.jcommune.webdriver.exceptions.PermissionsDeniedException; +import org.jtalks.tests.jcommune.webdriver.exceptions.ValidationException; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebElement; +import org.testng.Assert; +import ru.yandex.qatools.allure.annotations.Step; +import java.util.List; + +import static org.apache.commons.collections.CollectionUtils.isEmpty; +import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; +import static org.jtalks.tests.jcommune.utils.ReportNgLogger.info; +import static org.jtalks.tests.jcommune.webdriver.JCommuneSeleniumConfig.driver; +import static org.jtalks.tests.jcommune.webdriver.action.Topics.openRequiredTopic; +import static org.jtalks.tests.jcommune.webdriver.page.Pages.*; +import static org.jtalks.tests.jcommune.webdriver.page.Pages.questionAndAnswersPage; + +public class QuestionAndAnswersTopic { + + public static QuestionAndAnswers createQuestionAndAnswers(QuestionAndAnswers questionAndAnswers) + throws PermissionsDeniedException, CouldNotOpenPageException, ValidationException { + if (questionAndAnswers.getBranch() == null) { + List branches = sectionPage.getBranches(); + if (isEmpty(branches)) { + throw new CouldNotOpenPageException("Could not open any branch, there were 0 on the page. " + + "Page URL: [" + JCommuneSeleniumConfig.driver.getCurrentUrl() + "]. " + + "Page Title: [" + JCommuneSeleniumConfig.driver.getTitle() + "]. " + + "Page source: " + JCommuneSeleniumConfig.driver.getPageSource()); + } + Branch branch = new Branch(sectionPage.getBranches().get(0).getText()); + questionAndAnswers.withBranch(branch); + } + Branches.openBranch(questionAndAnswers.getBranch()); + branchPage.clickQuestionAndAnswers(); + questionAndAnswersPage.fillQuesionAndAnswersFields(questionAndAnswers); + questionAndAnswersPage.clickAnswerToTopicButton(); + assertQuestionAndAnswersFormValid(); + return questionAndAnswers; + } + + private static void assertQuestionAndAnswersFormValid() throws ValidationException { + String failedFields = ""; + info("Check subject"); + if (Existence.existsImmediately(driver, questionAndAnswersPage.getSubjectErrorMessage())) { + WebElement subjectError = questionAndAnswersPage.getSubjectErrorMessage(); + failedFields += subjectError.getText() + "\n"; + } + info("Check body"); + if (Existence.existsImmediately(driver, questionAndAnswersPage.getBodyErrorMessage())) { + WebElement bodyError = questionAndAnswersPage.getBodyErrorMessage(); + failedFields += bodyError.getText(); + } + info("Check finished"); + if (!failedFields.equals("")) { + info("Found validation errors: " + failedFields); + throw new ValidationException(failedFields); + } + info("Check successful. No errors."); + } + + @Step + public static String fillCommentToQuestion(QuestionAndAnswers question, String comment) + throws PermissionsDeniedException, ValidationException { + openRequiredTopic(question); + info("We are in the required topic"); + questionAndAnswersPage.addFirstComment(comment); + questionAndAnswersPage.clickSubmitCommentButton(); + Assert.assertEquals(questionAndAnswersPage.getFirstCommentContent().getText(),comment); + return comment; + } + + @Step + public static String editCommentToQuestion(QuestionAndAnswers question, String comment) + throws PermissionsDeniedException, ValidationException { + openRequiredTopic(question); + info("We are in the required topic"); + questionAndAnswersPage.findComment(comment); + questionAndAnswersPage.clickEditCommentButton(); + String newCommentContent = randomAlphanumeric(100); + questionAndAnswersPage.editComment(newCommentContent); + questionAndAnswersPage.clickConfirmEditCommentButton(); + Assert.assertEquals(questionAndAnswersPage.getFirstCommentContent().getText(),newCommentContent); + return newCommentContent; + } + + @Step + public static void deleteQAComment(QuestionAndAnswers question,String comment) throws PermissionsDeniedException { + openRequiredTopic(question); + info("We are in the required topic"); + questionAndAnswersPage.findComment(comment); + info("Clicking delete button for topic's first comment"); + try { + questionAndAnswersPage.clickDeleteCommentButton();; + } catch (NoSuchElementException e) { + info("Delete button was not found"); + throw new PermissionsDeniedException("Delete button was not found. Lack of permissions?"); + } + questionAndAnswersPage.getConfirmDeleteCommentButton().click(); + } + + @Step + public static void answerToQuestion(QuestionAndAnswers question) throws PermissionsDeniedException { + openRequiredTopic(question); + info("We are in the required topic"); + questionAndAnswersPage.clickAnswerToQuestionButton(); + questionAndAnswersPage.getConfirmAnswerButton().click(); + info("Adding a new answer"); + String answer = randomAlphanumeric(100); + questionAndAnswersPage.fillBody(answer); + info("Click the post answer button"); + questionAndAnswersPage.getPostButton().click(); + Assert.assertEquals(questionAndAnswersPage.findAnswer(answer),answer); + } +} diff --git a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Topics.java b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Topics.java index f57ab1cd..35c0ea88 100644 --- a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Topics.java +++ b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Topics.java @@ -15,13 +15,12 @@ package org.jtalks.tests.jcommune.webdriver.action; +import com.google.common.base.Splitter; +import org.apache.commons.lang3.StringUtils; import org.jtalks.tests.jcommune.assertion.Existence; import org.jtalks.tests.jcommune.webdriver.JCommuneSeleniumConfig; import org.jtalks.tests.jcommune.webdriver.entity.branch.Branch; -import org.jtalks.tests.jcommune.webdriver.entity.topic.CodeReview; -import org.jtalks.tests.jcommune.webdriver.entity.topic.CodeReviewComment; -import org.jtalks.tests.jcommune.webdriver.entity.topic.Post; -import org.jtalks.tests.jcommune.webdriver.entity.topic.Topic; +import org.jtalks.tests.jcommune.webdriver.entity.topic.*; import org.jtalks.tests.jcommune.webdriver.entity.user.User; import org.jtalks.tests.jcommune.webdriver.exceptions.CouldNotOpenPageException; import org.jtalks.tests.jcommune.webdriver.exceptions.PermissionsDeniedException; @@ -29,11 +28,14 @@ import org.jtalks.tests.jcommune.webdriver.exceptions.ValidationException; import static org.jtalks.tests.jcommune.webdriver.JCommuneSeleniumConfig.driver; +import org.jtalks.tests.jcommune.webdriver.page.Pages; import org.jtalks.tests.jcommune.webdriver.page.PostPage; +import org.jtalks.tests.jcommune.webdriver.page.QuestionAndAnswersPage; import org.jtalks.tests.jcommune.webdriver.page.TopicPage; import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.Assert; @@ -128,7 +130,7 @@ public static void editPost(Topic topic, Post postToEdit) { String newPostContent = randomAlphanumeric(100); topicPage.fillBody(newPostContent); topicPage.clickAnswerToTopicButton(); - for(int i = 0; i < topic.getPosts().size(); i++) { + for (int i = 0; i < topic.getPosts().size(); i++) { if (topic.getPosts().get(i).getPostContent().equals(postToEdit.getPostContent())) { topic.getPosts().get(i).setPostContent(newPostContent); break; @@ -386,7 +388,7 @@ public static void editCodeReviewComment(CodeReview codeReview, CodeReviewCommen String newCommentContent = randomAlphanumeric(100); postPage.editCodeReviewCommentBody(newCommentContent); postPage.clickOkButtonInEditComment(); - for(int i = 0; i < codeReview.getComments().size(); i++) { + for (int i = 0; i < codeReview.getComments().size(); i++) { if (codeReview.getComments().get(i).getPostContent().equals(codeReviewComment.getPostContent())) { codeReview.getComments().get(i).setPostContent(newCommentContent); break; @@ -424,10 +426,11 @@ public static void editPost(CodeReview codeReview, Post postToEdit) { throw new UnsupportedOperationException("Edit post can't be done in code review type topics"); } - public static void deleteCodeReviewComment(CodeReview codeReview, CodeReviewComment codeReviewComment){ + public static void deleteCodeReviewComment(CodeReview codeReview, CodeReviewComment codeReviewComment) { openRequiredTopic(codeReview); postPage.clickDeleteInCodeReviewCommentContainingString(codeReviewComment.getPostContent()); postPage.closeDeleteCRCommentConfirmDialogOk(); } + } diff --git a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/entity/topic/QuestionAndAnswers.java b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/entity/topic/QuestionAndAnswers.java new file mode 100644 index 00000000..fecb9e77 --- /dev/null +++ b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/entity/topic/QuestionAndAnswers.java @@ -0,0 +1,9 @@ +package org.jtalks.tests.jcommune.webdriver.entity.topic; + +public class QuestionAndAnswers extends Topic { + + public QuestionAndAnswers() { + super(); + } + +} diff --git a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/BranchPage.java b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/BranchPage.java index a0426784..51583c37 100644 --- a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/BranchPage.java +++ b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/BranchPage.java @@ -43,6 +43,9 @@ public class BranchPage { @FindBy(className = "new-code-review-btn") private WebElement newCodeReviewButton; + @FindBy(className = "new-question-btn") + private WebElement newQuestionAndAnswersButton; + @FindBy(xpath = "//table[@id='topics-table']/tbody/tr/td[@class='posts-td-small posts-td-small_2']/h2/a[contains(@href, '" + JCommuneSeleniumConfig.JCOMMUNE_CONTEXT_PATH + "/topics/')]") private List topicsList; @@ -80,6 +83,23 @@ public void clickCreateCodeReview() throws PermissionsDeniedException { } } + + @Step + public void clickQuestionAndAnswers() throws PermissionsDeniedException { + info("Clicking New Question and Answers Button"); + try { + if (getNewTopicToggle() != null) { + getNewTopicToggle().click(); + } + getNewQuestionAndAnswersButton().click(); + } catch (NoSuchElementException e) { + info("No such button found!"); + throw new PermissionsDeniedException("Couldn't find New Question and Answers button. Check if Q&A plugin is enabled. Here is the page source: \n" + + driver.getPageSource()); + } + } + + public boolean isUserAlreadySubscribed() { return subscribeButton.getAttribute("href").contains("/unsubscribe"); } @@ -169,6 +189,10 @@ public WebElement getNewCodeReviewButton() { return newCodeReviewButton; } + public WebElement getNewQuestionAndAnswersButton() { + return newQuestionAndAnswersButton; + } + public List getTopicsList() { return topicsList; } diff --git a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/MainPage.java b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/MainPage.java index e314ce4c..24f370a9 100644 --- a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/MainPage.java +++ b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/MainPage.java @@ -45,6 +45,10 @@ public class MainPage { private WebElement administrationDropdownMenu; @FindBy(id = "Administration") private WebElement toggleAdmineModeLink; + @FindBy (id = "PluginPage") + WebElement togglePluginPageLink; + @FindBy (className = "plugin-checkbox") + private WebElement QuestionAndAnswersCheckbox; @FindBy(xpath = openedDropdownMenuSel) private WebElement openedDropdownMenu; @FindBy(xpath = languageSwitcherSel) @@ -246,6 +250,24 @@ public boolean isInSmallScreenMode() { } } + @Step + public void openPluginsPage() { + administrationDropdownMenu.click(); + togglePluginPageLink.click(); + } + + @Step + public void ensurePlugingEnabled() { + info("Checking if Q&A plugin is enabled"); + if (! QuestionAndAnswersCheckbox.isSelected()) { + info("Q&A plugin is disabled. Switching it ON"); + QuestionAndAnswersCheckbox.click(); + } else { + info("Q&A plugin is already enabled, doing nothing"); + } + info("Q&A plugin is switched ON"); + } + public WebElement getLastPostAuthor() { return lastPostAuthor; } diff --git a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/Pages.java b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/Pages.java index 2de7ea02..8abae5aa 100644 --- a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/Pages.java +++ b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/Pages.java @@ -1,5 +1,6 @@ package org.jtalks.tests.jcommune.webdriver.page; +import org.jtalks.tests.jcommune.webdriver.entity.topic.QuestionAndAnswers; import org.openqa.selenium.WebDriver; /** @author stanislav bashkirtsev */ @@ -16,6 +17,7 @@ public class Pages { public static ExternalLinksDialog externalLinksDialog; public static ForumSettingsDialog forumSettingsDialog; public static MoveTopicEditor moveTopicEditor; + public static QuestionAndAnswersPage questionAndAnswersPage; public static void createAllPages(WebDriver driver) { @@ -31,5 +33,6 @@ public static void createAllPages(WebDriver driver) { externalLinksDialog = new ExternalLinksDialog(driver); forumSettingsDialog = new ForumSettingsDialog(driver); moveTopicEditor = new MoveTopicEditor(driver); + questionAndAnswersPage = new QuestionAndAnswersPage(driver); } } diff --git a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/QuestionAndAnswersPage.java b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/QuestionAndAnswersPage.java new file mode 100644 index 00000000..338408b0 --- /dev/null +++ b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/QuestionAndAnswersPage.java @@ -0,0 +1,300 @@ +package org.jtalks.tests.jcommune.webdriver.page; + +import org.apache.commons.lang3.StringUtils; +import org.jtalks.tests.jcommune.webdriver.entity.topic.QuestionAndAnswers; +import org.jtalks.tests.jcommune.webdriver.entity.topic.Topic; +import org.jtalks.tests.jcommune.webdriver.exceptions.PermissionsDeniedException; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.FindBys; +import java.util.List; +import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; +import static org.jtalks.tests.jcommune.utils.ReportNgLogger.info; +import static org.jtalks.tests.jcommune.webdriver.JCommuneSeleniumConfig.driver; + + +public class QuestionAndAnswersPage extends TopicPage { + private String commentContent = randomAlphanumeric(100); + + public static final String deleteCommentWarning = "(Are you sure you want to delete this comment?)" + + "|(Удалить комментарий?)"; + public static final String answerToOwnQuestionWarning ="(Are you sure you want to answer your question?)" + + "|(Use comments if you want to respond to someone's answer. Or edit your question if you want to add more details.)" + + "|(Вы точно хотите ответить на свой же вопрос?)" + + "|(Используйте комментарии, если хотите прокомментировать чей-то ответ. Либо отредактируйте свой вопрос, если хотите добавить больше информации.)"; + + @FindBys({@FindBy (css= "[id^='prompt']")}) + private List commentFields; + + @FindBys({@FindBy (css= "[class^='comment-content']")}) + private List commentFieldsContent; + + @FindBys({@FindBy (css= "[class^='content']")}) + private List answersContent; + + @FindBy(css= "[class='comment-textarea edit-comment']") + private WebElement commentTextArea; + + @FindBy(css= "[id='antiMultiAnswersBtn']") + private WebElement answerButton; + + @FindBy(css= "[id='continue-answering']") + private WebElement confirmAnswerButton; + +// @FindBy(className = "vote-up vote-up-unpressed") +// private WebElement voteUpButton; +// +// @FindBy(className = "vote-down vote-down-unpressed") +// private WebElement voteDownButton; +// +// @FindBy(className = "vote-result") +// private WebElement voteResult; + + @FindBy (css= "[class='btn btn-primary comment-submit']") + private WebElement commentButton; + + @FindBy(css= "[class='btn comment-cancel']") + private WebElement commentCamcelButton; + + @FindBy(css= "[class='icon-pencil']") + private WebElement editCommentButton; + + @FindBy(css= "[class='icon-trash']") + private WebElement deleteCommentButton; + + @FindBy(css= "[class='btn btn-primary edit-submit']") + private WebElement editCommentConfirmButton; + + @FindBy (css= "[id='remove-review-ok']") + private WebElement confirmDeleteCommentButton; + + public QuestionAndAnswersPage(WebDriver driver) { + super(driver); + } + + public void fillQuesionAndAnswersFields(QuestionAndAnswers question) { + info("Filling QA title: [" + StringUtils.left(question.getTitle(), 100) + "...]"); + getSubjectField().sendKeys(question.getTitle()); + fillBody(question.getFirstPost().getPostContent()); + } + + public String findComment (String comment) { + info("Trying to find comment with content: " + comment); + for (WebElement currentComment : getCommentFieldsContent()) { + if (currentComment.getText().contains(comment)) { + info("Comment was found."); + } + else { + info("Comment wasn't found."); + } + break; + } + return comment; + } + + public String findAnswer (String answer) { + info("Trying to find answer with content: " + answer); + for (WebElement currentAnswer : getAnswersContent()) { + if (currentAnswer.getText().contains(answer)) { + info("Answer was found."); + } + else { + info("Answer wasn't found."); + } + break; + } + return answer; + } + + + public void clickSubmitCommentButton() throws PermissionsDeniedException { + info("Clicking the button to post new comment to the post"); + try { + getCommentButton().click(); + info("The button was clicked"); + } catch (NoSuchElementException e) { + info("Couldn't click the button, looks like the permissions are granted"); + throw new PermissionsDeniedException("User does not have permissions to leave comments in the branch"); + } + } + + public void clickEditCommentButton() throws PermissionsDeniedException { + info("Clicking the button to edit a comment"); + try { + getEditCommentButton().click(); + info("The button was clicked"); + } catch (NoSuchElementException e) { + info("Couldn't click the button, looks like the permissions are granted"); + throw new PermissionsDeniedException("User does not have permissions to edit comments in the branch"); + } + } + + + public void clickConfirmEditCommentButton() throws PermissionsDeniedException { + info("Clicking the button to save an updated comment"); + try { + getEditCommentConfirmButton().click(); + info("The button was clicked"); + } catch (NoSuchElementException e) { + info("Couldn't click the button, looks like the permissions are granted"); + throw new PermissionsDeniedException("User does not have permissions to edit comments in the branch"); + } + } + + + public void clickDeleteCommentButton() throws PermissionsDeniedException { + info("Clicking the button to remove a comment"); + try { + getDeleteCommentButton().click(); + info("The button was clicked"); + } catch (NoSuchElementException e) { + info("Couldn't click the button, looks like the permissions are granted"); + throw new PermissionsDeniedException("User does not have permissions to delete comments in the branch"); + } + } + + public void clickAnswerToQuestionButton() throws PermissionsDeniedException { + info("Clicking the button to answer to own question"); + try { + getAnswerButton().click(); + info("The button was clicked"); + } catch (NoSuchElementException e) { + info("Couldn't click the button, looks like the permissions are granted"); + throw new PermissionsDeniedException("User does not have permissions to answer to question in the branch"); + } + } + + + @Override + public void fillTopicMainFields(Topic topic) throws PermissionsDeniedException { + super.fillTopicMainFields(topic); + } + + @Override + public void clickAnswerToTopicButton() throws PermissionsDeniedException { + super.clickAnswerToTopicButton(); + } + + @Override + public void fillBody(String newMessage) { + super.fillBody(newMessage); + } + + @Override + public WebElement getPostButton() { + return super.getPostButton(); + } + + @Override + public WebElement getBodyErrorMessage() { + return super.getBodyErrorMessage(); + } + + @Override + public WebElement getSubjectErrorMessage() { + return super.getSubjectErrorMessage(); + } + + @Override + public WebElement getSubjectField() { + return super.getSubjectField(); + } + + @Override + public WebElement getMainBodyArea() { + return super.getMainBodyArea(); + } + + public List getCommentFields() { + return commentFields; + } + + public WebElement getCommentButton() { + return commentButton; + } + + + public WebElement getFirstCommentContent() { + return getCommentFieldsContent().get(0); + } + + public void addFirstComment (String answer){ + Actions actions = new Actions(driver); + for (WebElement comment : getCommentFields()) { + actions.moveToElement(comment); + actions.click(); + info("Filling new comment: " + answer); + actions.sendKeys(answer); + actions.build().perform(); + } + } + + public void editComment (String newComment){ + getCommentTextArea().clear(); + info("Filling new comment: " + newComment); + getCommentTextArea().sendKeys(newComment); + } + + +// +// public WebElement getVoteUpButton() { +// return voteUpButton; +// } +// +// public WebElement getVoteDownButton() { +// return voteDownButton; +// } +// +// public WebElement getVoteResult() { +// return voteResult; +// } +// + + public WebElement getCommentCamcelButton() { + return commentCamcelButton; + } + + public String getCommentContent() { + return commentContent; + } +// + public WebElement getEditCommentButton() { + return editCommentButton; + } + + public WebElement getEditCommentConfirmButton() { + return editCommentConfirmButton; + } + + public List getCommentFieldsContent() { + return commentFieldsContent; + } + + public List getAnswersContent() { + return answersContent; + } + + public WebElement getDeleteCommentButton() { + return deleteCommentButton; + } + + public WebElement getConfirmDeleteCommentButton() { + return confirmDeleteCommentButton; + } + + public WebElement getCommentTextArea() { + return commentTextArea; + } + + public WebElement getAnswerButton() { + return answerButton; + } + + public WebElement getConfirmAnswerButton() { + return confirmAnswerButton; + } + +} \ No newline at end of file diff --git a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/TopicPage.java b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/TopicPage.java index 12e46217..a3d0ad02 100644 --- a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/TopicPage.java +++ b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/page/TopicPage.java @@ -6,6 +6,7 @@ import org.jtalks.tests.jcommune.webdriver.JCommuneSeleniumConfig; import org.jtalks.tests.jcommune.webdriver.entity.topic.CodeReview; import org.jtalks.tests.jcommune.webdriver.entity.topic.Poll; +import org.jtalks.tests.jcommune.webdriver.entity.topic.QuestionAndAnswers; import org.jtalks.tests.jcommune.webdriver.entity.topic.Topic; import org.jtalks.tests.jcommune.webdriver.exceptions.PermissionsDeniedException; import org.openqa.selenium.NoSuchElementException; @@ -242,6 +243,7 @@ public void fillCodeReviewFields(CodeReview codeReview) { getSubjectField().sendKeys(codeReview.getTitle()); fillBody(codeReview.getContent()); } + //Getters