Skip to content

Commit

Permalink
Merge pull request #24 from ThePalaceProject/refactoring
Browse files Browse the repository at this point in the history
Refactoring android
  • Loading branch information
AEkaterina authored Dec 20, 2023
2 parents 9e5a52a + 5f62e7a commit 096ea5f
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 53 deletions.
6 changes: 3 additions & 3 deletions src/test/java/features/AudiobookOverdrive.feature
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ Feature: Audiobooks in A1QA library
And Book is not playing on audio player screen
When Save book play time as 'timeAhead' on audio player screen
And Save chapter time as 'chapterTimeKey' on audio player screen
And Skip ahead 15 seconds on audio player screen
And Skip ahead 30 seconds on audio player screen
And Tap pause button on audio player screen
Then Play button is present on audio player screen
And Playback has been moved forward by 30 seconds from 'timeAhead' and 'chapterTimeKey' seconds on audio player screen
When Save book play time as 'timeBehind' on audio player screen
And Skip behind 15 seconds on audio player screen
And Skip behind 30 seconds on audio player screen
And Tap pause button on audio player screen
Then Play button is present on audio player screen
And Playback has been moved behind by 30 seconds from 'timeBehind' and 'chapterTimeKey' seconds on audio player screen
Expand Down Expand Up @@ -137,7 +137,7 @@ Feature: Audiobooks in A1QA library
Then Check that book contains LISTEN action button on Book details screen
When Click LISTEN action button on Book details screen
Then Audio player screen of book 'bookInfo' is opened
And The speed by default is 1.0
And The speed by default is "1.0"X
When Open playback speed on audio player screen
And Close playback speed screen
Then Play button is present on audio player screen
Expand Down
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
16 changes: 9 additions & 7 deletions src/test/java/features/Search.feature
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,16 @@ Feature: Search module
When Close welcome screen
Then Add library screen is opened
When Add library "LYRASIS Reads" on Add library screen
And Wait for 3 seconds
And Open search modal
And Search for word <word> and save as 'info' on Catalog books screen
Then Books contain word 'info' on Catalog books screen

Scenarios:
| word |
| cat |
| a |
| 1 |
| word |
| in |
| a |
| 0 |

@tier2
Scenario Outline: Find a book with name in different font cases in LYRASIS Reads
Expand All @@ -165,9 +166,9 @@ Feature: Search module

Scenarios:
|word |
| silk road |
| SILK ROAD |
| SiLk rOaD |
| the silk road |
| THE SILK ROAD |
| ThE SiLk rOaD |

@tier2
Scenario Outline: Enter invalid data in book name in LYRASIS Reads
Expand All @@ -176,6 +177,7 @@ Feature: Search module
When Close welcome screen
Then Add library screen is opened
When Add library "LYRASIS Reads" on Add library screen
And Wait for 3 seconds
And Open search modal
And Search for word <data> and save as 'info' on Catalog books screen
Then There is no results on Catalog books 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
2 changes: 1 addition & 1 deletion src/test/java/screens/SortOptionsScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class SortOptionsScreen extends Screen {

private final IButton btnSortBy = getElementFactory().getButton(LocatorUtils.getLocator(
new AndroidLocator(By.xpath("//android.widget.HorizontalScrollView/android.widget.LinearLayout/android.widget.Button[2]")),
new AndroidLocator(By.xpath("//android.widget.HorizontalScrollView/android.widget.LinearLayout/android.widget.Button")),
new IosLocator(By.xpath("//XCUIElementTypeStaticText[@name=\"Sort By:\"]/following-sibling::XCUIElementTypeButton"))), "Sort by button");
private final IButton btnAvailability = getElementFactory().getButton(LocatorUtils.getLocator(
new AndroidLocator(By.xpath("//*[contains(@resource-id,\"feedHeaderFacets\")]/android.widget.Button[1]")),
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/screens/TutorialScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TutorialScreen extends Screen {

private final IButton btnCloseTutorial = getElementFactory().getButton(LocatorUtils.getLocator(
new AndroidLocator(By.xpath("//android.widget.ImageView[contains(@resource-id, \"skip_button\")]")),
new IosLocator(By.xpath("//XCUIElementTypeButton"))), "Close tutorial btn");
new IosLocator(By.xpath("//XCUIElementTypeButton[@name=\"Close\"]"))), "Close tutorial btn");
private final ILabel lblPage = getElementFactory().getLabel(LocatorUtils.getLocator(
new AndroidLocator(By.xpath("//android.widget.ImageView[@content-desc=\"Tutorial page\"]")),
new IosLocator(By.xpath("//XCUIElementTypeWindow"))), "Page label");
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/screens/epub/NavigationBarScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public class NavigationBarScreen extends Screen {
new AndroidLocator(By.xpath("//android.widget.Button[contains(@resource-id,\"readerMenuTOC\")]")),
new IosLocator(By.xpath("//XCUIElementTypeNavigationBar/XCUIElementTypeButton[@name=\"Table of contents and bookmarks\"]"))), "TOC button");
private final IButton btnAddBookmark = getElementFactory().getButton(LocatorUtils.getLocator(
new AndroidLocator(By.xpath("//android.widget.TextView[@content-desc=\"Create a bookmark for the current page\"]")),
new AndroidLocator(By.id("readerMenuAddBookmark")),
new IosLocator(By.xpath("//XCUIElementTypeNavigationBar/XCUIElementTypeButton[@name=\"Add Bookmark\"]"))), "Add Bookmark button");
private final IButton btnDeleteBookmark = getElementFactory().getButton(LocatorUtils.getLocator(
new AndroidLocator(By.xpath("//android.widget.TextView[@content-desc=\"Delete the bookmark for the current page\"]")),
new AndroidLocator(By.xpath("//android.widget.TextView[contains(@content-desc,\"Delete the bookmark\")]")),
new IosLocator(By.xpath("//XCUIElementTypeNavigationBar/XCUIElementTypeButton[@name=\"Remove Bookmark\"]"))), "Delete bookmark button");
private final IButton btnFontSettings = getElementFactory().getButton(LocatorUtils.getLocator(
new AndroidLocator(By.xpath("//android.widget.TextView[contains(@resource-id,\"readerMenuSettings\")]")),
Expand Down Expand Up @@ -48,7 +48,7 @@ public void tapAddBookmarkButton() {
}

public boolean isBookmarkDisplayed() {
return btnDeleteBookmark.state().isDisplayed();
return btnDeleteBookmark.state().waitForDisplayed();
}

public void tapDeleteBookmarkButton() {
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 096ea5f

Please sign in to comment.