-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f83c37
commit da81cc4
Showing
6 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
32 changes: 32 additions & 0 deletions
32
webdriver_java/src/main/java/pages/InfiniteScrollPage.java
This file contains 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,32 @@ | ||
package pages; | ||
|
||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.JavascriptExecutor; | ||
import org.openqa.selenium.WebDriver; | ||
|
||
public class InfiniteScrollPage { | ||
|
||
private WebDriver driver; | ||
By textBlocks = By.className("jscroll-added"); | ||
|
||
public InfiniteScrollPage(WebDriver driver){ | ||
this.driver = driver; | ||
} | ||
|
||
/** | ||
* Scrolls until paragraph with index specified is in view | ||
* @param index 1-based | ||
*/ | ||
public void scrollToParagraph(int index){ | ||
String script = "window.scrollTo(0, document.body.scrollHeight)"; | ||
var jsExecutor = (JavascriptExecutor)driver; | ||
|
||
while(getNumberOfParagraphsPresent() < index){ | ||
jsExecutor.executeScript(script); | ||
} | ||
} | ||
|
||
private int getNumberOfParagraphsPresent(){ | ||
return driver.findElements(textBlocks).size(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
webdriver_java/src/main/java/pages/LargeAndDeepDomPage.java
This file contains 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,22 @@ | ||
package pages; | ||
|
||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.JavascriptExecutor; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
|
||
public class LargeAndDeepDomPage { | ||
|
||
private WebDriver driver; | ||
private By table = By.id("large-table"); | ||
|
||
public LargeAndDeepDomPage(WebDriver driver){ | ||
this.driver = driver; | ||
} | ||
|
||
public void scrollToTable(){ | ||
WebElement tableElement = driver.findElement(table); | ||
String script = "arguments[0].scrollIntoView();"; | ||
((JavascriptExecutor)driver).executeScript(script, tableElement); | ||
} | ||
} |
This file contains 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
21 changes: 21 additions & 0 deletions
21
webdriver_java/src/test/java/javascript/JavaScriptTests.java
This file contains 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,21 @@ | ||
package javascript; | ||
|
||
import base.BaseTests; | ||
import org.testng.annotations.Test; | ||
|
||
public class JavaScriptTests extends BaseTests { | ||
|
||
/************************************************************ | ||
NOTE: We did not add assertions to these tests in the video | ||
************************************************************/ | ||
|
||
@Test | ||
public void testScrollToTable(){ | ||
homePage.clickLargeAndDeepDom().scrollToTable(); | ||
} | ||
|
||
@Test | ||
public void testScrollToFifthParagraph(){ | ||
homePage.clickInfiniteScroll().scrollToParagraph(5); | ||
} | ||
} |
This file contains 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