diff --git a/src/test/java/features/Samples.feature b/src/test/java/features/Samples.feature index d2e4b55..b045d22 100644 --- a/src/test/java/features/Samples.feature +++ b/src/test/java/features/Samples.feature @@ -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 diff --git a/src/test/java/features/Settings.feature b/src/test/java/features/Settings.feature index b6e5abc..c53daf0 100644 --- a/src/test/java/features/Settings.feature +++ b/src/test/java/features/Settings.feature @@ -1,6 +1,6 @@ Feature: Check sections from settings screen - @tier2 @exclude_android + @tier2 Scenario: About Palace When Close tutorial screen Then Welcome screen is opened @@ -8,8 +8,8 @@ Feature: Check sections from settings 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 diff --git a/src/test/java/framework/utilities/ScreenshotUtils.java b/src/test/java/framework/utilities/ScreenshotUtils.java new file mode 100644 index 0000000..d622fdf --- /dev/null +++ b/src/test/java/framework/utilities/ScreenshotUtils.java @@ -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); + } +} diff --git a/src/test/java/hooks/CredentialsHooks.java b/src/test/java/hooks/CredentialsHooks.java new file mode 100644 index 0000000..dd34dde --- /dev/null +++ b/src/test/java/hooks/CredentialsHooks.java @@ -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(); + } +} diff --git a/src/test/java/hooks/ScreenshotHooks.java b/src/test/java/hooks/ScreenshotHooks.java new file mode 100644 index 0000000..61bbeba --- /dev/null +++ b/src/test/java/hooks/ScreenshotHooks.java @@ -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"); + } +} diff --git a/src/test/java/screens/AboutPalaceScreen.java b/src/test/java/screens/AboutAppScreen.java similarity index 92% rename from src/test/java/screens/AboutPalaceScreen.java rename to src/test/java/screens/AboutAppScreen.java index ff443f7..903c672 100644 --- a/src/test/java/screens/AboutPalaceScreen.java +++ b/src/test/java/screens/AboutAppScreen.java @@ -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"); diff --git a/src/test/java/screens/BookDetailsScreen.java b/src/test/java/screens/BookDetailsScreen.java index 6846315..021d9a0 100644 --- a/src/test/java/screens/BookDetailsScreen.java +++ b/src/test/java/screens/BookDetailsScreen.java @@ -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"); @@ -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"; @@ -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(); } diff --git a/src/test/java/screens/SettingsScreen.java b/src/test/java/screens/SettingsScreen.java index 8ac2d39..a213163 100644 --- a/src/test/java/screens/SettingsScreen.java +++ b/src/test/java/screens/SettingsScreen.java @@ -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"); @@ -61,7 +61,7 @@ public boolean isScreenOpened() { return lblSettings.state().waitForDisplayed(); } - public void openAboutPalace() { + public void openAboutApp() { btnAboutPalace.click(); } diff --git a/src/test/java/screens/epub/NavigationBarScreen.java b/src/test/java/screens/epub/NavigationBarScreen.java index 3bad78f..9907a38 100644 --- a/src/test/java/screens/epub/NavigationBarScreen.java +++ b/src/test/java/screens/epub/NavigationBarScreen.java @@ -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"); diff --git a/src/test/java/stepdefinitions/BookDetailsSteps.java b/src/test/java/stepdefinitions/BookDetailsSteps.java index 0de45b5..e875874 100644 --- a/src/test/java/stepdefinitions/BookDetailsSteps.java +++ b/src/test/java/stepdefinitions/BookDetailsSteps.java @@ -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(); } diff --git a/src/test/java/stepdefinitions/SettingsSteps.java b/src/test/java/stepdefinitions/SettingsSteps.java index 7343432..49c99e9 100644 --- a/src/test/java/stepdefinitions/SettingsSteps.java +++ b/src/test/java/stepdefinitions/SettingsSteps.java @@ -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; @@ -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(); @@ -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")