Skip to content

Commit

Permalink
updated tests for Manage libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
AEkaterina committed Dec 20, 2023
1 parent 5392220 commit 5f62e7a
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 38 deletions.
6 changes: 3 additions & 3 deletions src/test/java/features/ManageLibraries.feature
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Feature: Manage Libraries
And Open Catalog
And Switch to 'Palace Bookshelf' from side menu
And Open categories by chain and chain starts from CategoryScreen:
| Summer Reading |
| Holiday Reads |
And Click GET action button on the first EBOOK book on catalog books screen and save book as 'bookInfo'
And Open Books
Then EBOOK book with READ action button and 'bookInfo' bookInfo is present on books screen
Expand Down Expand Up @@ -183,8 +183,8 @@ Feature: Manage Libraries
| Escondido Public Library |
| Granby Public Library |
| Victorville City Library |
And Save 5 amount as 'amountKey'
When Tap the logo on catalog screen
And Save 6 amount as 'amountKey'
And Tap the logo on catalog screen
Then The sorting of 'amountKey' libraries is alphabetical on find your library screen
When Tap cancel button on find your library screen
Then Category names are loaded on Catalog screen
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/screens/AddLibraryScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import aquality.appium.mobile.elements.ElementType;
import aquality.appium.mobile.elements.interfaces.IButton;
import aquality.appium.mobile.elements.interfaces.IElement;
import aquality.appium.mobile.elements.interfaces.ILabel;
import aquality.appium.mobile.elements.interfaces.ITextBox;
import aquality.appium.mobile.screens.Screen;
Expand Down Expand Up @@ -32,7 +31,8 @@ public class AddLibraryScreen extends Screen {
new AndroidLocator(By.id("search_close_btn")),
new IosLocator(By.xpath("//XCUIElementTypeButton[@name=\"clear.button.text\"]"))), "Clear search field button");

private static final String LIBRARY_BUTTON_LOCATOR_ANDROID = "//android.widget.TextView[contains(@text, \"%s\")]";
private static final String CURRENT_LIBRARY_BUTTON_LOCATOR_ANDROID = "//android.widget.TextView[contains(@text, \"%s\")]";
private static final String LIBRARY_BUTTON_LOCATOR_ANDROID = "//androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup/android.widget.TextView[1]";
private static final String LIBRARY_BUTTON_LOCATOR_IOS = "//XCUIElementTypeStaticText[contains(@name, \"%s\")]";


Expand Down Expand Up @@ -108,12 +108,12 @@ public boolean isSortingOfLibrariesCorrect() {

private IButton getLibraryButton(String libraryName) {
return getElementFactory().getButton(LocatorUtils.getLocator(
new AndroidLocator(By.xpath(String.format(LIBRARY_BUTTON_LOCATOR_ANDROID, libraryName))),
new AndroidLocator(By.xpath(String.format(CURRENT_LIBRARY_BUTTON_LOCATOR_ANDROID, libraryName))),
new IosLocator(By.xpath(String.format(LIBRARY_BUTTON_LOCATOR_IOS, libraryName)))), libraryName);
}

private List<String> getLibrariesNames() {
List<IElement> libraries = getElementFactory().findElements(LocatorUtils.getLocator(
List<ILabel> libraries = getElementFactory().findElements(LocatorUtils.getLocator(
new AndroidLocator(By.xpath(LIBRARY_BUTTON_LOCATOR_ANDROID)),
new IosLocator(By.xpath(LIBRARY_BUTTON_LOCATOR_IOS))), ElementType.LABEL);

Expand Down
5 changes: 3 additions & 2 deletions src/test/java/screens/CatalogScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import aquality.appium.mobile.screens.Screen;
import aquality.selenium.core.elements.ElementState;
import aquality.selenium.core.elements.ElementsCount;
import constants.appattributes.AndroidAttributes;
import constants.appattributes.IosAttributes;
import framework.utilities.ActionProcessorUtils;
import framework.utilities.LocatorUtils;
Expand Down Expand Up @@ -42,7 +43,7 @@ public class CatalogScreen extends Screen {
private static final String CATEGORY_NAME_LOCATOR_ANDROID = "//android.widget.TextView[contains(@resource-id, \"feedLaneTitle\") and @text=\"%1$s\"]/parent::android.widget.LinearLayout/following-sibling::*[contains(@resource-id,\"feedLaneCoversScroll\")]";
private static final String CATEGORY_LOCATOR_ANDROID = "//androidx.recyclerview.widget.RecyclerView//android.widget.LinearLayout/android.widget.TextView[1]";
private static final String BOOK_COVER_IN_CATEGORY_LOCATOR_ANDROID = "/android.widget.FrameLayout";
private static final String BOOK_NAME_LOCATOR_ANDROID = "//androidx.recyclerview.widget.RecyclerView[contains(@resource-id,\"feedWithoutGroupsList\")]/android.widget.FrameLayout/android.view.ViewGroup/android.widget.TextView[1]";
private static final String BOOK_NAME_LOCATOR_ANDROID = "//androidx.recyclerview.widget.RecyclerView[contains(@resource-id,\"feedLaneCoversScroll\")]/android.widget.FrameLayout";
private static final String CURRENT_CATEGORY_LOCATOR_ANDROID = "//android.widget.TextView[contains(@resource-id, \"feedLaneTitle\") and @text=\"%1$s\"]";
private static final String MORE_BUTTON_LOCATOR_ANDROID = "//android.widget.LinearLayout/android.widget.TextView[@text=\"More…\"]";
private static final String CURRENT_SECTION_LOCATOR_IN_CATALOG_ANDROID = "//androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout[%d]/android.widget.LinearLayout/android.widget.TextView[1]";
Expand Down Expand Up @@ -96,7 +97,7 @@ public Set<String> getListOfBooksNameInFirstCategory() {
public List<String> getListOfBooksNames() {
List<String> listOfBookNames = ActionProcessorUtils.doForAndroid(() -> {
List<ILabel> listOfBooks = getElementFactory().findElements(By.xpath(BOOK_NAME_LOCATOR_ANDROID), ElementType.LABEL);
return listOfBooks.stream().map(book -> book.getText()).collect(Collectors.toList());
return listOfBooks.stream().map(book -> book.getAttribute(AndroidAttributes.CONTENT_DESC)).collect(Collectors.toList());
});

if(listOfBookNames == null) {
Expand Down
36 changes: 13 additions & 23 deletions src/test/java/screens/FindYourLibraryScreen.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package screens;

import aquality.appium.mobile.elements.ElementType;
import aquality.appium.mobile.elements.interfaces.IButton;
import aquality.appium.mobile.elements.interfaces.ILabel;
import aquality.appium.mobile.screens.Screen;
Expand All @@ -16,16 +17,13 @@ public class FindYourLibraryScreen extends Screen {
private final IButton btnAddLib = getElementFactory().getButton(LocatorUtils.getLocator(
new AndroidLocator(By.xpath("//android.widget.LinearLayout//android.widget.TextView[@text=\"Add Library\"]")),
new IosLocator(By.xpath("//XCUIElementTypeScrollView//XCUIElementTypeButton[@name=\"Add Library\"]"))), "Add library button");
private final CreatingLibraryLocator libraryLocator = (index ->
getElementFactory().getLabel(LocatorUtils.getLocator(
new AndroidLocator(By.xpath(String.format("//android.widget.LinearLayout//androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout[%d]/android.widget.LinearLayout/android.widget.TextView[1]", index))),
new IosLocator(By.xpath(String.format("//XCUIElementTypeSheet//XCUIElementTypeScrollView[2]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther[%d]/XCUIElementTypeButton", index)))), "Library"));
private final IButton btnCancel = getElementFactory().getButton(LocatorUtils.getLocator(
new AndroidLocator(By.xpath("//android.widget.TextView[@text=\"Cancel\"]")),
new IosLocator(By.xpath("//XCUIElementTypeSheet//XCUIElementTypeScrollView//XCUIElementTypeButton[@name=\"Cancel\"]"))), "Close button");

private static final String LIBRARY_NAME_IOS = "//XCUIElementTypeSheet//XCUIElementTypeScrollView//XCUIElementTypeButton[@name=\"%s\"]";
private static final String LIBRARY_NAME_ANDROID = "//android.widget.LinearLayout/android.widget.TextView[@text=\"%s\"]";
private static final String CURRENT_LIBRARY_NAME_LOCATOR_ANDROID = "//android.widget.LinearLayout/android.widget.TextView[@text=\"%s\"]";
private static final String LIBRARY_NAME_LOCATOR_ANDROID = "//androidx.recyclerview.widget.RecyclerView[contains(@resource-id,\"recyclerView\")]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.TextView[1]";

public FindYourLibraryScreen() {
super(LocatorUtils.getLocator(
Expand All @@ -39,34 +37,26 @@ public void tapAddLibrary() {

public void tapToLibrary(String libName) {
getElementFactory().getButton(LocatorUtils.getLocator(
new AndroidLocator(By.xpath(String.format(LIBRARY_NAME_ANDROID, libName))),
new AndroidLocator(By.xpath(String.format(CURRENT_LIBRARY_NAME_LOCATOR_ANDROID, libName))),
new IosLocator(By.xpath(String.format(LIBRARY_NAME_IOS, libName)))), "Library button").click();
}

public boolean isSortingAlphabetical(int amountOfLibraries) {
List<String > libraries = getListOfLibraries(amountOfLibraries);
public boolean isSortingAlphabetical(int libraryAmount) {
List<String> libraries = getListOfLibraries(libraryAmount);
return Ordering.natural().isOrdered(libraries);
}

public void tapCancelBtn() {
btnCancel.click();
}

private List<String > getListOfLibraries(int listSize) {
List<String > libraries = new ArrayList<>();
int index = 1;
int end = 0;
while (end <= listSize) {
ILabel lblLibrary = libraryLocator.createLbl(index);
libraries.add(lblLibrary.getText());
index+=2;
end++;
}
return libraries;
}
private List<String > getListOfLibraries(int amount) {
List<ILabel> libraryLabels = getElementFactory().findElements(LocatorUtils.getLocator(
new AndroidLocator(By.xpath(LIBRARY_NAME_LOCATOR_ANDROID)),
new IosLocator(By.xpath("asd"))), ElementType.LABEL);

@FunctionalInterface
interface CreatingLibraryLocator {
ILabel createLbl(int index);
List<String> libraries = new ArrayList<>();
libraryLabels.stream().limit(amount).forEach(label -> libraries.add(label.getText().toLowerCase()));
return libraries;
}
}
4 changes: 1 addition & 3 deletions src/test/java/screens/LibrariesScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public class LibrariesScreen extends Screen {
new AndroidLocator(By.id("accountsMenuActionAccountAdd")),
new IosLocator(By.xpath("//XCUIElementTypeButton[@name=\"Add Library\"]"))), "Add library button");
private final IButton btnDeleteLibrary = getElementFactory().getButton(LocatorUtils.getLocator(
new AndroidLocator(By.xpath("//android.widget.TextView[@text=\"Delete\"]")),
new AndroidLocator(By.xpath("//android.widget.Button[@text=\"Remove\"]")),
new IosLocator(By.xpath("//XCUIElementTypeButton[@label=\"Delete\"]"))), "Delete library button");
private final IButton btnAcceptDeletionAndroid = getElementFactory().getButton(By.id("android:id/button1"), "btnAcceptDeletion");

private static final String LIBRARY_NAME_LOC_IOS = "//XCUIElementTypeStaticText[@name=\"%s\"]/parent::XCUIElementTypeCell";
private static final String LIBRARY_NAME_ON_LIBRARY_SETTINGS_LOC_IOS = "//XCUIElementTypeStaticText[@name=\"%s\"]";
Expand Down Expand Up @@ -101,7 +100,6 @@ public void deleteLibrary(String libraryName) {
ActionProcessorUtils.doForAndroid(() -> {
getElementFactory().getButton(By.xpath(String.format(POPUP_MENU_BUTTON_BY_LIBRARY_NAME_LOC_ANDROID, libraryName)), "Popup menu button").click();
btnDeleteLibrary.click();
btnAcceptDeletionAndroid.click();
});
}

Expand Down
1 change: 1 addition & 0 deletions src/test/java/stepdefinitions/AccountSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public void removeAccount(String libraryName) {

@Then("Library {string} is not present on Libraries screen")
public void checkAccountIsNotPresent(String libraryName) {
openAccounts();
Assert.assertFalse(libraryName + " is present on Accounts screen", librariesScreen.isLibraryPresent(libraryName));
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/stepdefinitions/ApplicationSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public void tapTheLogo() {
@Then("The sorting of {string} libraries is alphabetical on find your library screen")
public void isSortingCorrect(String amountKey) {
int amount = context.get(amountKey);
Assert.assertTrue("The list of libraries is not in alphabetical ored", findYourLibraryScreen.isSortingAlphabetical(amount));
Assert.assertTrue("The list of libraries is not in alphabetical order", findYourLibraryScreen.isSortingAlphabetical(amount));
}

@When("Tap cancel button on find your library screen")
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/stepdefinitions/CatalogSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void checkCurrentCategoryName(String expectedCategoryName) {
@Then("List of books on screen is not equal to list of books saved as {string}")
public void checkListOfBooksAndSavedListOfBooks(String booksNamesListKey) {
List<String> expectedList = context.get(booksNamesListKey);
List<String> actualList = catalogBooksScreen.getListOfBooks();
List<String> actualList = catalogScreen.getListOfBooksNames();
Assert.assertNotEquals("Lists of books are equal" + expectedList.stream().map(Object::toString).collect(Collectors.joining(", ")), expectedList, actualList);
}

Expand Down
3 changes: 2 additions & 1 deletion src/test/java/stepdefinitions/CredentialsSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import enums.localization.catalog.ActionButtonsForBooksAndAlertsKeys;
import framework.configuration.Configuration;
import framework.configuration.Credentials;
import framework.utilities.ActionProcessorUtils;
import framework.utilities.ScenarioContext;
import framework.utilities.returningbooksutil.APIUtil;
import io.cucumber.java.en.Then;
Expand Down Expand Up @@ -78,7 +79,7 @@ public void checkLoginIsPerformedSuccessfully() {
@When("Click the log out button on the account screen")
public void clickLogOut() {
accountScreen.tapSignOut();
accountScreen.tapApproveSignOut();
ActionProcessorUtils.doForIos(accountScreen::tapApproveSignOut);
if(alertScreen.state().waitForDisplayed()){
alertScreen.waitAndPerformAlertActionIfDisplayed(ActionButtonsForBooksAndAlertsKeys.SIGN_OUT);
}
Expand Down

0 comments on commit 5f62e7a

Please sign in to comment.