-
Notifications
You must be signed in to change notification settings - Fork 18
extract URL into project config && extend method checkColumnExists #55
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
Open
brumlablo
wants to merge
2
commits into
main
Choose a base branch
from
issues9_and_54
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
20 changes: 20 additions & 0 deletions
20
src/main/java/cz/czechitas/automation/ElementFinderInterface.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,20 @@ | ||
| package cz.czechitas.automation; | ||
|
|
||
| import org.openqa.selenium.WebElement; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.ParametersAreNonnullByDefault; | ||
|
|
||
| /** | ||
| * Used for mocking in testing | ||
| */ | ||
| @ParametersAreNonnullByDefault | ||
| public interface ElementFinderInterface { | ||
|
|
||
| @Nonnull | ||
| WebElement findByXPath(String xpathExpression); | ||
|
|
||
| @Nonnull | ||
| WebElement findByCssSelector(String cssSelector); | ||
| } | ||
|
|
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
89 changes: 89 additions & 0 deletions
89
src/test/java/cz/czechitas/automation/assertion/ApplicationAssertionTest.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,89 @@ | ||
| package cz.czechitas.automation.assertion; | ||
|
|
||
| import cz.czechitas.automation.ElementFinderInterface; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
| import org.openqa.selenium.WebElement; | ||
|
|
||
| import javax.annotation.ParametersAreNonnullByDefault; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThatCode; | ||
| import static org.mockito.Mockito.*; | ||
|
|
||
| @ParametersAreNonnullByDefault | ||
| @ExtendWith(MockitoExtension.class) | ||
| class ApplicationAssertionTest { | ||
|
|
||
| @Mock | ||
| ElementFinderInterface elementFinder; | ||
|
|
||
| private static WebElement mockElementWithText(String text) { | ||
| WebElement el = mock(WebElement.class); | ||
| when(el.getText()).thenReturn(text); | ||
| return el; | ||
| } | ||
|
|
||
| // Re-implementation of production xpathLiteral for building expected xpath in tests | ||
| private static String xpathLiteralForTest(String s) { | ||
| if (!s.contains("'")) { | ||
| return "'" + s + "'"; | ||
| } | ||
| if (!s.contains("\"")) { | ||
| return "\"" + s + "\""; | ||
| } | ||
| String[] parts = s.split("'"); | ||
| StringBuilder sb = new StringBuilder("concat("); | ||
| for (int i = 0; i < parts.length; i++) { | ||
| if (i > 0) { | ||
| sb.append(", \"'\", "); | ||
| } | ||
| sb.append("'").append(parts[i]).append("'"); | ||
| } | ||
| sb.append(")"); | ||
| return sb.toString(); | ||
| } | ||
|
|
||
| @Test | ||
| void checkColumnExists_singleColumn() { | ||
| String column = "Name"; | ||
| String expectedXpath = "//table[@id='DataTables_Table_0']/thead/tr/th[normalize-space(.) = " + xpathLiteralForTest(column) + "]"; | ||
| doReturn(mockElementWithText(column)).when(elementFinder).findByXPath(expectedXpath); | ||
|
|
||
| ApplicationAssertion assertion = new ApplicationAssertion(elementFinder); | ||
|
|
||
| assertThatCode(() -> assertion.checkColumnExists(column)).doesNotThrowAnyException(); | ||
| verify(elementFinder).findByXPath(expectedXpath); | ||
| } | ||
|
|
||
| @Test | ||
| void checkColumnExists_multipleColumns() { | ||
| String col1 = "Name"; | ||
| String col2 = "Email"; | ||
|
|
||
| String xpath1 = "//table[@id='DataTables_Table_0']/thead/tr/th[normalize-space(.) = " + xpathLiteralForTest(col1) + "]"; | ||
| String xpath2 = "//table[@id='DataTables_Table_0']/thead/tr/th[normalize-space(.) = " + xpathLiteralForTest(col2) + "]"; | ||
|
|
||
| doReturn(mockElementWithText(col1)).when(elementFinder).findByXPath(xpath1); | ||
| doReturn(mockElementWithText(col2)).when(elementFinder).findByXPath(xpath2); | ||
|
|
||
| ApplicationAssertion assertion = new ApplicationAssertion(elementFinder); | ||
|
|
||
| assertThatCode(() -> assertion.checkColumnExists(col1, col2)).doesNotThrowAnyException(); | ||
| verify(elementFinder).findByXPath(xpath1); | ||
| verify(elementFinder).findByXPath(xpath2); | ||
| } | ||
|
|
||
| @Test | ||
| void checkColumnExists_columnWithBothQuotes() { | ||
| String col = "O'Hara \"Test\""; | ||
| String expectedXpath = "//table[@id='DataTables_Table_0']/thead/tr/th[normalize-space(.) = " + xpathLiteralForTest(col) + "]"; | ||
| doReturn(mockElementWithText(col)).when(elementFinder).findByXPath(expectedXpath); | ||
|
|
||
| ApplicationAssertion assertion = new ApplicationAssertion(elementFinder); | ||
|
|
||
| assertThatCode(() -> assertion.checkColumnExists(col)).doesNotThrowAnyException(); | ||
| verify(elementFinder).findByXPath(expectedXpath); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| app.url=https://team8-2022brno.herokuapp.com/ |
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.