Last active
November 3, 2020 12:26
-
-
Save ShamaUgale/552df64db476f26459a38e69fa02cfbe to your computer and use it in GitHub Desktop.
An example to demonstarte the geo location mocking with selenium 4
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
package com.devtools; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
import org.openqa.selenium.devtools.DevTools; | |
import org.openqa.selenium.devtools.emulation.Emulation; | |
import org.openqa.selenium.devtools.network.model.ConnectionType; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.Optional; | |
public class GeoMocking { | |
final static String PROJECT_PATH = System.getProperty("user.dir"); | |
public static void main(String[] args){ | |
System.setProperty("webdriver.chrome.driver", PROJECT_PATH + "/src/main/resources/chromedriver"); | |
ChromeDriver driver = new ChromeDriver(); | |
DevTools devTools = driver.getDevTools(); | |
devTools.createSession(); | |
devTools.send(Emulation.setGeolocationOverride( | |
Optional.of(35.8235), | |
Optional.of(-78.8256), | |
Optional.of(100))); | |
driver.get("https://mycurrentlocation.net/"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment