Skip to content

Commit

Permalink
feat(java): ✨ added locator alias name for better logging (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
WasiqB committed Oct 25, 2022
1 parent 5534a11 commit 1d87358
Show file tree
Hide file tree
Showing 26 changed files with 192 additions and 149 deletions.
20 changes: 8 additions & 12 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,27 @@ updates:
- package-ecosystem: 'npm'
directory: '/'
target-branch: 'develop'
versioning-strategy: widen
schedule:
interval: 'weekly'
day: 'saturday'
interval: 'daily'
versioning-strategy: increase

- package-ecosystem: 'maven'
directory: '/core-java'
target-branch: 'develop'
versioning-strategy: widen
schedule:
interval: 'weekly'
day: 'saturday'
interval: 'daily'
versioning-strategy: increase

- package-ecosystem: 'maven'
directory: '/sample-tests'
target-branch: 'develop'
versioning-strategy: widen
schedule:
interval: 'weekly'
day: 'saturday'
interval: 'daily'
versioning-strategy: increase

- package-ecosystem: 'github-actions'
directory: '/'
target-branch: 'develop'
versioning-strategy: increase-if-necessary
schedule:
interval: 'weekly'
day: 'saturday'
interval: 'daily'
versioning-strategy: increase
2 changes: 1 addition & 1 deletion core-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<url>https://github.com/WasiqBhamla/boyka-framework</url>

<properties>
<selenium-webdriver.version>4.5.0</selenium-webdriver.version>
<selenium-webdriver.version>4.5.3</selenium-webdriver.version>
<testng.version>7.6.1</testng.version>
<appium-java-client.version>8.2.0</appium-java-client.version>
<webdrivermanager.version>5.3.0</webdrivermanager.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public final class DropDownActions {
*/
public static void deselectAll (final Locator locator) {
LOGGER.traceEntry ();
LOGGER.info ("Deselecting element located by: {}", locator);
LOGGER.info ("Deselecting element located by: {}", locator.getName ());
performElementAction (e -> {
final var select = new Select (e);
if (!select.isMultiple ()) {
Expand All @@ -67,7 +67,7 @@ public static void deselectAll (final Locator locator) {
*/
public static void deselectByIndex (final Locator locator, final int index) {
LOGGER.traceEntry ();
LOGGER.info ("Deselecting element located by: {} by index: {}", locator, index);
LOGGER.info ("Deselecting element located by: {} by index: {}", locator.getName (), index);
performElementAction (e -> {
final var select = new Select (e);
if (!select.isMultiple ()) {
Expand All @@ -86,7 +86,7 @@ public static void deselectByIndex (final Locator locator, final int index) {
*/
public static void deselectByText (final Locator locator, final String text) {
LOGGER.traceEntry ();
LOGGER.info ("Deselecting element located by: {} by visible text: {}", locator, text);
LOGGER.info ("Deselecting element located by: {} by visible text: {}", locator.getName (), text);
performElementAction (e -> {
final var select = new Select (e);
if (!select.isMultiple ()) {
Expand All @@ -105,7 +105,7 @@ public static void deselectByText (final Locator locator, final String text) {
*/
public static void deselectByValue (final Locator locator, final String value) {
LOGGER.traceEntry ();
LOGGER.info ("Deselecting element located by: {} by value: {}", locator, value);
LOGGER.info ("Deselecting element located by: {} by value: {}", locator.getName (), value);
performElementAction (e -> {
final var select = new Select (e);
if (!select.isMultiple ()) {
Expand All @@ -124,7 +124,7 @@ public static void deselectByValue (final Locator locator, final String value) {
*/
public static void selectByIndex (final Locator locator, final int index) {
LOGGER.traceEntry ();
LOGGER.info ("Selecting element located by: {} by index: {}", locator, index);
LOGGER.info ("Selecting element located by: {} by index: {}", locator.getName (), index);
performElementAction (e -> {
final var select = new Select (e);
select.selectByIndex (index);
Expand All @@ -140,7 +140,7 @@ public static void selectByIndex (final Locator locator, final int index) {
*/
public static void selectByText (final Locator locator, final String text) {
LOGGER.traceEntry ();
LOGGER.info ("Selecting element located by: {} by text: {}", locator, text);
LOGGER.info ("Selecting element located by: {} by text: {}", locator.getName (), text);
performElementAction (e -> {
final var select = new Select (e);
select.selectByVisibleText (text);
Expand All @@ -156,7 +156,7 @@ public static void selectByText (final Locator locator, final String text) {
*/
public static void selectByValue (final Locator locator, final String value) {
LOGGER.traceEntry ();
LOGGER.info ("Selecting element located by: {} by value: {}", locator, value);
LOGGER.info ("Selecting element located by: {} by value: {}", locator.getName (), value);
performElementAction (e -> {
final var select = new Select (e);
select.selectByValue (value);
Expand All @@ -173,7 +173,7 @@ public static void selectByValue (final Locator locator, final String value) {
*/
public static String selectedItem (final Locator locator) {
LOGGER.traceEntry ();
LOGGER.info ("Getting selected option from element located by: {}", locator);
LOGGER.info ("Getting selected option from element located by: {}", locator.getName ());
return getElementAttribute (element -> {
final var select = new Select (element);
try {
Expand All @@ -194,7 +194,7 @@ public static String selectedItem (final Locator locator) {
*/
public static List<String> selectedItems (final Locator locator) {
LOGGER.traceEntry ();
LOGGER.info ("Getting all selected options from element located by: {}", locator);
LOGGER.info ("Getting all selected options from element located by: {}", locator.getName ());
return getElementAttribute (e -> {
final var select = new Select (e);
return select.getAllSelectedOptions ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public final class ElementActions {
*/
public static String attributeOf (final Locator locator, final String attribute) {
LOGGER.traceEntry ();
LOGGER.info ("Getting attribute: {} of element located by: {}", attribute, locator);
LOGGER.info ("Getting attribute: {} of element located by: {}", attribute, locator.getName ());
LOGGER.traceExit ();
return getElementAttribute (e -> e.getAttribute (attribute), locator);
}
Expand All @@ -55,7 +55,7 @@ public static String attributeOf (final Locator locator, final String attribute)
*/
public static void clear (final Locator locator) {
LOGGER.traceEntry ();
LOGGER.info ("Clearing element located by: {}", locator);
LOGGER.info ("Clearing element located by: {}", locator.getName ());
performElementAction (WebElement::clear, locator);
LOGGER.traceExit ();
}
Expand All @@ -69,7 +69,7 @@ public static void clear (final Locator locator) {
*/
public static boolean isDisplayed (final Locator locator) {
LOGGER.traceEntry ();
LOGGER.info ("Checking if element located by: {} is displayed", locator);
LOGGER.info ("Checking if element located by: {} is displayed", locator.getName ());
return LOGGER.traceExit (getElementAttribute (WebElement::isDisplayed, locator));
}

Expand All @@ -82,7 +82,7 @@ public static boolean isDisplayed (final Locator locator) {
*/
public static boolean isEnabled (final Locator locator) {
LOGGER.traceEntry ();
LOGGER.info ("Checking if element located by: {} is enabled", locator);
LOGGER.info ("Checking if element located by: {} is enabled", locator.getName ());
return LOGGER.traceExit (getElementAttribute (WebElement::isEnabled, locator));
}

Expand All @@ -95,7 +95,7 @@ public static boolean isEnabled (final Locator locator) {
*/
public static boolean isSelected (final Locator locator) {
LOGGER.traceEntry ();
LOGGER.info ("Checking if element located by: {} is selected", locator);
LOGGER.info ("Checking if element located by: {} is selected", locator.getName ());
return LOGGER.traceExit (getElementAttribute (WebElement::isSelected, locator));
}

Expand All @@ -109,7 +109,7 @@ public static boolean isSelected (final Locator locator) {
*/
public static String styleOf (final Locator locator, final String attribute) {
LOGGER.traceEntry ();
LOGGER.info ("Getting attribute: {} of element located by: {}", attribute, locator);
LOGGER.info ("Getting attribute: {} of element located by: {}", attribute, locator.getName ());
LOGGER.traceExit ();
return getElementAttribute (e -> e.getCssValue (attribute), locator);
}
Expand All @@ -121,7 +121,7 @@ public static String styleOf (final Locator locator, final String attribute) {
*/
public static void submit (final Locator locator) {
LOGGER.traceEntry ();
LOGGER.info ("Submitting element located by: {}", locator);
LOGGER.info ("Submitting element located by: {}", locator.getName ());
performElementAction (WebElement::submit, locator);
LOGGER.traceExit ();
}
Expand All @@ -135,7 +135,7 @@ public static void submit (final Locator locator) {
*/
public static String textOf (final Locator locator) {
LOGGER.traceEntry ();
LOGGER.info ("Getting text of element located by: {}", locator);
LOGGER.info ("Getting text of element located by: {}", locator.getName ());
return LOGGER.traceExit (getElementAttribute (WebElement::getText, locator));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public final class KeyboardActions {
*/
public static void appendText (final Locator locator, final String text) {
LOGGER.traceEntry ();
LOGGER.info ("Appending text {} to element {}", text, locator);
LOGGER.info ("Appending text {} to element {}", text, locator.getName ());
performElementAction (e -> e.sendKeys (text), locator);
LOGGER.traceExit ();
}
Expand All @@ -55,7 +55,7 @@ public static void appendText (final Locator locator, final String text) {
*/
public static void enterText (final Locator locator, final String text) {
LOGGER.traceEntry ();
LOGGER.info ("Entering text {} in element {}", text, locator);
LOGGER.info ("Entering text {} in element {}", text, locator.getName ());
clear (locator);
appendText (locator, text);
LOGGER.traceExit ();
Expand All @@ -69,7 +69,7 @@ public static void enterText (final Locator locator, final String text) {
*/
public static void pressKey (final Locator locator, final CharSequence... keys) {
LOGGER.traceEntry ();
stream (keys).forEach (key -> LOGGER.info ("Pressing key {} in element {}", key, locator));
stream (keys).forEach (key -> LOGGER.info ("Pressing key {} in element {}", key, locator.getName ()));
performElementAction (e -> e.sendKeys (chord (keys)), locator);
LOGGER.traceExit ();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final class MouseActions {
*/
public static void clickAndHold (final Locator locator) {
LOGGER.traceEntry ();
LOGGER.info ("Click and hold on element: {}", locator);
LOGGER.info ("Click and hold on element: {}", locator.getName ());
performElementAction (element -> {
final Actions actions = new Actions (getSession ().getDriver ());
actions.clickAndHold (element)
Expand All @@ -60,7 +60,7 @@ public static void clickAndHold (final Locator locator) {
*/
public static void clickOn (final Locator locator) {
LOGGER.traceEntry ();
LOGGER.info ("Clicking on element: {}", locator);
LOGGER.info ("Clicking on element: {}", locator.getName ());
performElementAction (WebElement::click, locator);
LOGGER.traceExit ();
}
Expand All @@ -72,7 +72,7 @@ public static void clickOn (final Locator locator) {
*/
public static void doubleClickOn (final Locator locator) {
LOGGER.traceEntry ();
LOGGER.info ("Double Click on element: {}", locator);
LOGGER.info ("Double Click on element: {}", locator.getName ());
performElementAction (element -> {
final Actions actions = new Actions (getSession ().getDriver ());
actions.doubleClick (element)
Expand All @@ -89,7 +89,7 @@ public static void doubleClickOn (final Locator locator) {
*/
public static void dragDropTo (final Locator source, final Locator destination) {
LOGGER.traceEntry ();
LOGGER.info ("Drag and Drop on element: {} , {}", source, destination);
LOGGER.info ("Drag and Drop on element: {} , {}", source.getName (), destination.getName ());
performElementAction (element -> {
final var actions = new Actions (getSession ().getDriver ());
actions.dragAndDrop (element, find (destination, VISIBLE))
Expand All @@ -105,7 +105,7 @@ public static void dragDropTo (final Locator source, final Locator destination)
*/
public static void hoverOn (final Locator locator) {
LOGGER.traceEntry ();
LOGGER.info ("Hover on element: {}", locator);
LOGGER.info ("Hover on element: {}", locator.getName ());
performElementAction (element -> {
final Actions actions = new Actions (getSession ().getDriver ());
actions.moveToElement (element)
Expand All @@ -121,7 +121,7 @@ public static void hoverOn (final Locator locator) {
*/
public static void rightClickOn (final Locator locator) {
LOGGER.traceEntry ();
LOGGER.info ("Right Click on element: {}", locator);
LOGGER.info ("Right Click on element: {}", locator.getName ());
new Actions (getSession ().getDriver ()).contextClick (find (locator, CLICKABLE))
.perform ();
LOGGER.traceExit ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public final class VerifyElementActions {
*/
public static StringSubject verifyAttributeOf (final Locator locator, final String attribute) {
LOGGER.traceEntry ();
LOGGER.info ("Verifying attribute of {}", locator);
LOGGER.info ("Verifying attribute of {}", locator.getName ());
LOGGER.traceExit ();
return assertThat (attributeOf (locator, attribute));
}
Expand All @@ -63,7 +63,7 @@ public static StringSubject verifyAttributeOf (final Locator locator, final Stri
*/
public static BooleanSubject verifyElementDisplayed (final Locator locator) {
LOGGER.traceEntry ();
LOGGER.info ("Verifying element {} is displayed", locator);
LOGGER.info ("Verifying element {} is displayed", locator.getName ());
LOGGER.traceExit ();
return assertThat (isDisplayed (locator));
}
Expand All @@ -77,7 +77,7 @@ public static BooleanSubject verifyElementDisplayed (final Locator locator) {
*/
public static BooleanSubject verifyElementEnabled (final Locator locator) {
LOGGER.traceEntry ();
LOGGER.info ("Verifying element {} is enabled", locator);
LOGGER.info ("Verifying element {} is enabled", locator.getName ());
LOGGER.traceExit ();
return assertThat (isEnabled (locator));
}
Expand All @@ -91,7 +91,7 @@ public static BooleanSubject verifyElementEnabled (final Locator locator) {
*/
public static BooleanSubject verifyElementSelected (final Locator locator) {
LOGGER.traceEntry ();
LOGGER.info ("Verifying element {} is selected", locator);
LOGGER.info ("Verifying element {} is selected", locator.getName ());
LOGGER.traceExit ();
return assertThat (isSelected (locator));
}
Expand All @@ -106,7 +106,7 @@ public static BooleanSubject verifyElementSelected (final Locator locator) {
*/
public static StringSubject verifyStyleOf (final Locator locator, final String attribute) {
LOGGER.traceEntry ();
LOGGER.info ("Verifying style of {}", locator);
LOGGER.info ("Verifying style of {}", locator.getName ());
LOGGER.traceExit ();
return assertThat (styleOf (locator, attribute));
}
Expand All @@ -120,7 +120,7 @@ public static StringSubject verifyStyleOf (final Locator locator, final String a
*/
public static StringSubject verifyTextOf (final Locator locator) {
LOGGER.traceEntry ();
LOGGER.info ("Verifying text of {}", locator);
LOGGER.info ("Verifying text of {}", locator.getName ());
LOGGER.traceExit ();
return assertThat (textOf (locator));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
import org.jetbrains.annotations.NotNull;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

Expand All @@ -36,6 +37,8 @@
public class Locator {
private Predicate<WebElement> filter;
private int index;
@NotNull
private String name;
private Locator parent;
private By web;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static CartPage cartPage () {
}

private final Locator checkout = buildLocator ().web (id ("checkout"))
.name ("Checkout")
.build ();

private CartPage () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,28 @@ public static CheckoutPage checkoutPage () {
}

private final Locator completeHeader = buildLocator ().web (cssSelector ("h2.complete-header"))
.name ("Complete Header")
.build ();
private final Locator completeText = buildLocator ().web (cssSelector ("div.complete-text"))
.name ("Complete Text")
.build ();
private final Locator continueButton = buildLocator ().web (id ("continue"))
.name ("Continue Button")
.build ();
private final Locator finish = buildLocator ().web (id ("finish"))
.name ("Finish")
.build ();
private final Locator firstName = buildLocator ().web (id ("first-name"))
.name ("First Name")
.build ();
private final Locator lastName = buildLocator ().web (id ("last-name"))
.name ("Last Name")
.build ();
private final Locator title = buildLocator ().web (cssSelector ("span.title"))
.name ("Title")
.build ();
private final Locator zipCode = buildLocator ().web (id ("postal-code"))
.name ("Zip Code")
.build ();

private CheckoutPage () {
Expand Down

0 comments on commit 1d87358

Please sign in to comment.