Skip to content

Seo 670 new tests #2517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.wikia.webdriver.elements.communities.desktop.components.categories;

import com.wikia.webdriver.elements.communities.desktop.pages.categories.CategoryExhibitionPage;
import com.wikia.webdriver.elements.communities.desktop.pages.categories.DynamicCategoryPage;
import com.wikia.webdriver.pageobjectsfactory.pageobject.BasePageObject;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

/**
* This component lets user choose category page layout, it's available only for logged in users
*/
public class CategoryLayoutSelector extends BasePageObject {

@FindBy(css = "li[data-category-layout=mediawiki]")
private WebElement classicViewButton;
@FindBy(css = "li[data-category-layout=category-exhibition]")
private WebElement categoryExhibitionButton;
@FindBy(css = "li[data-category-layout=category-page3]")
private WebElement dynamicViewButton;
@FindBy(css = ".category-layout-selector")
private WebElement viewContainer;

public boolean isCategoryExhibitionActive() {
return categoryExhibitionButton.getAttribute("class").contains("is-active");
}

public boolean isDynamicViewActive() {
return dynamicViewButton.getAttribute("class").contains("is-active");
}

public void switchToClassicView() {
classicViewButton.click();
}

public CategoryExhibitionPage switchToCategoryExhibitionView() {
categoryExhibitionButton.click();
return new CategoryExhibitionPage();
}

public DynamicCategoryPage switchToDynamicCategoriesView() {
dynamicViewButton.click();
return new DynamicCategoryPage();
}

public boolean isVisible() {
return isVisible(viewContainer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.wikia.webdriver.elements.communities.desktop.components.categories;

import com.wikia.webdriver.common.logging.Log;
import com.wikia.webdriver.pageobjectsfactory.pageobject.BasePageObject;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class PaginationControls<T> extends BasePageObject {

private final T outer;
@FindBy(xpath = "//a[contains(text(),'First')]")
private WebElement firstButton;
@FindBy(css = ".category-page__pagination-next")
private WebElement nextButton;
@FindBy(css = ".category-page__pagination-prev")
private WebElement previousButton;
@FindBy(xpath = "//a[contains(text(),'Last')]")
private WebElement lastButton;

public PaginationControls (T outer) {
this.outer = outer;
}

public boolean isFirstButtonIsVisible() {
return isVisible(firstButton);
}

public boolean isNextButtonVisible() {
return isVisible(nextButton);
}

public boolean isPreviousButtonVisible() {
return isVisible(previousButton);
}

public boolean isLastButtonVisible() {
return isVisible(lastButton);
}

public T clickFirstButton() {
this.scrollAndClick(firstButton);
Log.info("First page button clicked.");

return outer;
}

public T clickNextButton() {
this.scrollAndClick(nextButton);
Log.info("Next page button clicked.");

return outer;
}

public T clickPreviousButton() {
this.scrollAndClick(previousButton);
Log.info("Previous page button clicked.");

return outer;
}

public T clickLastButton() {
this.scrollAndClick(lastButton);
Log.info("Last page button clicked.");

return outer;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wikia.webdriver.pageobjectsfactory.pageobject.category;
package com.wikia.webdriver.elements.communities.desktop.pages.categories;

import com.wikia.webdriver.common.logging.Log;
import com.wikia.webdriver.pageobjectsfactory.pageobject.WikiBasePageObject;
Expand All @@ -10,7 +10,7 @@

import java.util.List;

public class CategoryPageObject extends WikiBasePageObject {
public class CategoryExhibitionPage extends WikiBasePageObject {

@FindBy(css = ".category-gallery-item")
private List<WebElement> categoryGalleryItems;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.wikia.webdriver.elements.communities.desktop.pages.categories;

import com.wikia.webdriver.common.logging.Log;
import com.wikia.webdriver.elements.communities.desktop.components.categories.CategoryLayoutSelector;
import com.wikia.webdriver.elements.communities.desktop.components.categories.PaginationControls;
import com.wikia.webdriver.pageobjectsfactory.pageobject.WikiBasePageObject;

import lombok.Getter;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DynamicCategoryPage extends WikiBasePageObject {

@FindBy(css=".article-content")
private WebElement articleContent;


private By categoryMembersContainer = By.cssSelector(".category-members-grouped");
private By categoryMembers = By.cssSelector(".category-page__members li a");

@Getter(lazy = true)
private final CategoryLayoutSelector layoutSelector = new CategoryLayoutSelector();
@Getter(lazy = true)
private final PaginationControls paginationControls = new PaginationControls(this);

public String getArticleContent() {
return articleContent.getText();
}

public boolean categoryMembersContainerIsVisible() {
wait.forElementVisible(categoryMembersContainer);
Log.info("Category members container is visible.");

return true;
}

public boolean hasCategoryMembers() {
wait.forElementVisible(categoryMembers);
Log.info("Category has members.");

return driver.findElements(categoryMembers).size() > 0;
}

public List<WebElement> getMembers() {
return driver.findElements(categoryMembers);
}

public String getNumberOfElementsInCategory() {
Pattern pattern = Pattern.compile("(?:All items )\\((.d)\\)");
Matcher matcher = pattern.matcher("test");
if (matcher.group().isEmpty()) {
throw new IllegalArgumentException("Unable to extract number of elements in the category");
}
return matcher.group(0);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -747,11 +747,14 @@ public void enterEmailChangeLink(String email, String password) {

public boolean isVisible(WebElement element) {
boolean result;

try {
wait.forElementVisible(element);
result = true;
} catch (TimeoutException e) {
changeImplicitWait(0, TimeUnit.MILLISECONDS);
Log.info("Element: " + element.toString() + " not found.", e);
restoreDefaultImplicitWait();
result = false;
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.wikia.webdriver.common.core.Assertion;
import com.wikia.webdriver.common.logging.Log;
import com.wikia.webdriver.pageobjectsfactory.componentobject.modalwindows.CreateArticleModalComponentObject;
import com.wikia.webdriver.pageobjectsfactory.pageobject.category.CategoryPageObject;
import com.wikia.webdriver.elements.communities.desktop.pages.categories.CategoryExhibitionPage;

import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
Expand Down Expand Up @@ -195,18 +195,18 @@ public PortableInfobox clickImage() {
return this;
}

public CategoryPageObject clickCategoryLink() {
public CategoryExhibitionPage clickCategoryLink() {
wait.forElementVisible(categoryLinkInInfobox);
scrollAndClick(categoryLinkInInfobox);

return new CategoryPageObject();
return new CategoryExhibitionPage();
}

public CategoryPageObject clickCategoryWithIndex(int index) {
public CategoryExhibitionPage clickCategoryWithIndex(int index) {
wait.forElementVisible(categories.get(index));
scrollAndClick(categories.get(index));

return new CategoryPageObject();
return new CategoryExhibitionPage();
}

public PortableInfobox open(String articleTitle) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package com.wikia.webdriver.testcases.desktop.categoriestests;

import com.wikia.webdriver.common.core.Assertion;
import com.wikia.webdriver.common.core.annotations.Execute;
import com.wikia.webdriver.common.core.helpers.User;
import com.wikia.webdriver.common.templates.NewTestTemplate;
import com.wikia.webdriver.elements.communities.desktop.components.categories.CategoryLayoutSelector;
import com.wikia.webdriver.elements.communities.desktop.components.categories.PaginationControls;
import com.wikia.webdriver.elements.communities.desktop.pages.categories.DynamicCategoryPage;
import com.wikia.webdriver.pageobjectsfactory.pageobject.article.ArticlePageObject;

import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;

import java.util.List;

@Test(groups = {"Category, Oasis_Category"})
@Execute(onWikia = "category")
public class DynamicCategoryPageTests extends NewTestTemplate {


public void dynamicCategoryAnonNotAbleToChangeLayout() {
new ArticlePageObject().open("Category:200elements");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Define a constant instead of duplicating this literal "Category:200elements" 4 times. rule


DynamicCategoryPage categoryPage = new DynamicCategoryPage();
CategoryLayoutSelector layoutSelector = categoryPage.getLayoutSelector();
Assertion.assertFalse(layoutSelector.isVisible(), "Layout selectors are displayed for anon");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Define a constant instead of duplicating this literal "Layout selectors are displayed for anon" 3 times. rule

}

/**
* Category exhibition is set as default for USER
*/
@Execute(asUser = User.USER)
public void categoryExhibitionSetInPreferencesAsDefaultView() {
new ArticlePageObject().open("Category:200elements");

DynamicCategoryPage categoryPage = new DynamicCategoryPage();
CategoryLayoutSelector layoutSelector = categoryPage.getLayoutSelector();
Assertion.assertTrue(layoutSelector.isCategoryExhibitionActive());

}

@Execute(asUser = User.USER)
public void dynamicCategoryLoggedInUserCanChangeLayout() {
new ArticlePageObject().open("Category:200elements");

DynamicCategoryPage categoryPage = new DynamicCategoryPage();
CategoryLayoutSelector layoutSelector = categoryPage.getLayoutSelector();
Assertion.assertTrue(layoutSelector.isVisible(), "Layout selectors are displayed for anon");
String pageUrl = categoryPage.getCurrentUrl();
layoutSelector.switchToDynamicCategoriesView();
Assertion.assertStringContains(categoryPage.getCurrentUrl(), pageUrl);
}

/**
* Default settings (dynamic category) are applied for USER_2
*/
@Execute(asUser = User.USER_2)
public void pagination200elementsNoNextButton() {
new ArticlePageObject().open("Category:200elements");

DynamicCategoryPage categoryPage = new DynamicCategoryPage();
CategoryLayoutSelector layoutSelector = categoryPage.getLayoutSelector();
Assertion.assertTrue(layoutSelector.isDynamicViewActive());
PaginationControls paginationControls = categoryPage.getPaginationControls();
Assertion.assertFalse(paginationControls.isNextButtonVisible());
}

@Execute(asUser = User.USER_2)
public void pagination201elementsNextButtonVisible() {
new ArticlePageObject().open("Category:201elements");

DynamicCategoryPage categoryPage = new DynamicCategoryPage();
CategoryLayoutSelector layoutSelector = categoryPage.getLayoutSelector();
Assertion.assertEquals(layoutSelector.isDynamicViewActive(), true, "Dynamic view is not active");
PaginationControls paginationControls = categoryPage.getPaginationControls();
paginationControls.clickNextButton();
Assertion.assertEquals(categoryPage.getMembers().size(), 1, "Invalid number of members on category page");
}

@Execute(asUser = User.USER_2)
public void pagination401elementsNextButtonVisible() {
new ArticlePageObject().open("Category:401elements");

DynamicCategoryPage categoryPage = new DynamicCategoryPage();
CategoryLayoutSelector layoutSelector = categoryPage.getLayoutSelector();
Assertion.assertEquals(layoutSelector.isDynamicViewActive(), true, "Dynamic view is not active");
PaginationControls paginationControls = categoryPage.getPaginationControls();
Assertion.assertTrue(paginationControls.isNextButtonVisible(), "Next button is not visible");
Assertion.assertTrue(paginationControls.isLastButtonVisible(), "Last button is not visible");
paginationControls.clickLastButton();

List<WebElement> memberList = categoryPage.getMembers();

Assertion.assertEquals(categoryPage.getMembers().size(), 1);
Assertion.assertTrue(memberList.stream().anyMatch(e->"Article99".equals(e.getText())));
paginationControls.clickFirstButton();

memberList = categoryPage.getMembers();
Assertion.assertTrue(memberList.stream().anyMatch(e->"Article1".equals(e.getText())));
}

@Execute(asUser = User.USER_2)
public void overridingLayoutSetInPreferences() {
new ArticlePageObject().open("Category:201elements");

DynamicCategoryPage categoryPage = new DynamicCategoryPage();
CategoryLayoutSelector layoutSelector = categoryPage.getLayoutSelector();
Assertion.assertTrue(layoutSelector.isVisible(), "Layout selectors are displayed for anon");
Assertion.assertTrue(layoutSelector.isDynamicViewActive());
layoutSelector.switchToCategoryExhibitionView();
categoryPage.refreshPage();
Assertion.assertTrue(layoutSelector.isCategoryExhibitionActive());
}

@Execute(asUser = User.USER_2)
public void subcategoriesAreMixedWithArticles() {
new ArticlePageObject().open("Category:Articles");

DynamicCategoryPage categoryPage = new DynamicCategoryPage();
List<WebElement> memberList = categoryPage.getMembers();
Assertion.assertTrue(
memberList.stream().anyMatch(m -> m.getText().matches("(?:Category|Kategoria):TestArticles")),
"Category cannot be found in the list"
);

}
}
Loading