├── .gitignore ├── .gitpod.yml ├── README.md ├── pom.xml └── src └── test └── com └── lambdatest └── EmulateGeolocation.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | /target/ 4 | .vscode/ 5 | 6 | # Log file 7 | *.log 8 | 9 | # BlueJ files 10 | *.ctxt 11 | 12 | # Mobile Tools for Java (J2ME) 13 | .mtj.tmp/ 14 | 15 | # Package Files # 16 | *.jar 17 | *.war 18 | *.nar 19 | *.ear 20 | *.zip 21 | *.tar.gz 22 | *.rar 23 | 24 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 25 | hs_err_pid* 26 | -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | # List the start up tasks. Learn more https://www.gitpod.io/docs/config-start-tasks/ 2 | tasks: 3 | - init: echo 'init script' # runs during prebuild 4 | command: mvn clean install exec:java -Dexec.mainClass="com.lambdatest.EmulateGeolocation" -Dexec.classpathScope=test -e 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # How to set geolocation for automation test in Java-selenium on LambdaTest 2 |  3 | 4 | ### Prerequisites 5 | 1. Install and set environment variable for java. 6 | * Windows - https://www.oracle.com/java/technologies/downloads/ 7 | * Linux - ``` sudo apt-get install openjdk-8-jre ``` 8 | * MacOS - Java should already be present on Mac OS X by default. 9 | 2 Install and set environment varibale for Maven. 10 | * Windows - https://maven.apache.org/install.html 11 | * Linux/ MacOS - [Homebrew](http://brew.sh/) (Easier) 12 | ``` 13 | install maven 14 | ``` 15 | ### Setting geolocation 16 | 17 | Option 1: To set geolocation, you can utilise the 'geolocation' capability like so: 18 | ```Java 19 | ltOptions.put("geoLocation", "US"); 20 | ``` 21 | Option 2: To set geolocation, you can use `devTools` and `Emulation.setGeolocationOverride` like so: 22 | 23 | ```java 24 | // setGeolocationOverride() takes input lattitude, longitude and accuracy as 25 | // parameters. 26 | devTools.send(Emulation.setGeolocationOverride(Optional.of(28.622409), 27 | Optional.of(77.364925), 28 | Optional.of(1))); 29 | ``` 30 | 31 | ### Run your First Test 32 | 1. Clone the Java-Selenium-Sample repository. 33 | ``` 34 | git clone https://github.com/LambdaTest/java-selenium-sample.git 35 | ``` 36 | 2. Next get into Java-Selenium-Sample folder, and import Lamabdatest Credentials. You can get these from lambdatest automation dashboard. 37 |
38 | For Linux/macOS:: 39 | 40 | ``` 41 | export LT_USERNAME="YOUR_USERNAME" 42 | export LT_ACCESS_KEY="YOUR ACCESS KEY" 43 | ``` 44 |
45 | For Windows:
46 |
47 | ```
48 | set LT_USERNAME="YOUR_USERNAME"
49 | set LT_ACCESS_KEY="YOUR ACCESS KEY"
50 | ```
51 | Step 3. You may also want to run the command below to check for outdated dependencies. Please be sure to verify and review updates before editing your pom.xml file as they may not be compatible with your code.
52 | ```
53 | mvn versions:display-dependency-updates
54 | ```
55 | Step 4. Run single test.
56 | ```
57 | mvn clean install exec:java -Dexec.mainClass="com.lambdatest.EmulateGeolocation" -Dexec.classpathScope=test -e
58 | ```
59 |
60 | ## About LambdaTest
61 |
62 | [LambdaTest](https://www.lambdatest.com/) is a cloud based selenium grid infrastructure that can help you run automated cross browser compatibility tests on 2000+ different browser and operating system environments. LambdaTest supports all programming languages and frameworks that are supported with Selenium, and have easy integrations with all popular CI/CD platforms. It's a perfect solution to bring your [selenium automation testing](https://www.lambdatest.com/selenium-automation) to cloud based infrastructure that not only helps you increase your test coverage over multiple desktop and mobile browsers, but also allows you to cut down your test execution time by running tests on parallel.
63 |
64 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |