Skip to content

Commit

Permalink
Merge pull request #13 from ThePalaceProject/refactoring
Browse files Browse the repository at this point in the history
Refactoring alerts and logger
  • Loading branch information
AEkaterina authored Oct 9, 2023
2 parents d4eb7ec + cd8cada commit 4d85400
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 36 deletions.
50 changes: 25 additions & 25 deletions src/test/java/features/BookDetailView.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Feature: Book detail view screen

@tier2
@palace
Scenario Outline: Check of a book title and author in LYRASIS Reads
When Close tutorial screen
Then Welcome screen is opened
Expand Down Expand Up @@ -28,7 +28,7 @@ Feature: Book detail view screen
| Biblioboard | EBOOK | eBooks |
| Biblioboard | AUDIOBOOK | Audiobooks |

@tier2
@palace
Scenario Outline: Check of a book format in LYRASIS Reads
When Close tutorial screen
Then Welcome screen is opened
Expand All @@ -46,16 +46,16 @@ Feature: Book detail view screen
And Book format in Information section is '<format>' on Book details screen
Scenarios:
| distributor | bookType | tabName | format |
| Bibliotheca | EBOOK | eBooks | ePub |
| Bibliotheca | EBOOK | eBooks | eBook |
| Bibliotheca | AUDIOBOOK | Audiobooks | Audiobook |
| Axis 360 | EBOOK | eBooks | ePub |
| Axis 360 | EBOOK | eBooks | eBook |
| Axis 360 | AUDIOBOOK | Audiobooks | Audiobook |
| Palace Marketplace | EBOOK | eBooks | ePub |
| Palace Marketplace | EBOOK | eBooks | eBook |
| Palace Marketplace | AUDIOBOOK | Audiobooks | Audiobook |
| Biblioboard | EBOOK | eBooks | PDF |
| Biblioboard | AUDIOBOOK | Audiobooks | Audiobook |

@tier2
@palace
Scenario Outline: Check of a "More..." button in Description section in LYRASIS Reads
When Close tutorial screen
Then Welcome screen is opened
Expand Down Expand Up @@ -83,7 +83,7 @@ Feature: Book detail view screen
| Biblioboard | EBOOK | eBooks |
| Biblioboard | AUDIOBOOK | Audiobooks |

@tier2
@palace
Scenario Outline: Check fields in Information section in LYRASIS Reads
When Close tutorial screen
Then Welcome screen is opened
Expand Down Expand Up @@ -112,14 +112,14 @@ Feature: Book detail view screen
| Biblioboard | EBOOK | eBooks |
| Biblioboard | AUDIOBOOK | Audiobooks |

@tier2
@palace
Scenario Outline: Check related books section in LYRASIS
When Close tutorial screen
Then Welcome screen is opened
When Close welcome screen
Then Add library screen is opened
When Add library "LYRASIS Reads" on Add library screen
Then Library "LERASIS Reads" is opened on Libraries screen
Then Library "LYRASIS Reads" is opened on Libraries screen
When Open Catalog
And Open search modal
And Search 'available' book of distributor '<distributor>' and bookType '<bookType>' and save as 'bookNameInfo'
Expand Down Expand Up @@ -171,7 +171,7 @@ Feature: Book detail view screen
# | Biblioboard | EBOOK | eBooks |
# | Biblioboard | AUDIOBOOK | Audiobooks |

@tier2
@palace
Scenario: Check of a book title and author in Palace Bookshelf
When Close tutorial screen
Then Welcome screen is opened
Expand All @@ -187,7 +187,7 @@ Feature: Book detail view screen
And Book 'bookInfo' has correct title and author name on Book details screen
And The book cover is displayed on Book details screen

@tier2
@palace
Scenario: Check of a "More..." button in Description section in Palace Bookshelf
When Close tutorial screen
Then Welcome screen is opened
Expand All @@ -203,7 +203,7 @@ Feature: Book detail view screen
And Description is not empty on Book details screen
And Button More in Description is available on Book details screen

@tier2
@palace
Scenario: Check fields in Information section in Palace Bookshelf
When Close tutorial screen
Then Welcome screen is opened
Expand All @@ -218,7 +218,7 @@ Feature: Book detail view screen
Then Book 'bookInfo' is opened on book details screen
And Publisher and Categories in Information section are correct on book details screen

@tier2
@palace
Scenario: Check related books section in Palace Bookshelf
When Close tutorial screen
Then Welcome screen is opened
Expand Down Expand Up @@ -253,7 +253,7 @@ Feature: Book detail view screen
# When I sort books by TITLE
# Then Books are sorted by Title ascending

@tier2
@palace
Scenario: Check of a book title and author in Overdrive
When Close tutorial screen
Then Welcome screen is opened
Expand All @@ -274,7 +274,7 @@ Feature: Book detail view screen
And Book 'bookInfo' has correct title and author name on Book details screen
And The book cover is displayed on Book details screen

@tier2
@palace
Scenario: Check of a "More..." button in Description section in Overdrive
When Close tutorial screen
Then Welcome screen is opened
Expand All @@ -295,7 +295,7 @@ Feature: Book detail view screen
And Description is not empty on Book details screen
And Button More in Description is available on Book details screen

@tier2
@palace
Scenario: Check fields in Information section in Overdrive
When Close tutorial screen
Then Welcome screen is opened
Expand All @@ -316,7 +316,7 @@ Feature: Book detail view screen
And Publisher and Categories in Information section are correct on book details screen
And Distributor is equal to 'Overdrive' on book details screen

@tier2
@palace
Scenario: Check related books section in Overdrive
When Close tutorial screen
Then Welcome screen is opened
Expand All @@ -338,7 +338,7 @@ Feature: Book detail view screen
And There is a list of related books on book details screen
And More button in related books section is available on book details screen

@tier2
@palace
Scenario: Get button: Check of availability of required interface elements
When Close tutorial screen
Then Welcome screen is opened
Expand All @@ -354,7 +354,7 @@ Feature: Book detail view screen
Then Sing in screen is opened
And All fields and links are displayed on Sign in screen

@tier2 @exclude_android
@palace @exclude_android
Scenario: Get button: check of Library Card field
When Close tutorial screen
Then Welcome screen is opened
Expand All @@ -370,7 +370,7 @@ Feature: Book detail view screen
Then Sing in screen is opened
And There is a placeholder Library Card in the Library Card field on Sign in screen

@tier2 @exclude_android
@palace @exclude_android
Scenario: Get button: check of Password field
When Close tutorial screen
Then Welcome screen is opened
Expand All @@ -386,7 +386,7 @@ Feature: Book detail view screen
Then Sing in screen is opened
And There is a placeholder "Password" in the Password field on Sign in screen

@tier2
@palace
Scenario: Get: Sign in: Check of loging in with leaving the Library Card field empty
When Close tutorial screen
Then Welcome screen is opened
Expand All @@ -403,7 +403,7 @@ Feature: Book detail view screen
When Enter a valid Password for "LYRASIS Reads" library on Sign in screen
Then Sign in button is disabled on Sign in screen

@tier2
@palace
Scenario: Get: Sign in: Check of loging in with leaving the Password field empty
When Close tutorial screen
Then Welcome screen is opened
Expand All @@ -420,7 +420,7 @@ Feature: Book detail view screen
When Enter a valid Library card "01230000000098" on Sign in screen
Then Sign in button is disabled on Sign in screen

@tier2
@palace
Scenario: Get: Sign in: Library card: Check that the field allows you to edit the data
When Close tutorial screen
Then Welcome screen is opened
Expand All @@ -438,7 +438,7 @@ Feature: Book detail view screen
And Edit data by adding "22" in Library card field and save it as 'newLibraryCard' on sign in screen
Then There is a placeholder 'newLibraryCard' in the Library Card field on Sign in screen

@tier2
@palace
Scenario Outline: Get: Sign in: Library card: Check of less than minimum allowed or more than maximum characters
When Close tutorial screen
Then Welcome screen is opened
Expand All @@ -462,7 +462,7 @@ Feature: Book detail view screen
| 13 |
| 15 |

@tier2
@palace
Scenario: Get: Log in: Library card: Check that the field doesn't allow characters except numbers
When Close tutorial screen
Then Welcome screen is opened
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/features/MyBooks.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Feature: My books module

@tier2
@palace
Scenario: Check of added books in Palace Bookshelf
When Close tutorial screen
Then Welcome screen is opened
Expand Down Expand Up @@ -40,7 +40,7 @@ Feature: My books module
When Sort books by TITLE
Then Books are sorted by Title ascending on books screen

@logout @returnBooks @trier1
@logout @returnBooks @run
Scenario: Return book from My Books in LYRASIS Reads
When Close tutorial screen
Then Welcome screen is opened
Expand All @@ -63,7 +63,7 @@ Feature: My books module
And Open Books
Then EBOOK book with GET action button and 'bookInfo' bookInfo is not present on books screen

@logout @returnBooks @tier1
@logout @returnBooks @run
Scenario: Get a book from Book Detail View and Return from Books in LYRASIS Reads
When Close tutorial screen
Then Welcome screen is opened
Expand All @@ -88,7 +88,7 @@ Feature: My books module
And Wait for 10 seconds
Then EBOOK book with READ action button and 'bookInfo' bookInfo is not present on books screen

@logout @returnBooks @tier1
@logout @returnBooks @run
Scenario: Get a book from Subcategory List View and Return from Books in LYRASIS Reads
When Close tutorial screen
Then Welcome screen is opened
Expand Down Expand Up @@ -117,7 +117,7 @@ Feature: My books module
And Wait for 7 seconds
Then EBOOK book with READ action button and 'bookInfo' bookInfo is not present on books screen

@logout @returnBooks @tier1 @exclude_android
@logout @returnBooks @run @exclude_android
Scenario: Get a book from Subcategory List View and Return from Subcategory List View in LYRASIS Reads
When Close tutorial screen
Then Welcome screen is opened
Expand Down
54 changes: 54 additions & 0 deletions src/test/java/framework/utilities/Logger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package framework.utilities;

import aquality.appium.mobile.application.AqualityServices;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.RollingFileAppender;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class Logger {

private static ThreadLocal<Logger> instance = ThreadLocal.withInitial(Logger::new);
private RollingFileAppender scenarioAppender;

private Logger() {
}

public static Logger getInstance() {
return instance.get();
}

public void upload() {
instance.remove();
}


public void createAppender(String name) {
PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} %-5p - %m%n");
try {
scenarioAppender = new RollingFileAppender(
layout, String.format("%s%s.log", "target/log/", name.replace(",", "").replace(" ", "_")), false);
AqualityServices.getLogger().addAppender(scenarioAppender);
} catch (IOException exception) {
AqualityServices.getLogger().error("Failed to add appender !! " + exception.getMessage());
}
}

public byte[] getLoggerInfoBytes() {
byte[] data = new byte[0];
try {
data = Files.readAllBytes(Paths.get(scenarioAppender.getFile()));
} catch (IOException exception) {
AqualityServices.getLogger().error(exception.toString());
}
return data;
}

public void removeAppender() {
if (scenarioAppender != null) {
AqualityServices.getLogger().removeAppender(scenarioAppender);
}
}
}
69 changes: 69 additions & 0 deletions src/test/java/hooks/LoggerHooks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package hooks;

import aquality.appium.mobile.application.AqualityServices;
import framework.utilities.Logger;
import io.cucumber.core.backend.TestCaseState;
import io.cucumber.java.*;
import io.cucumber.plugin.event.PickleStepTestStep;
import io.cucumber.plugin.event.TestCase;

import java.lang.reflect.Field;
import java.util.List;
import java.util.stream.Collectors;

import static java.lang.String.format;

public class LoggerHooks {

private static ThreadLocal<Integer> counter = ThreadLocal.withInitial(() -> 0);

@Before(order = 0)
public void startScenarioLogger(Scenario scenario) {
Logger logger = Logger.getInstance();
AqualityServices.getLogger().info("isLoggerNullBeforeAnnotation-"+logger);
logger.createAppender(scenario.getName());
AqualityServices.getLogger().info(format("Scenario '%s' start", scenario.getName()));
AqualityServices.getLogger().info("Session id - " + AqualityServices.getApplication().getDriver().getSessionId().toString());
}

@After(order = 2)
public void addLogToScenario(Scenario scenario) {
Logger logger = Logger.getInstance();
AqualityServices.getLogger().info("isLoggerNullAfterAnnotation-"+logger);
byte[] data = logger.getLoggerInfoBytes();
AqualityServices.getLogger().info(format("Scenario '%s' end", scenario.getName()));
scenario.attach(data, "text/plain", "log.txt");
Logger.getInstance().removeAppender();
}

@BeforeStep
public void getStepName(Scenario scenario) throws Exception {
Field delegateField = scenario.getClass().getDeclaredField("delegate");
delegateField.setAccessible(true);
TestCaseState testCaseState = (TestCaseState) delegateField.get(scenario);

Field testCaseField = testCaseState.getClass().getDeclaredField("testCase");
testCaseField.setAccessible(true);
TestCase r1 = (TestCase) testCaseField.get(testCaseState);

List<PickleStepTestStep> stepDefinitions = r1.getTestSteps()
.stream()
.filter(x -> x instanceof PickleStepTestStep)
.map(x -> (PickleStepTestStep) x)
.collect(Collectors.toList());

PickleStepTestStep currentStep = stepDefinitions.get(counter.get());

AqualityServices.getLogger().info(String.format("Step %d - %s", counter.get(), currentStep.getStep().getText()));
}

@AfterStep
public void afterStep(Scenario scenario) {
counter.set(counter.get() + 1);
}

@After
public void afterTest(Scenario scenario) {
counter.set(0);
}
}
6 changes: 3 additions & 3 deletions src/test/java/screens/AccountScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
public class AccountScreen extends Screen {

private final ITextBox txbCard = getElementFactory().getTextBox(LocatorUtils.getLocator(
new AndroidLocator(By.id("authBasicUserField")),
new AndroidLocator(By.id("authBasicTokenUserField")),
new IosLocator(By.xpath("//XCUIElementTypeTable/XCUIElementTypeCell[1]/XCUIElementTypeTextField"))), "Library card text box");
private final ITextBox txbPassword = getElementFactory().getTextBox(LocatorUtils.getLocator(
new AndroidLocator(By.id("authBasicPassField")),
new AndroidLocator(By.id("authBasicTokenPassField")),
new IosLocator(By.xpath("//XCUIElementTypeTable/XCUIElementTypeCell[2]/XCUIElementTypeSecureTextField"))), "Password text box");
private final IButton btnSignIn = getElementFactory().getButton(LocatorUtils.getLocator(
new AndroidLocator(By.xpath(String.format(SIGN_IN_BTN_LOCATOR_ANDROID, AccountScreenSignInStatus.SIGN_IN.getDefaultLocalizedValue()))),
Expand Down Expand Up @@ -66,7 +66,7 @@ public class AccountScreen extends Screen {
new AndroidLocator(By.xpath("")),
new IosLocator(By.xpath("//XCUIElementTypeStaticText[@name=\"Advanced\"]"))), "Advanced button");

private static final String BTN_SIGN_IN_ID_ANDROID = "authBasicLogin";
private static final String BTN_SIGN_IN_ID_ANDROID = "authBasicTokenLogin";
private static final String SIGN_IN_BTN_LOCATOR_ANDROID = "//*[contains(@resource-id,\"" + BTN_SIGN_IN_ID_ANDROID + "\") and @text=\"%1$s\"]";
private static final String LIBRARY_NAME_LOCATOR_ANDROID = "accountCellTitle";

Expand Down
Loading

0 comments on commit 4d85400

Please sign in to comment.