Skip to content

Conversation

mialeska
Copy link
Contributor

@mialeska mialeska commented Feb 4, 2020

PR Details

Implement IElementFinder, add DesiredState and ElementState helpful classes
add RelativeElementFinder, add tests

Related Issue Link:

closes #13

How Has This Been Tested
Checklist
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

/**
* Defines desired state for element with ability to handle exceptions.
*/
public class DesiredState {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make this class package-private? and do not we need to extract an interface of it?

Copy link
Contributor Author

@mialeska mialeska Feb 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, we cannot make it private, we will need it in child libraries.
no, I don't think that we need to extract an interface of it. This class is a simple model, and we expect it to remain the same. We don't register it in DI, so the interface is needless

List<WebElement> resultElements = new ArrayList<>();
try {
conditionalWait.waitFor(driver -> {
List<WebElement> currentFoundElements = driver == null ? new ArrayList<>() : driver.findElements(locator);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is the driver initialized? I am asking because trying to imagine what case driver might be null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that the driver could possibly be null (it gained from the application class, from the DI). There is only one reason for this null check: IDE code-checking plugins suggest to add it


@Override
public List<WebElement> findElements(By locator, DesiredState desiredState, Long timeoutInSeconds) {
AtomicBoolean wasAnyElementFound = new AtomicBoolean(false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this variable? why can't we operate only with 'resultElements.isEmpty()'?
or it is just because lambda usage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result elements is a different array, in fact it has elements after filtering, while this variable defines whether any element was there before filtering. please recheck your suggestion

}

@Override
public List<WebElement> findElements(By locator, DesiredState desiredState, Long timeoutInSeconds) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I am right the difference between this method and another one from the ElementFinder class that here we use 'searchContextSupplier.get()' instead 'driver' - can we create one parametrized and re-use it for both cases by passing necessary supplier?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually no, you are wrong.
Nevertheless, I guess that I can extract the method from the lambda expression

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored, please check again

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 5, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@DmitryBogatko DmitryBogatko merged commit 4e21d59 into master Feb 7, 2020
@paveliam paveliam deleted the Feature/13-ElementFinder branch May 7, 2020 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement ElementFinder

3 participants