-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add javascriptexecutor scrolling example
- Loading branch information
1 parent
7763ae2
commit 23e191a
Showing
13 changed files
with
201 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target/ | ||
*.iml |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
JavascriptExecutor-scrolling-demo/.idea/codeStyles/codeStyleConfig.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
JavascriptExecutor-scrolling-demo/.idea/jarRepositories.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.example</groupId> | ||
<artifactId>JavascriptExecutor-scrolling-demo</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<dependencies> | ||
<!-- https://mvnrepository.com/artifact/io.appium/java-client --> | ||
<dependency> | ||
<groupId>io.appium</groupId> | ||
<artifactId>java-client</artifactId> | ||
<version>7.3.0</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/org.testng/testng --> | ||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<version>7.1.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --> | ||
<dependency> | ||
<groupId>org.seleniumhq.selenium</groupId> | ||
<artifactId>selenium-java</artifactId> | ||
<version>3.141.59</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
33 changes: 33 additions & 0 deletions
33
JavascriptExecutor-scrolling-demo/src/test/java/BaseTest.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,33 @@ | ||
import org.openqa.selenium.JavascriptExecutor; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.chrome.ChromeDriver; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeMethod; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
public class BaseTest { | ||
WebDriver driver; | ||
JavascriptExecutor jse; | ||
|
||
@BeforeMethod | ||
public void setUp() { | ||
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/src/test/resources/chromedriver"); | ||
driver = new ChromeDriver(); | ||
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); | ||
driver.manage().window().maximize(); | ||
driver.get("file:///home/rv/Desktop/index.html"); | ||
|
||
jse = (JavascriptExecutor) driver; | ||
} | ||
|
||
@AfterMethod | ||
public void tearDown() { | ||
try { | ||
Thread.sleep(5000); | ||
} catch (InterruptedException e){ | ||
e.printStackTrace(); | ||
} | ||
driver.quit(); | ||
} | ||
} |
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,40 @@ | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebElement; | ||
import org.testng.annotations.Test; | ||
|
||
public class Demo extends BaseTest{ | ||
|
||
// scroll into a web page using specific number of pixels - vertical | ||
@Test | ||
public void verticalScrollBySpecificNumberOfPixels() { | ||
jse.executeScript("window.scrollBy(0, 1000)"); //1000 pixels - vertical | ||
} | ||
|
||
// scroll into a web page using specific number of pixels - horizontal | ||
@Test | ||
public void horizontalScrollBySpecificNumberOfPixels() { | ||
jse.executeScript("window.scrollBy(1000, 0)"); // 1000 pixels - horizontal | ||
} | ||
|
||
// scroll into a web page to reach certain visible web element | ||
@Test | ||
public void scrollToCertainElement() { | ||
WebElement paragraph = driver.findElement(By.id("final")); | ||
|
||
jse.executeScript("arguments[0].scrollIntoView();", paragraph); | ||
} | ||
|
||
// scroll into a web page to reach the bottom of the page | ||
@Test | ||
public void scrollToBottomPage() { | ||
jse.executeScript("window.scrollTo(0, document.body.scrollHeight)"); | ||
} | ||
|
||
// horizontal scrolling | ||
@Test | ||
public void horizontalScrolling() { | ||
WebElement rightElement = driver.findElement(By.xpath("/html/body/div/div[2]/p")); | ||
|
||
jse.executeScript("arguments[0].scrollIntoView();", rightElement); | ||
} | ||
} |
Binary file not shown.
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,13 @@ | ||
#main { | ||
width: 3000px; | ||
height: 2000px; | ||
} | ||
|
||
.general { | ||
color: blue; | ||
font-weight: bold; | ||
} | ||
|
||
#right { | ||
float:right; | ||
} |
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,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Scrolling Demo</title> | ||
<link rel="stylesheet" type="text/css" href="css/style.css"> | ||
<script src="js/script.js"></script> | ||
</head> | ||
<body> | ||
<div id="main"> | ||
<div class="general"><p>Welcome to the Scrolling demo!</p></div> | ||
<div id="right"><p>RIGHT</p></div> | ||
<div id="inject"></div> | ||
<div class="general"> | ||
<p>THIS IS THE FINAL PARAGRAPH</p> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
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,8 @@ | ||
document.addEventListener("DOMContentLoaded", function(event) { | ||
var myElement = document.getElementById("inject"); | ||
var text = "Lorem Ipsum "; | ||
|
||
for (var i = 0; i < 4000; i++) { | ||
myElement.innerHTML += text; | ||
} | ||
}); |