Create generic methods like:
public void zoomIn() {
zoomValue += zoomIncrement;
zoom(zoomValue);
}
public void zoomOut() {
zoomValue -= zoomIncrement;
zoom(zoomValue);
}
private static void zoom(int level) {
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.body.style.zoom='" + level + "%'");
}
And then call ZoomIn() and ZoomOut() wherever you want.
Complete sample code:
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import io.github.bonigarcia.wdm.WebDriverManager;
public class zoomTest {
public static WebDriver driver;
private int zoomValue = 100;
private int zoomIncrement = 20;
public void zoomIn() {
zoomValue += zoomIncrement;
zoom(zoomValue);
}
public void zoomOut() {
zoomValue -= zoomIncrement;
zoom(zoomValue);
}
private static void zoom(int level) {
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.body.style.zoom='" + level + "%'");
}
@Test
public void applyZoom() {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://testersdigest.blogspot.com/");
zoomIn();
zoomIn();
zoomIn();
zoomOut();
}
}
Comments
Post a Comment