Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(java): 🐛 fixed assertion messages for inbuilt assertions #786

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static com.github.wasiqb.boyka.actions.CommonActions.getDriverAttribute;
import static com.github.wasiqb.boyka.enums.ListenerType.ALERT_ACTION;
import static com.github.wasiqb.boyka.manager.ParallelSession.getSession;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static java.util.Optional.ofNullable;
import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.apache.logging.log4j.LogManager.getLogger;
Expand Down Expand Up @@ -100,7 +100,7 @@ public StringSubject verifyAccept () {
LOGGER.info ("Verifying accept alert");
LOGGER.traceExit ();
ofNullable (this.listener).ifPresent (IAlertActionsListener::onVerifyAccept);
return assertThat (accept ());
return assertWithMessage ("Accepted Alert").that (accept ());
}

@Override
Expand All @@ -109,7 +109,7 @@ public StringSubject verifyAccept (final String text) {
LOGGER.info ("Verifying accept prompt");
LOGGER.traceExit ();
ofNullable (this.listener).ifPresent (l -> l.onVerifyAccept (text));
return assertThat (accept (text));
return assertWithMessage ("Accepted Alert Prompt").that (accept (text));
}

@Override
Expand All @@ -118,6 +118,6 @@ public StringSubject verifyDismiss () {
LOGGER.info ("Verifying alert message and dismissing the alert");
LOGGER.traceExit ();
ofNullable (this.listener).ifPresent (IAlertActionsListener::onVerifyDismiss);
return assertThat (dismiss ());
return assertWithMessage ("Dismissed Alert").that (dismiss ());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import static com.github.wasiqb.boyka.enums.Message.BASE_URL_EMPTY;
import static com.github.wasiqb.boyka.manager.ParallelSession.getSession;
import static com.github.wasiqb.boyka.utils.Validator.requireNonEmpty;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static java.util.Optional.ofNullable;
import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.apache.logging.log4j.LogManager.getLogger;
Expand Down Expand Up @@ -119,6 +119,6 @@ public StringSubject verifyUrl () {
LOGGER.info ("Verifying browser url");
ofNullable (this.listener).ifPresent (INavigateActionsListener::onVerifyUrl);
LOGGER.traceExit ();
return assertThat (getUrl ());
return assertWithMessage ("URL").that (getUrl ());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import static com.github.wasiqb.boyka.manager.ParallelSession.getSession;
import static com.github.wasiqb.boyka.utils.ErrorHandler.handleAndThrow;
import static com.github.wasiqb.boyka.utils.Validator.requireNonNull;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static java.util.Optional.ofNullable;
import static org.apache.commons.io.FileUtils.copyFile;
import static org.apache.commons.lang3.StringUtils.EMPTY;
Expand Down Expand Up @@ -220,7 +220,7 @@ public StringSubject verifyTitle () {
LOGGER.info ("Verifying browser title...");
ofNullable (this.listener).ifPresent (IWindowActionsListener::onVerifyTitle);
LOGGER.traceExit ();
return assertThat (getTitle ());
return assertWithMessage ("Title").that (getTitle ());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import static com.github.wasiqb.boyka.enums.Message.ERROR_DESELECT_FROM_DROPDOWN;
import static com.github.wasiqb.boyka.manager.ParallelSession.getSession;
import static com.github.wasiqb.boyka.utils.ErrorHandler.throwError;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static java.util.Collections.emptyList;
import static java.util.Optional.ofNullable;
import static org.apache.commons.lang3.StringUtils.EMPTY;
Expand Down Expand Up @@ -199,13 +199,13 @@ public List<String> selectedItems () {
public StringSubject verifySelectedItem () {
LOGGER.info ("Verifying the selected item...");
ofNullable (this.listener).ifPresent (l -> l.onVerifySelectedItem (this.locator));
return assertThat (selectedItem ());
return assertWithMessage ("Selected Item").that (selectedItem ());
}

@Override
public IterableSubject verifySelectedItems () {
LOGGER.info ("Verifying the selected items...");
ofNullable (this.listener).ifPresent (l -> l.onVerifySelectedItems (this.locator));
return assertThat (selectedItems ());
return assertWithMessage ("Selected Items").that (selectedItems ());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import static com.github.wasiqb.boyka.enums.ListenerType.ELEMENT_ACTION;
import static com.github.wasiqb.boyka.enums.PlatformType.WEB;
import static com.github.wasiqb.boyka.manager.ParallelSession.getSession;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static java.util.Optional.ofNullable;
import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.apache.logging.log4j.LogManager.getLogger;
Expand Down Expand Up @@ -142,7 +142,7 @@ public StringSubject verifyAttribute (final String attribute) {
LOGGER.info ("Verifying attribute of {}", this.locator.getName ());
ofNullable (this.listener).ifPresent (l -> l.onVerifyAttribute (this.locator, attribute));
LOGGER.traceExit ();
return assertThat (getAttribute (attribute));
return assertWithMessage (attribute).that (getAttribute (attribute));
}

@Override
Expand All @@ -151,7 +151,7 @@ public BooleanSubject verifyIsDisplayed () {
LOGGER.info ("Verifying element {} is displayed", this.locator.getName ());
ofNullable (this.listener).ifPresent (l -> l.onVerifyIsDisplayed (this.locator));
LOGGER.traceExit ();
return assertThat (isDisplayed ());
return assertWithMessage ("Displayed").that (isDisplayed ());
}

@Override
Expand All @@ -160,7 +160,7 @@ public BooleanSubject verifyIsEnabled () {
LOGGER.info ("Verifying element {} is enabled", this.locator.getName ());
ofNullable (this.listener).ifPresent (l -> l.onVerifyIsEnabled (this.locator));
LOGGER.traceExit ();
return assertThat (isEnabled ());
return assertWithMessage ("Enabled").that (isEnabled ());
}

@Override
Expand All @@ -169,7 +169,7 @@ public BooleanSubject verifyIsSelected () {
LOGGER.info ("Verifying element {} is selected", this.locator.getName ());
ofNullable (this.listener).ifPresent (l -> l.onVerifyIsSelected (this.locator));
LOGGER.traceExit ();
return assertThat (isSelected ());
return assertWithMessage ("Selected").that (isSelected ());
}

@Override
Expand All @@ -178,7 +178,7 @@ public StringSubject verifyStyle (final String styleName) {
LOGGER.info ("Verifying style of {}", this.locator.getName ());
ofNullable (this.listener).ifPresent (l -> l.onVerifyStyle (this.locator, styleName));
LOGGER.traceExit ();
return assertThat (getStyle (styleName));
return assertWithMessage (styleName).that (getStyle (styleName));
}

@Override
Expand All @@ -187,6 +187,6 @@ public StringSubject verifyText () {
LOGGER.info ("Verifying text of {}", this.locator.getName ());
ofNullable (this.listener).ifPresent (l -> l.onVerifyText (this.locator));
LOGGER.traceExit ();
return assertThat (getText ().trim ());
return assertWithMessage ("Text").that (getText ().trim ());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static com.github.wasiqb.boyka.enums.Message.RESPONSE_SCHEMA_NOT_MATCHING;
import static com.github.wasiqb.boyka.utils.ErrorHandler.handleAndThrow;
import static com.github.wasiqb.boyka.utils.ErrorHandler.throwError;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static com.jayway.jsonpath.JsonPath.compile;
import static com.jayway.jsonpath.JsonPath.parse;
Expand Down Expand Up @@ -109,7 +108,7 @@ public BooleanSubject verifyBooleanField (final String expression) {
LOGGER.traceEntry ();
LOGGER.info ("Verifying boolean field for expression: {}", expression);
LOGGER.traceExit ();
return assertThat (getResponseData (expression, Boolean.class));
return assertWithMessage (expression).that (getResponseData (expression, Boolean.class));
}

/**
Expand All @@ -126,7 +125,7 @@ public StringSubject verifyHeader (final String key) {
if (!getHeaders ().containsKey (key)) {
throwError (INVALID_HEADER_KEY, key);
}
return assertThat (getHeaders ().get (key));
return assertWithMessage (key).that (getHeaders ().get (key));
}

/**
Expand All @@ -140,7 +139,7 @@ public IntegerSubject verifyIntField (final String expression) {
LOGGER.traceEntry ();
LOGGER.info ("Verifying integer field for expression: {}", expression);
LOGGER.traceExit ();
return assertThat (getResponseData (expression, Integer.class));
return assertWithMessage (expression).that (getResponseData (expression, Integer.class));
}

/**
Expand Down Expand Up @@ -179,7 +178,7 @@ public IntegerSubject verifyStatusCode () {
LOGGER.traceEntry ();
LOGGER.info ("Verifying Status Code");
LOGGER.traceExit ();
return assertThat (getStatusCode ());
return assertWithMessage ("Status Code").that (getStatusCode ());
}

/**
Expand All @@ -191,7 +190,7 @@ public StringSubject verifyStatusMessage () {
LOGGER.traceEntry ();
LOGGER.info ("Verifying Status Message");
LOGGER.traceExit ();
return assertThat (getStatusMessage ());
return assertWithMessage ("Status Message").that (getStatusMessage ());
}

/**
Expand All @@ -205,7 +204,7 @@ public StringSubject verifyTextField (final String expression) {
LOGGER.traceEntry ();
LOGGER.info ("Verifying text field for expression: {}", expression);
LOGGER.traceExit ();
return assertThat (getResponseData (expression));
return assertWithMessage (expression).that (getResponseData (expression));
}

private DocumentContext jsonPath () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.github.wasiqb.boyka.testng.others;

import static com.github.wasiqb.boyka.utils.JsonUtil.fromFile;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static java.lang.System.getProperty;

import java.nio.file.Path;
Expand Down Expand Up @@ -47,6 +47,7 @@ public void testFromFile () {
*/
@Test
public void testToString () {
assertThat (JsonUtil.toString ("Created")).isEqualTo ("Created");
assertWithMessage ("JsonUtil").that (JsonUtil.toString ("Created"))
.isEqualTo ("Created");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import static com.github.wasiqb.boyka.manager.ParallelSession.clearSession;
import static com.github.wasiqb.boyka.manager.ParallelSession.createSession;
import static com.github.wasiqb.boyka.testng.ui.theinternet.pages.HomePage.homePage;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;

import com.github.wasiqb.boyka.enums.PlatformType;
import org.testng.annotations.AfterClass;
Expand Down Expand Up @@ -69,8 +69,9 @@ public void tearDownClass () {
@Test (description = "Verify delete all cookies", priority = 3)
public void testDeleteAllCookies () {
withCookies ().deleteAll ();
assertThat (withCookies ().cookies ()
.size ()).isEqualTo (0);
assertWithMessage ("Cookie size").that (withCookies ().cookies ()
.size ())
.isEqualTo (0);
}

/**
Expand All @@ -81,8 +82,9 @@ public void testDeleteSingleCookie () {
final var cookies = withCookies ().cookies ();
final var cookieCount = cookies.size ();
withCookies ().delete (cookies.get (0));
assertThat (withCookies ().cookies ()
.size ()).isEqualTo (cookieCount - 1);
assertWithMessage ("Cookie Size").that (withCookies ().cookies ()
.size ())
.isEqualTo (cookieCount - 1);
}

/**
Expand All @@ -92,7 +94,8 @@ public void testDeleteSingleCookie () {
public void testGetCookie () {
final var cookie = withCookies ().cookies ()
.get (0);
assertThat (withCookies ().cookie (cookie)
.getName ()).isEqualTo (cookie);
assertWithMessage ("Cookie Name").that (withCookies ().cookie (cookie)
.getName ())
.isEqualTo (cookie);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import static com.github.wasiqb.boyka.manager.ParallelSession.createSession;
import static com.github.wasiqb.boyka.testng.ui.theinternet.pages.HomePage.homePage;
import static com.github.wasiqb.boyka.testng.ui.theinternet.pages.MultiWindowPage.multiWindowPage;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static java.text.MessageFormat.format;
import static org.openqa.selenium.WindowType.TAB;
import static org.openqa.selenium.support.ui.ExpectedConditions.urlMatches;
Expand Down Expand Up @@ -127,7 +127,8 @@ public void testOpenWindow () {
.stream ()
.filter (handle -> !handle.equals (currentWindow))
.findFirst ();
assertThat (newWindow.isPresent ()).isTrue ();
assertWithMessage ("Window").that (newWindow.isPresent ())
.isTrue ();
onWindow ().switchTo (newWindow.get ());
withDriver ().waitUntil (urlMatches (format ("{0}windows/new", URL)));
navigate ().verifyUrl ()
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
"license": "MIT",
"private": true,
"devDependencies": {
"@commitlint/cli": "^18.6.1",
"@commitlint/config-conventional": "^18.6.2",
"@commitlint/cli": "^19.0.3",
"@commitlint/config-conventional": "^19.0.3",
"@lerna/child-process": "^7.4.2",
"@types/node": "^20.11.20",
"@types/node": "^20.11.24",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"commitlint": "^18.6.1",
"commitlint": "^19.0.3",
"eslint": "^8.57.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^9.1.0",
Expand All @@ -50,7 +50,7 @@
"lerna-version": "^6.6.2",
"lint-staged": "^15.2.2",
"lodash": "^4.17.21",
"nx": "^18.0.5",
"nx": "^18.0.6",
"prettier": "^3.2.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
Loading