-
Notifications
You must be signed in to change notification settings - Fork 4
Feature/15 element #34
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
8b2fb31
#15 extracted IElement
knysh 34e185b
Merge branch 'master' into Feature/15-element
knysh eb6f9bf
#14 merged with master and fixed issues
knysh e5355fd
#14 inherited Custom element from Element
knysh 6a53ed1
#14 updated IElement and added tests for this
knysh e0f53c3
#14 removed last 's' in applications
knysh 0571868
#14 small fix for docs
knysh f3c13a6
#14 fix comments
knysh 03fc0ac
#14 remove using logger from testRetrierShouldWorkOnceIfMethodSucceeded
knysh dd24d54
#14 reverted getElementState() for Element
knysh c8f3992
#14 fix localization
knysh 02ab897
Merge branch 'master' into Feature/15-element
knysh a7c1814
#14 increased accuracy of conditional wait tests
knysh fb0c5d3
Merge branch 'master' into Feature/15-element
knysh 3ba1d5e
#14 added taskkill chromedriver
knysh da4b6ff
#14 removed taskkill chromedriver
knysh 9a4538b
#14 hot fix for WaitForObjectTests
knysh 701bce9
#14 removed redundant ,
knysh a60d9c5
#14 added debug info
knysh 6264ee6
#14 added catching of InterruptedException
knysh da2f07a
#14 removed parallel = true for data driven
knysh 53fe0d1
#14 reverted for element action retrier tests
knysh 55d49ee
#14 added accuracy for checkRetrierShouldWaitPollingTimeBetweenMethod…
knysh be548c2
#14 removed unused import
knysh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
145 changes: 145 additions & 0 deletions
145
src/main/java/aquality/selenium/core/elements/Element.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
package aquality.selenium.core.elements; | ||
|
||
import aquality.selenium.core.applications.IApplication; | ||
import aquality.selenium.core.configurations.IElementCacheConfiguration; | ||
import aquality.selenium.core.elements.interfaces.*; | ||
import aquality.selenium.core.localization.ILocalizedLogger; | ||
import aquality.selenium.core.logging.Logger; | ||
import aquality.selenium.core.utilities.IElementActionRetrier; | ||
import aquality.selenium.core.waitings.IConditionalWait; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.NoSuchElementException; | ||
import org.openqa.selenium.WebDriverException; | ||
import org.openqa.selenium.remote.RemoteWebElement; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public abstract class Element implements IElement { | ||
|
||
private final String name; | ||
private final ElementState elementState; | ||
private final By locator; | ||
private IElementCacheHandler elementCacheHandler; | ||
|
||
protected Element(final By loc, final String name, final ElementState state) { | ||
locator = loc; | ||
this.name = name; | ||
elementState = state; | ||
} | ||
|
||
protected abstract IApplication getApplication(); | ||
|
||
protected abstract IElementFactory getElementFactory(); | ||
|
||
protected abstract IElementFinder getElementFinder(); | ||
|
||
protected abstract IElementCacheConfiguration getElementCacheConfiguration(); | ||
|
||
protected abstract IElementActionRetrier getElementActionRetrier(); | ||
|
||
protected abstract ILocalizedLogger getLocalizedLogger(); | ||
|
||
protected abstract IConditionalWait getConditionalWait(); | ||
|
||
protected abstract String getElementType(); | ||
|
||
protected IElementCacheHandler getCache() { | ||
if (elementCacheHandler == null) { | ||
elementCacheHandler = new ElementCacheHandler(locator, elementState, getElementFinder()); | ||
} | ||
|
||
return elementCacheHandler; | ||
} | ||
|
||
protected Logger getLogger() { | ||
return Logger.getInstance(); | ||
} | ||
|
||
@Override | ||
public By getLocator() { | ||
return locator; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public IElementStateProvider state() { | ||
return getElementCacheConfiguration().isEnabled() | ||
? new CachedElementStateProvider(locator, getConditionalWait(), getCache(), getLocalizedLogger()) | ||
: new DefaultElementStateProvider(locator, getConditionalWait(), getElementFinder()); | ||
} | ||
|
||
@Override | ||
public RemoteWebElement getElement(Long timeout) { | ||
try { | ||
return getElementCacheConfiguration().isEnabled() | ||
? getCache().getElement(timeout) | ||
: (RemoteWebElement) getElementFinder().findElement(locator, elementState, timeout); | ||
} catch (NoSuchElementException e) { | ||
logPageSource(e); | ||
throw e; | ||
} | ||
} | ||
|
||
protected void logPageSource(WebDriverException exception) { | ||
try { | ||
getLogger().debug("Page source:".concat(System.lineSeparator()).concat(getApplication().getDriver().getPageSource()), exception); | ||
} catch (WebDriverException e) { | ||
getLogger().error(exception.getMessage()); | ||
getLocalizedLogger().fatal("loc.get.page.source.failed", e); | ||
} | ||
} | ||
|
||
@Override | ||
public String getText() { | ||
logElementAction("loc.get.text"); | ||
return doWithRetry(() -> getElement().getText()); | ||
} | ||
|
||
@Override | ||
public String getAttribute(String attr) { | ||
logElementAction("loc.el.getattr", attr); | ||
return doWithRetry(() -> getElement().getAttribute(attr)); | ||
} | ||
|
||
@Override | ||
public void sendKeys(String keys) { | ||
logElementAction("loc.text.sending.keys", keys); | ||
doWithRetry(() -> getElement().sendKeys(keys)); | ||
} | ||
|
||
@Override | ||
public void click() { | ||
logElementAction("loc.clicking"); | ||
doWithRetry(() -> getElement().click()); | ||
} | ||
|
||
@Override | ||
public <T extends IElement> T findChildElement(By childLoc, String name, Class<T> clazz, ElementState state) { | ||
return getElementFactory().findChildElement(this, childLoc, name, clazz, state); | ||
} | ||
|
||
@Override | ||
public <T extends IElement> T findChildElement(By childLoc, String name, IElementSupplier<T> supplier, ElementState state) { | ||
return getElementFactory().findChildElement(this, childLoc, name, supplier, state); | ||
} | ||
|
||
protected <T> T doWithRetry(Supplier<T> action) { | ||
return getElementActionRetrier().doWithRetry(action); | ||
} | ||
|
||
protected void doWithRetry(Runnable action) { | ||
getElementActionRetrier().doWithRetry(action); | ||
} | ||
|
||
protected void logElementAction(String messageKey, Object... args) { | ||
getLocalizedLogger().infoElementAction(getElementType(), name, messageKey, args); | ||
} | ||
|
||
protected ElementState getElementState() { | ||
return elementState; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.