Skip to content

Commit

Permalink
Merge pull request #16 from ThePalaceProject/refactoring
Browse files Browse the repository at this point in the history
updated settings, added screenshot hook
  • Loading branch information
AEkaterina authored Oct 16, 2023
2 parents 97f5edb + 23e78bd commit b6c87e3
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/test/java/features/Samples.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Feature: Check of View Sample
Then Library "A1QA Test Library" is opened on Libraries screen
When Open Catalog
And Open search modal
And Search for "Alice in Wonderland" and save bookName as 'bookNameInfo'
And Search for "Writing Wild" and save bookName as 'bookNameInfo'
And Switch to "eBooks" catalog tab
And Open EBOOK book with GET action button and 'bookNameInfo' bookName on Catalog books screen and save book as 'bookInfo'
And Click VIEW_SAMPLE action button on Book details screen
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/features/Settings.feature
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Feature: Check sections from settings screen

@tier2 @exclude_android
@tier2
Scenario: About Palace
When Close tutorial screen
Then Welcome screen is opened
When Close welcome screen
Then Add library screen is opened
When Add library "Palace Bookshelf" on Add library screen
And Open Settings
And Open About Palace on settings screen
Then About Palace screen is opened
And Open About App on settings screen
Then About App screen is opened

@tier2
Scenario: Privacy Policy
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/framework/utilities/ScreenshotUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package framework.utilities;

import aquality.appium.mobile.application.AqualityServices;
import org.openqa.selenium.OutputType;

public class ScreenshotUtils {
public static byte[] getScreenshot() {
AqualityServices.getApplication().getDriver().getPageSource();
return AqualityServices.getApplication().getDriver().getScreenshotAs(OutputType.BYTES);
}
}
12 changes: 12 additions & 0 deletions src/test/java/hooks/CredentialsHooks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package hooks;

import framework.configuration.ConfigurationStorage;
import io.cucumber.java.After;
import io.cucumber.java.Scenario;

public class CredentialsHooks {
@After(order = 2)
public void unlockCredentials(Scenario scenario) {
ConfigurationStorage.unlockCredentials();
}
}
30 changes: 30 additions & 0 deletions src/test/java/hooks/ScreenshotHooks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package hooks;

import aquality.appium.mobile.application.AqualityServices;
import com.google.inject.Inject;
import constants.keysForContext.ScenarioContextKey;
import framework.utilities.ScreenshotUtils;
import framework.utilities.ScenarioContext;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.Scenario;

public class ScreenshotHooks {
private ScenarioContext context;

@Inject
public ScreenshotHooks(ScenarioContext context) {
this.context = context;
}

@Before
public void startScenarioLogger(Scenario scenario) {
context.add(ScenarioContextKey.SCENARIO_KEY, scenario);
}

@After(order = 4)
public void takeScreenshot(Scenario scenario) {
AqualityServices.getLogger().info("Taking screenshot");
scenario.attach(ScreenshotUtils.getScreenshot(), "image/png", "screenshot.png");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import models.IosLocator;
import org.openqa.selenium.By;

public class AboutPalaceScreen extends Screen {
public class AboutAppScreen extends Screen {

private final ILabel lblAboutPalace = getElementFactory().getLabel(LocatorUtils.getLocator(
new AndroidLocator(By.xpath("//android.widget.Image[@text=\"The Palace Project\"]")),
new IosLocator(By.xpath("//XCUIElementTypeImage[@name=\"The Palace Project\"]"))), "About palace label");

public AboutPalaceScreen() {
public AboutAppScreen() {
super(LocatorUtils.getLocator(
new AndroidLocator(By.xpath("//android.widget.TextView[@text=\"About Palace\"]")),
new IosLocator(By.xpath("//XCUIElementTypeNavigationBar[@name=\"About Palace\"]"))), "About Palace screen");
Expand Down
26 changes: 25 additions & 1 deletion src/test/java/screens/BookDetailsScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class BookDetailsScreen extends Screen {
new IosLocator(By.xpath("//XCUIElementTypeScrollView/XCUIElementTypeOther[1]//XCUIElementTypeStaticText[1]"))), "Book title label");
private final ILabel lblBookAuthor = getElementFactory().getLabel(LocatorUtils.getLocator(
new AndroidLocator(By.id("bookDetailAuthors")),
new IosLocator(By.xpath("//XCUIElementTypeStaticText[@name=\"Description\"]/preceding-sibling::XCUIElementTypeStaticText"))), "Book author label");
new IosLocator(By.xpath("//XCUIElementTypeStaticText[@name=\"Description\"]/preceding-sibling::XCUIElementTypeStaticText[2]"))), "Book author label");
private final ILabel lblBookCover = getElementFactory().getLabel(LocatorUtils.getLocator(
new AndroidLocator(By.xpath("//android.widget.ImageView[contains(@resource-id, \"bookDetailCoverImage\")]")),
new IosLocator(By.xpath("//XCUIElementTypeOther//XCUIElementTypeImage[1]"))), "Book cover");
Expand Down Expand Up @@ -55,10 +55,14 @@ public class BookDetailsScreen extends Screen {
new AndroidLocator(By.xpath("//android.widget.FrameLayout//android.widget.TextView[@text=\"More…\"]")),
new IosLocator(By.xpath("//XCUIElementTypeTable//XCUIElementTypeButton[@name=\"More...\"]"))), "More button in related books section");

private static final String BOOK_NAME_LOC_ANDROID = "//android.widget.TextView[@text=\"%s\"]";
private static final String AUTHOR_NAME_LOC_ANDROID = "//android.widget.TextView[@text=\"%s\"]";
private static final String BOOK_ACTION_BUTTON_LOC_ANDROID = "//android.widget.Button[@text=\"%s\"]";
private static final String AUTHOR_IN_RELATED_BOOKS_LOC_ANDROID = "//android.widget.FrameLayout//android.widget.TextView[@text=\"%s\"]";
private static final String LIST_OF_RELATED_BOOKS_LOC_ANDROID = "//androidx.recyclerview.widget.RecyclerView[contains(@resource-id, \"feedLaneCoversScroll\")]/android.widget.LinearLayout";

private static final String BOOK_NAME_LOC_IOS = "//XCUIElementTypeStaticText[@name=\"%s\"]";
private static final String AUTHOR_NAME_LOC_IOS = "//XCUIElementTypeStaticText[@name=\"%s\"]";
private static final String BOOK_ACTION_BUTTON_LOC_IOS = "//XCUIElementTypeButton/XCUIElementTypeStaticText[@name=\"%s\"]";
private static final String AUTHOR_IN_RELATED_BOOKS_LOC_IOS = "//XCUIElementTypeTable//XCUIElementTypeButton[@name=\"%s\"]";
private static final String LIST_OF_RELATED_BOOKS_LOC_IOS = "//XCUIElementTypeTable/XCUIElementTypeCell/XCUIElementTypeButton";
Expand All @@ -70,11 +74,31 @@ public BookDetailsScreen() {
}

public CatalogBookModel getBookInfo() {

System.out.println("title: " + lblBookTitle.getText());
System.out.println("author: " + lblBookAuthor.getText());

return new CatalogBookModel()
.setTitle(lblBookTitle.getText())
.setAuthor(lblBookAuthor.getText());
}

public boolean isBookTitleDisplayed(String bookName) {
ILabel lblBookNameIos = getElementFactory().getLabel(LocatorUtils.getLocator(
new AndroidLocator(By.xpath(String.format(BOOK_NAME_LOC_ANDROID, bookName))),
new IosLocator(By.xpath(String.format(BOOK_NAME_LOC_IOS, bookName)))), "Book name label");
return lblBookNameIos.state().waitForDisplayed();
}

public boolean isAuthorNameDisplayed(String authorName) {
ILabel lblAuthor = getElementFactory().getLabel(LocatorUtils.getLocator(
new AndroidLocator(By.xpath(String.format(AUTHOR_NAME_LOC_ANDROID, authorName))),
new IosLocator(By.xpath(String.format(AUTHOR_NAME_LOC_IOS, authorName)))), "Author name label");
System.out.println(lblAuthor.getText());

return lblAuthor.state().waitForDisplayed();
}

public boolean isBookHasCover() {
return lblBookCover.state().isExist();
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/screens/SettingsScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public class SettingsScreen extends Screen {
new AndroidLocator(By.xpath("//android.widget.TextView")),
new IosLocator(By.xpath("//XCUIElementTypeNavigationBar"))), "Settings label");
private final IButton btnAboutPalace = getElementFactory().getButton(LocatorUtils.getLocator(
new AndroidLocator(By.xpath("")),
new IosLocator(By.xpath("//XCUIElementTypeButton[@name=\"About Palace\"]"))), "About Palace button");
new AndroidLocator(By.xpath("//android.widget.TextView[@text=\"About Palace\"]")),
new IosLocator(By.xpath("//XCUIElementTypeButton[@name=\"About App\"]"))), "About App button");
private final IButton btnPrivacyPolicy = getElementFactory().getButton(LocatorUtils.getLocator(
new AndroidLocator(By.xpath("//android.widget.TextView[@text=\"Privacy Policy\"]")),
new IosLocator(By.xpath("//XCUIElementTypeButton[@name=\"Privacy Policy\"]"))), "Privacy Policy button");
Expand Down Expand Up @@ -61,7 +61,7 @@ public boolean isScreenOpened() {
return lblSettings.state().waitForDisplayed();
}

public void openAboutPalace() {
public void openAboutApp() {
btnAboutPalace.click();
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/screens/epub/NavigationBarScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class NavigationBarScreen extends Screen {

private final IButton btnTOC = getElementFactory().getButton(LocatorUtils.getLocator(
new AndroidLocator(By.xpath("//android.widget.Button[contains(@resource-id,\"readerMenuTOC\")]")),
new IosLocator(By.xpath("//XCUIElementTypeNavigationBar/XCUIElementTypeButton[2]"))), "TOC button");
new IosLocator(By.xpath("//XCUIElementTypeNavigationBar/XCUIElementTypeButton[3]"))), "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 IosLocator(By.xpath("//XCUIElementTypeNavigationBar/XCUIElementTypeButton[@name=\"Add Bookmark\"]"))), "Add Bookmark button");
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/stepdefinitions/BookDetailsSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public BookDetailsSteps(ScenarioContext context) {
public void isBookOpened(String bookInfoKey) {
CatalogBookModel bookModel = context.get(bookInfoKey);
SoftAssertions softAssertions = new SoftAssertions();
softAssertions.assertThat(bookDetailsScreen.getBookInfo().getTitle())
softAssertions.assertThat(bookDetailsScreen.isBookTitleDisplayed(bookModel.getTitle().replace(". Audiobook.", "")))
.as("Expected book is not opened. Book title is wrong")
.isEqualTo(bookModel.getTitle().replace(". Audiobook.", ""));
softAssertions.assertThat(bookDetailsScreen.getBookInfo().getAuthor())
.isTrue();
softAssertions.assertThat(bookDetailsScreen.isAuthorNameDisplayed(bookModel.getAuthor()))
.as("Expected book is not opened. Author is wrong")
.isEqualTo(bookModel.getAuthor());
.isTrue();
softAssertions.assertAll();
}

Expand Down
14 changes: 7 additions & 7 deletions src/test/java/stepdefinitions/SettingsSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class SettingsSteps {

private final MenuBarScreen menuBarScreen;
private final SettingsScreen settingsScreen;
private final AboutPalaceScreen aboutPalaceScreen;
private final AboutAppScreen aboutAppScreen;
private final PrivacyPolicyScreen privacyPolicyScreen;
private final UserAgreementScreen userAgreementScreen;
private final SoftwareLicensesScreen softwareLicensesScreen;
Expand All @@ -21,7 +21,7 @@ public class SettingsSteps {
public SettingsSteps(){
menuBarScreen = new MenuBarScreen();
settingsScreen = new SettingsScreen();
aboutPalaceScreen = new AboutPalaceScreen();
aboutAppScreen = new AboutAppScreen();
privacyPolicyScreen = new PrivacyPolicyScreen();
userAgreementScreen = new UserAgreementScreen();
softwareLicensesScreen = new SoftwareLicensesScreen();
Expand All @@ -47,14 +47,14 @@ public void openLibrary(String libraryName) {
settingsScreen.openLibrary(libraryName);
}

@When("Open About Palace on settings screen")
@When("Open About App on settings screen")
public void openAboutPalace() {
settingsScreen.openAboutPalace();
settingsScreen.openAboutApp();
}

@Then("About Palace screen is opened")
public void aboutPalaceIsPresent() {
aboutPalaceScreen.isOpened();
@Then("About App screen is opened")
public void aboutAppIsPresent() {
aboutAppScreen.isOpened();
}

@When("Open Privacy Policy on settings screen")
Expand Down

0 comments on commit b6c87e3

Please sign in to comment.