Skip to content

Commit

Permalink
cleanup: remove unused field UIAssertionError.driver
Browse files Browse the repository at this point in the history
  • Loading branch information
asolntsev committed Sep 28, 2021
1 parent c04e484 commit cb7933c
Show file tree
Hide file tree
Showing 49 changed files with 131 additions and 171 deletions.
31 changes: 20 additions & 11 deletions src/main/java/com/codeborne/selenide/ElementsCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ protected void waitUntil(CollectionCondition condition, Duration timeout) {
while (!stopwatch.isTimeoutReached());

if (lastError instanceof IndexOutOfBoundsException) {
throw new ElementNotFound(collection.driver(), collection.description(), exist, lastError);
throw new ElementNotFound(collection.description(), exist, lastError);
}
else if (lastError instanceof UIAssertionError) {
throw (UIAssertionError) lastError;
Expand All @@ -225,7 +225,8 @@ else if (lastError instanceof UIAssertionError) {
void sleep(long ms) {
try {
Thread.sleep(ms);
} catch (InterruptedException e) {
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
Expand All @@ -247,9 +248,9 @@ public ElementsCollection filter(Condition condition) {
/**
* Filters collection elements based on the given condition (lazy evaluation)
*
* @see #filter(Condition)
* @param condition condition
* @return ElementsCollection
* @see #filter(Condition)
* @see <a href="https://github.com/selenide/selenide/wiki/lazy-loading">Lazy loading</a>
*/
@CheckReturnValue
Expand All @@ -274,9 +275,9 @@ public ElementsCollection exclude(Condition condition) {
/**
* Filters elements excluding those which met the given condition (lazy evaluation)
*
* @see #exclude(Condition)
* @param condition condition
* @return ElementsCollection
* @see #exclude(Condition)
* @see <a href="https://github.com/selenide/selenide/wiki/lazy-loading">Lazy loading</a>
*/
@CheckReturnValue
Expand All @@ -301,9 +302,9 @@ public SelenideElement find(Condition condition) {
/**
* Find the first element which met the given condition (lazy evaluation)
*
* @see #find(Condition)
* @param condition condition
* @return SelenideElement
* @see #find(Condition)
* @see <a href="https://github.com/selenide/selenide/wiki/lazy-loading">Lazy loading</a>
*/
@CheckReturnValue
Expand All @@ -320,6 +321,7 @@ private List<WebElement> getElements() {

/**
* Gets all the texts in elements collection
*
* @return array of texts
* @see <a href="https://github.com/selenide/selenide/wiki/do-not-use-getters-in-tests">NOT RECOMMENDED</a>
*/
Expand All @@ -331,6 +333,7 @@ public List<String> texts() {

/**
* Fail-safe method for retrieving texts of given elements.
*
* @param elements Any collection of WebElements
* @return Array of texts (or exceptions in case of any WebDriverExceptions)
*/
Expand All @@ -343,13 +346,15 @@ public static List<String> texts(@Nullable Collection<WebElement> elements) {
private static String getText(WebElement element) {
try {
return element.getText();
} catch (WebDriverException elementDisappeared) {
}
catch (WebDriverException elementDisappeared) {
return elementDisappeared.toString();
}
}

/**
* Outputs string presentation of the element's collection
*
* @param elements elements of string
* @return e.g. "[<h1>foo</h1>, <h2>bar</h2>]"
* @see <a href="https://github.com/selenide/selenide/wiki/do-not-use-getters-in-tests">NOT RECOMMENDED</a>
Expand Down Expand Up @@ -450,22 +455,24 @@ public ElementsCollection last(int elements) {
* return actual size of the collection, doesn't wait on collection to be loaded.
* </p>
*
* @see <a href="https://github.com/selenide/selenide/wiki/do-not-use-getters-in-tests">NOT RECOMMENDED</a>
* @return actual size of the collection
* @see <a href="https://github.com/selenide/selenide/wiki/do-not-use-getters-in-tests">NOT RECOMMENDED</a>
*/
@CheckReturnValue
@Override
public int size() {
try {
return getElements().size();
} catch (IndexOutOfBoundsException outOfCollection) {
}
catch (IndexOutOfBoundsException outOfCollection) {
return 0;
}
}

/**
* Does not reload collection elements while iterating it.
* Not recommended to use.
*
* @see <a href="https://github.com/selenide/selenide/wiki/do-not-use-getters-in-tests">NOT RECOMMENDED</a>
*/
@Override
Expand All @@ -478,6 +485,7 @@ public Iterator<SelenideElement> iterator() {
/**
* Does not reload collection elements while iterating it.
* Not recommended to use.
*
* @see <a href="https://github.com/selenide/selenide/wiki/do-not-use-getters-in-tests">NOT RECOMMENDED</a>
*/
@Override
Expand Down Expand Up @@ -510,7 +518,7 @@ public Object[] toArray() {
/**
* Takes the snapshot of current state of this collection.
* Succeeding calls to this object WILL NOT RELOAD collection element from browser.
*
* <p>
* Use it to speed up your tests - but only if you know that collection will not be changed during the test.
*
* @return current state of this collection
Expand All @@ -523,7 +531,7 @@ public ElementsCollection snapshot() {

/**
* Give this collection a human-readable name
*
* <p>
* Caution: you probably don't need this method.
* It's always a good idea to have the actual selector instead of "nice" description (which might be misleading or even lying).
*
Expand All @@ -543,7 +551,8 @@ public ElementsCollection as(String alias) {
public String toString() {
try {
return String.format("%s %s", collection.description(), elementsToString(driver(), getElements()));
} catch (RuntimeException e) {
}
catch (RuntimeException e) {
return String.format("%s [%s]", collection.description(), Cleanup.of.webdriverExceptionMessage(e));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/codeborne/selenide/Modal.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private String getLogSubject(@Nullable String expectedDialogText) {

private static void checkDialogText(Driver driver, @Nullable String expectedDialogText, String actualDialogText) {
if (expectedDialogText != null && !expectedDialogText.equals(actualDialogText)) {
DialogTextMismatch assertionError = new DialogTextMismatch(driver, expectedDialogText, actualDialogText);
DialogTextMismatch assertionError = new DialogTextMismatch(expectedDialogText, actualDialogText);
throw UIAssertionError.wrap(driver, assertionError, driver.config().timeout());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,17 +236,17 @@ private SelenideWait Wait(Duration timeout) {
}

private Error frameNotFoundError(String message, Throwable cause) {
FrameNotFoundException error = new FrameNotFoundException(driver, message, cause);
FrameNotFoundException error = new FrameNotFoundException(message, cause);
return UIAssertionError.wrap(driver, error, config.timeout());
}

private Error windowNotFoundError(String message, Throwable cause) {
WindowNotFoundException error = new WindowNotFoundException(driver, message, cause);
WindowNotFoundException error = new WindowNotFoundException(message, cause);
return UIAssertionError.wrap(driver, error, config.timeout());
}

private Error alertNotFoundError(Throwable cause) {
AlertNotFoundException error = new AlertNotFoundException(driver, cause);
AlertNotFoundException error = new AlertNotFoundException(cause);
return UIAssertionError.wrap(driver, error, config.timeout());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void fail(CollectionSource collection,
throw elementNotFound;
}
else if (elements.size() != expectedTexts.size()) {
throw new TextsSizeMismatch(collection, ElementsCollection.texts(elements), expectedTexts, explanation, timeoutMs);
throw new TextsSizeMismatch(collection, expectedTexts, ElementsCollection.texts(elements), explanation, timeoutMs);
}
else {
throw new TextsMismatch(collection, expectedTexts, ElementsCollection.texts(elements), explanation, timeoutMs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void fail(CollectionSource collection,
@Nullable List<WebElement> elements,
@Nullable Exception lastError,
long timeoutMs) {
throw new ListSizeMismatch(collection.driver(), "=", expectedSize, explanation, collection, elements, lastError, timeoutMs);
throw new ListSizeMismatch("=", expectedSize, explanation, collection, elements, lastError, timeoutMs);
}

@CheckReturnValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void fail(CollectionSource collection,
@Nullable List<WebElement> elements,
@Nullable Exception lastError,
long timeoutMs) {
throw new ListSizeMismatch(collection.driver(), ">", expectedSize, explanation, collection, elements, lastError, timeoutMs);
throw new ListSizeMismatch(">", expectedSize, explanation, collection, elements, lastError, timeoutMs);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void fail(CollectionSource collection,
@Nullable List<WebElement> elements,
@Nullable Exception lastError,
long timeoutMs) {
throw new ListSizeMismatch(collection.driver(), ">=", expectedSize, explanation, collection, elements, lastError, timeoutMs);
throw new ListSizeMismatch(">=", expectedSize, explanation, collection, elements, lastError, timeoutMs);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void fail(CollectionSource collection,
@Nullable List<WebElement> elements,
@Nullable Exception lastError,
long timeoutMs) {
throw new ListSizeMismatch(collection.driver(), "<", expectedSize, explanation, collection, elements, lastError, timeoutMs);
throw new ListSizeMismatch("<", expectedSize, explanation, collection, elements, lastError, timeoutMs);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void fail(CollectionSource collection,
@Nullable List<WebElement> elements,
@Nullable Exception lastError,
long timeoutMs) {
throw new ListSizeMismatch(collection.driver(), "<=", expectedSize, explanation, collection, elements, lastError, timeoutMs);
throw new ListSizeMismatch("<=", expectedSize, explanation, collection, elements, lastError, timeoutMs);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void fail(CollectionSource collection,
@Nullable List<WebElement> elements,
@Nullable Exception lastError,
long timeoutMs) {
throw new ListSizeMismatch(collection.driver(), "<>", expectedSize, explanation, collection, elements, lastError, timeoutMs);
throw new ListSizeMismatch("<>", expectedSize, explanation, collection, elements, lastError, timeoutMs);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private void selectOptionsByTexts(WebElementSource selectField, String[] texts)
select.selectByVisibleText(text);
}
catch (NoSuchElementException e) {
throw new ElementNotFound(selectField.driver(), selectField.description() + "/option[text:" + text + ']', exist, e);
throw new ElementNotFound(selectField.description() + "/option[text:" + text + ']', exist, e);
}
}
}
Expand All @@ -53,7 +53,7 @@ private void selectOptionsByIndexes(WebElementSource selectField, int[] indexes)
select.selectByIndex(index);
}
catch (NoSuchElementException e) {
throw new ElementNotFound(selectField.driver(), selectField.description() + "/option[index:" + index + ']', exist, e);
throw new ElementNotFound(selectField.description() + "/option[index:" + index + ']', exist, e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private void selectOptionByValue(WebElementSource selectField, Select select, St
select.selectByValue(value);
}
catch (NoSuchElementException e) {
throw new ElementNotFound(selectField.driver(), selectField.description() + "/option[value:" + value + ']', exist, e);
throw new ElementNotFound(selectField.description() + "/option[value:" + value + ']', exist, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public SelenideElement execute(SelenideElement proxy, WebElementSource locator,
for (WebElement radio : matchingRadioButtons) {
if (value.equals(radio.getAttribute("value"))) {
if (radio.getAttribute("readonly") != null)
throw new InvalidStateException(locator.driver(), "Cannot select readonly radio button");
throw new InvalidStateException("Cannot select readonly radio button");
click.click(locator.driver(), radio);
return wrap(locator.driver(), radio);
}
}
throw new ElementNotFound(locator.driver(), locator.description(), value(value));
throw new ElementNotFound(locator.description(), value(value));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ public SelenideElement execute(SelenideElement proxy, WebElementSource locator,
boolean selected = firstOf(args);
WebElement element = locator.getWebElement();
if (!element.isDisplayed()) {
throw new InvalidStateException(locator.driver(), "Cannot change invisible element");
throw new InvalidStateException("Cannot change invisible element");
}
String tag = element.getTagName();
if (!tag.equals("option")) {
if (tag.equals("input")) {
String type = element.getAttribute("type");
if (!type.equals("checkbox") && !type.equals("radio")) {
throw new InvalidStateException(locator.driver(), "Only use setSelected on checkbox/option/radio");
throw new InvalidStateException("Only use setSelected on checkbox/option/radio");
}
}
else {
throw new InvalidStateException(locator.driver(), "Only use setSelected on checkbox/option/radio");
throw new InvalidStateException("Only use setSelected on checkbox/option/radio");
}
}
if (element.getAttribute("readonly") != null || element.getAttribute("disabled") != null) {
throw new InvalidStateException(locator.driver(), "Cannot change value of readonly/disabled element");
throw new InvalidStateException("Cannot change value of readonly/disabled element");
}
if (element.isSelected() != selected) {
click.execute(proxy, locator, NO_ARGS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void setValueForTextInput(Driver driver, WebElement element, String text
}
else if (driver.config().fastSetValue()) {
String error = setValueByJs(driver, element, text);
if (error != null) throw new InvalidStateException(driver, error);
if (error != null) throw new InvalidStateException(error);
else {
events.fireEvent(driver, element, "keydown", "keypress", "input", "keyup", "change");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.codeborne.selenide.ex;

import com.codeborne.selenide.Driver;

import javax.annotation.ParametersAreNonnullByDefault;

@ParametersAreNonnullByDefault
public class AlertNotFoundException extends UIAssertionError {
public AlertNotFoundException(Driver driver, Throwable cause) {
super(driver, "Alert not found", cause);
public AlertNotFoundException(Throwable cause) {
super("Alert not found", cause);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.codeborne.selenide.ex;

import com.codeborne.selenide.Driver;
import com.codeborne.selenide.ObjectCondition;

import javax.annotation.ParametersAreNonnullByDefault;
Expand All @@ -9,8 +8,8 @@

@ParametersAreNonnullByDefault
public class ConditionMetException extends ObjectConditionError {
public <T> ConditionMetException(Driver driver, ObjectCondition<T> condition, T subject) {
super(driver,
public <T> ConditionMetException(ObjectCondition<T> condition, T subject) {
super(
condition.describe(subject) + " " + condition.negativeDescription(),
condition.expectedValue(),
extractActualValue(condition, subject)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.codeborne.selenide.ex;

import com.codeborne.selenide.Driver;
import com.codeborne.selenide.ObjectCondition;

import javax.annotation.ParametersAreNonnullByDefault;
Expand All @@ -9,8 +8,8 @@

@ParametersAreNonnullByDefault
public class ConditionNotMetException extends ObjectConditionError {
public <T> ConditionNotMetException(Driver driver, ObjectCondition<T> condition, T subject) {
super(driver,
public <T> ConditionNotMetException(ObjectCondition<T> condition, T subject) {
super(
condition.describe(subject) + " " + condition.description(),
condition.expectedValue(),
extractActualValue(condition, subject)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.codeborne.selenide.ex;

import com.codeborne.selenide.Driver;

import javax.annotation.ParametersAreNonnullByDefault;

@ParametersAreNonnullByDefault
public class DialogTextMismatch extends UIAssertionError {
public DialogTextMismatch(Driver driver, String expectedText, String actualText) {
super(driver,
public DialogTextMismatch(String expectedText, String actualText) {
super(
String.format("Dialog text mismatch" +
"%nActual: %s" +
"%nExpected: %s", actualText, expectedText),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class DoesNotContainTextsError extends UIAssertionError {
public DoesNotContainTextsError(CollectionSource collection,
List<String> expectedTexts, List<String> actualTexts, List<String> difference,
@Nullable String explanation, long timeoutMs, @Nullable Throwable lastError) {
super(collection.driver(),
super(
"The collection with text elements: " + actualTexts +
lineSeparator() + "should contain all of the following text elements: " + expectedTexts +
(explanation == null ? "" : lineSeparator() + "Because: " + explanation) +
Expand Down
Loading

0 comments on commit cb7933c

Please sign in to comment.