├── .gitignore
├── .gitpod.yml
├── README.md
├── cloudbuild.yaml
├── dashboard.png
├── pom.xml
├── src
└── test
│ └── java
│ └── com
│ └── lambdatest
│ └── Timezone.java
└── timezone.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | /bin/
3 | .project
4 | .settings
5 | .theia
6 |
--------------------------------------------------------------------------------
/.gitpod.yml:
--------------------------------------------------------------------------------
1 | # List the ports you want to expose and what to do when they are served. See https://www.gitpod.io/docs/config-ports/
2 | ports:
3 | - port: 3000
4 | onOpen: open-preview
5 |
6 | # List the start up tasks. You can start them in parallel in multiple terminals. See https://www.gitpod.io/docs/config-start-tasks/
7 | tasks:
8 | - init: mvn install -Dsuite=timezone.xml # runs during prebuild
9 | command: echo 'Please check your test on https://automation.lambdatest.com/'
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Run Selenium Tests With TestNG On LambdaTest (Timezone setting Example)
2 |
3 | 
4 |
5 |
6 |
7 | Blog
8 | ⋅
9 | Docs
10 | ⋅
11 | Learning Hub
12 | ⋅
13 | Newsletter
14 | ⋅
15 | Certifications
16 | ⋅
17 | YouTube
18 |
19 |
20 |
21 |
22 |
23 | *Learn how to use TestNG framework to configure and run your Java automation testing scripts on the LambdaTest platform*
24 |
25 | [
](https://accounts.lambdatest.com/register)
26 |
27 | ## Table Of Contents
28 |
29 | * [Pre-requisites](#pre-requisites)
30 | * [Run Your First Test](#run-your-first-test)
31 | * [Parallel Testing With TestNG](#executing-parallel-tests-using-testng)
32 | * [Local Testing With TestNG](#testing-locally-hosted-or-privately-hosted-projects)
33 |
34 | ## Pre-requisites
35 |
36 | Before you can start performing Java automation testing with Selenium, you would need to:
37 |
38 | - Install the latest **Java development environment** i.e. **JDK 1.6** or higher. We recommend using the latest version.
39 |
40 | - Download the latest **Selenium Client** and its **WebDriver bindings** from the [official website](https://www.selenium.dev/downloads/). Latest versions of Selenium Client and WebDriver are ideal for running your automation script on LambdaTest Selenium cloud grid.
41 |
42 | - Install **Maven** which supports **JUnit** framework out of the box. **Maven** can be downloaded and installed following the steps from [the official website](https://maven.apache.org/). Maven can also be installed easily on **Linux/MacOS** using [Homebrew](https://brew.sh/) package manager.
43 |
44 | ### Cloning Repo And Installing Dependencies
45 |
46 | **Step 1:** Clone the LambdaTest’s Java-TestNG-Selenium repository and navigate to the code directory as shown below:
47 |
48 | ```bash
49 | git clone https://github.com/LambdaTest/Java-TestNG-Selenium
50 | cd Java-TestNG-Selenium
51 | ```
52 |
53 | You can also run the command below to check for outdated dependencies.
54 |
55 | ```bash
56 | mvn versions:display-dependency-updates
57 | ```
58 |
59 | ### Setting Up Your Authentication
60 |
61 | Make sure you have your LambdaTest credentials with you to run test automation scripts. You can get these credentials from the [LambdaTest Automation Dashboard](https://automation.lambdatest.com/build) or by your [LambdaTest Profile](https://accounts.lambdatest.com/login).
62 |
63 | **Step 2:** Set LambdaTest **Username** and **Access Key** in environment variables.
64 |
65 | * For **Linux/macOS**:
66 |
67 | ```bash
68 | export LT_USERNAME="YOUR_USERNAME"
69 | export LT_ACCESS_KEY="YOUR ACCESS KEY"
70 | ```
71 | * For **Windows**:
72 | ```bash
73 | set LT_USERNAME="YOUR_USERNAME"
74 | set LT_ACCESS_KEY="YOUR ACCESS KEY"
75 | ```
76 |
77 | ## Run Your First Test
78 |
79 | >**Test Scenario**: The sample [TestNGTodo1.java](https://github.com/LambdaTest/Java-TestNG-Selenium/blob/master/src/test/java/com/lambdatest/TestNGTodo1.java) tests a sample to-do list app by marking couple items as done, adding a new item to the list and finally displaying the count of pending items as output.
80 |
81 |
82 | ### Configuring Your Test Capabilities
83 |
84 | **Step 3:** In the test script, you need to update your test capabilities. In this code, we are passing browser, browser version, and operating system information, along with LambdaTest Selenium grid capabilities via capabilities object. The capabilities object in the above code are defined as:
85 |
86 | ```java
87 | DesiredCapabilities capabilities = new DesiredCapabilities();
88 | capabilities.setCapability("browserName", "chrome");
89 | capabilities.setCapability("version", "latest");
90 | capabilities.setCapability("platform", "Windows 10"); // If this cap isn't specified, it will just get the any available one
91 | capabilities.setCapability("build", "LambdaTestSampleApp");
92 | capabilities.setCapability("name", "LambdaTestJavaSample");
93 |
94 | caps.setCapability("timezone","UTC+03:00"); //Timezone capability to set the timezone
95 |
96 | ```
97 |
98 |
99 | You can generate capabilities for your test requirements with the help of our inbuilt [Desired Capability Generator](https://www.lambdatest.com/capabilities-generator/).
100 |
101 | ### Executing The Test
102 |
103 | **Step 4:** The tests can be executed in the terminal using the following command.
104 |
105 | ```bash
106 | mvn test -D suite=timezone.xml
107 | ```
108 |
109 | Your test results would be displayed on the test console (or command-line interface if you are using terminal/cmd) and on [LambdaTest automation dashboard](https://automation.lambdatest.com/build).
110 |
111 | ## Run Parallel Tests Using TestNG
112 |
113 |
114 | Here is an example `xml` file which would help you to run a single test on various browsers at the same time, you would also need to generate a testcase which makes use of **TestNG** framework parameters (`org.testng.annotations.Parameters`).
115 |
116 | ```xml title="testng.xml"
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 | ```
149 |
150 | ### Executing Parallel Tests Using TestNG
151 |
152 | To run parallel tests using **TestNG**, we would have to execute the below commands in the terminal:
153 |
154 | - For the above example code
155 | ```bash
156 | mvn test
157 | ```
158 | - For the cloned Java-TestNG-Selenium repo used to run our first sample test
159 | ```bash
160 | mvn test -D suite=parallel.xml
161 | ```
162 |
163 | ## Testing Locally Hosted Or Privately Hosted Projects
164 |
165 | You can test your locally hosted or privately hosted projects with LambdaTest Selenium grid using LambdaTest Tunnel. All you would have to do is set up an SSH tunnel using tunnel and pass toggle `tunnel = True` via desired capabilities. LambdaTest Tunnel establishes a secure SSH protocol based tunnel that allows you in testing your locally hosted or privately hosted pages, even before they are live.
166 |
167 | Refer our [LambdaTest Tunnel documentation](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/) for more information.
168 |
169 | Here’s how you can establish LambdaTest Tunnel.
170 |
171 | Download the binary file of:
172 | * [LambdaTest Tunnel for Windows](https://downloads.lambdatest.com/tunnel/v3/windows/64bit/LT_Windows.zip)
173 | * [LambdaTest Tunnel for macOS](https://downloads.lambdatest.com/tunnel/v3/mac/64bit/LT_Mac.zip)
174 | * [LambdaTest Tunnel for Linux](https://downloads.lambdatest.com/tunnel/v3/linux/64bit/LT_Linux.zip)
175 |
176 | Open command prompt and navigate to the binary folder.
177 |
178 | Run the following command:
179 |
180 | ```bash
181 | LT -user {user’s login email} -key {user’s access key}
182 | ```
183 | So if your user name is lambdatest@example.com and key is 123456, the command would be:
184 |
185 | ```bash
186 | LT -user lambdatest@example.com -key 123456
187 | ```
188 | Once you are able to connect **LambdaTest Tunnel** successfully, you would just have to pass on tunnel capabilities in the code shown below :
189 |
190 | **Tunnel Capability**
191 |
192 | ```java
193 | DesiredCapabilities capabilities = new DesiredCapabilities();
194 | capabilities.setCapability("tunnel", true);
195 | ```
196 |
197 | ## Tutorials 📙
198 |
199 | Check out our latest tutorials on TestNG automation testing 👇
200 |
201 | * [JUnit 5 vs TestNG: Choosing the Right Framework for Automation Testing](https://www.lambdatest.com/blog/junit-5-vs-testng/)
202 | * [How To Install TestNG?](https://www.lambdatest.com/blog/how-to-install-testng-in-eclipse-step-by-step-guide/)
203 | * [Create TestNG Project in Eclipse & Run Selenium Test Script](https://www.lambdatest.com/blog/create-testng-project-in-eclipse-run-selenium-test-script/)
204 | * [A Complete Guide for Your First TestNG Automation Script](https://www.lambdatest.com/blog/a-complete-guide-for-your-first-testng-automation-script/)
205 | * [How to Automate using TestNG in Selenium?](https://www.lambdatest.com/blog/testng-in-selenium/)
206 | * [How to Perform Parallel Test Execution in TestNG with Selenium](https://www.lambdatest.com/blog/parallel-test-execution-in-testng/)
207 | * [Creating TestNG XML File & Execute Parallel Testing](https://www.lambdatest.com/blog/create-testng-xml-file-execute-parallel-testing/)
208 | * [Speed Up Automated Parallel Testing in Selenium with TestNG](https://www.lambdatest.com/blog/speed-up-automated-parallel-testing-in-selenium-with-testng/)
209 | * [Automation Testing With Selenium, Cucumber & TestNG](https://www.lambdatest.com/blog/automation-testing-with-selenium-cucumber-testng/)
210 | * [How to Run JUnit Selenium Tests using TestNG](https://www.lambdatest.com/blog/test-example-junit-and-testng-in-selenium/)
211 | * [How to Group Test Cases in TestNG [With Examples]](https://www.lambdatest.com/blog/grouping-test-cases-in-testng/)
212 | * [How to Set Test Case Priority in TestNG with Selenium](https://www.lambdatest.com/blog/prioritizing-tests-in-testng-with-selenium/)
213 | * [How to Use Assertions in TestNG with Selenium](https://www.lambdatest.com/blog/asserts-in-testng/)
214 | * [How to Use DataProviders in TestNG [With Examples]](https://www.lambdatest.com/blog/how-to-use-dataproviders-in-testng-with-examples/)
215 | * [Parameterization in TestNG - DataProvider and TestNG XML [With Examples]](https://www.lambdatest.com/blog/parameterization-in-testng-dataprovider-and-testng-xml-examples/)
216 | * [TestNG Listeners in Selenium WebDriver [With Examples]](https://www.lambdatest.com/blog/testng-listeners-in-selenium-webdriver-with-examples/)
217 | * [TestNG Annotations Tutorial with Examples for Selenium Automation](https://www.lambdatest.com/blog/complete-guide-on-testng-annotations-for-selenium-webdriver/)
218 | * [How to Use TestNG Reporter Log in Selenium](https://www.lambdatest.com/blog/how-to-use-testng-reporter-log-in-selenium/)
219 | * [How to Generate TestNG Reports in Jenkins](https://www.lambdatest.com/blog/how-to-generate-testng-reports-in-jenkins/)
220 |
221 |
222 | ## Documentation & Resources :books:
223 |
224 |
225 | Visit the following links to learn more about LambdaTest's features, setup and tutorials around test automation, mobile app testing, responsive testing, and manual testing.
226 |
227 | * [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=Java-TestNG-Selenium)
228 | * [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=Java-TestNG-Selenium)
229 | * [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=Java-TestNG-Selenium)
230 |
231 | ## LambdaTest Community :busts_in_silhouette:
232 |
233 | The [LambdaTest Community](https://community.lambdatest.com/) allows people to interact with tech enthusiasts. Connect, ask questions, and learn from tech-savvy people. Discuss best practises in web development, testing, and DevOps with professionals from across the globe 🌎
234 |
235 | ## What's New At LambdaTest ❓
236 |
237 | To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/)
238 |
239 | ## About LambdaTest
240 |
241 | [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=Java-TestNG-Selenium) is a leading test execution and orchestration platform that is fast, reliable, scalable, and secure. It allows users to run both manual and automated testing of web and mobile apps across 3000+ different browsers, operating systems, and real device combinations. Using LambdaTest, businesses can ensure quicker developer feedback and hence achieve faster go to market. Over 500 enterprises and 1 Million + users across 130+ countries rely on LambdaTest for their testing needs.
242 |
243 | ### Features
244 |
245 | * Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments.
246 | * Real-time cross browser testing on 3000+ environments.
247 | * Test on Real device cloud
248 | * Blazing fast test automation with HyperExecute
249 | * Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale.
250 | * Smart Visual Regression Testing on cloud
251 | * 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more.
252 | * Automated Screenshot testing across multiple browsers in a single click.
253 | * Local testing of web and mobile apps.
254 | * Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems.
255 | * Geolocation testing of web and mobile apps across 53+ countries.
256 | * LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports
257 |
258 |
259 | [
](https://accounts.lambdatest.com/register)
260 |
261 |
262 |
263 | ## We are here to help you :headphones:
264 |
265 | * Got a query? we are available 24x7 to help. [Contact Us](support@lambdatest.com)
266 | * For more info, visit - [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=Java-TestNG-Selenium)
267 |
--------------------------------------------------------------------------------
/cloudbuild.yaml:
--------------------------------------------------------------------------------
1 | steps:
2 | - name: gcr.io/cloud-builders/docker
3 | args: ['run' , '-d', '--name=lt', '--network=cloudbuild', 'lambdatest/tunnel', '--user', '${_LT_USERNAME}', '--key', '${_LT_ACCESS_KEY}', '--tunnelName', 'GCloud', '--infoAPIPort', '15000','--load-balanced']
4 | - name: curlimages/curl
5 | args: ['-s', '--retry-connrefused', '--connect-timeout', '5', '--max-time', '5', '--retry', '30', '--retry-delay', '2', '--retry-max-time', '60', 'http://lt:15000/api/v1.0/info']
6 | - name: 'ubuntu'
7 | args: ['sleep', '20']
8 | - name: 'bash'
9 | args: ['ls']
10 | - name: 'maven'
11 | entrypoint: 'mvn'
12 | args: ['test', '-P', 'local']
13 | env:
14 | - 'LT_USERNAME=${_LT_USERNAME}'
15 | - 'LT_ACCESS_KEY=${_LT_ACCESS_KEY}'
16 |
--------------------------------------------------------------------------------
/dashboard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/praveenLT/java-testng-timezone-testing-sample/5d7605b750cc06f3c4acddb5c0b53aa512468061/dashboard.png
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | Java-TestNG-Selenium
6 | Java-TestNG-Selenium
7 | 0.0.1-SNAPSHOT
8 |
9 | Java-TestNG-Selenium/src
10 |
11 |
12 | Java-TestNG-Selenium/src
13 |
14 | **/*.java
15 |
16 |
17 |
18 |
19 |
20 | maven-compiler-plugin
21 | 3.7.0
22 |
23 | 10
24 |
25 |
26 |
27 | org.apache.maven.plugins
28 | maven-surefire-plugin
29 | 2.19.1
30 |
31 |
32 |
33 | test
34 |
35 |
36 |
37 |
38 |
39 |
40 | ${suite}
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | org.seleniumhq.selenium
50 | selenium-java
51 | 3.13.0
52 |
53 |
54 |
55 | org.testng
56 | testng
57 | 6.14.3
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/src/test/java/com/lambdatest/Timezone.java:
--------------------------------------------------------------------------------
1 | package com.lambdatest;
2 |
3 | import java.lang.reflect.Method;
4 | import java.net.MalformedURLException;
5 | import java.net.URL;
6 | import java.io.File;
7 |
8 | import org.openqa.selenium.By;
9 | import org.openqa.selenium.remote.DesiredCapabilities;
10 | import org.openqa.selenium.remote.RemoteWebDriver;
11 | import org.testng.Assert;
12 | import org.testng.ITestContext;
13 | import org.testng.annotations.AfterMethod;
14 | import org.testng.annotations.BeforeMethod;
15 | import org.testng.annotations.Test;
16 | import org.openqa.selenium.chrome.ChromeOptions;
17 |
18 | public class Timezone {
19 |
20 | private RemoteWebDriver driver;
21 | private String Status = "failed";
22 |
23 | @BeforeMethod
24 | public void setup(Method m, ITestContext ctx) throws MalformedURLException {
25 | String username = System.getenv("LT_USERNAME") == null ? "Your LT Username" : System.getenv("LT_USERNAME");
26 | String authkey = System.getenv("LT_ACCESS_KEY") == null ? "Your LT AccessKey" : System.getenv("LT_ACCESS_KEY");
27 | ;
28 | String hub = "@hub.lambdatest.com/wd/hub";
29 |
30 | DesiredCapabilities caps = new DesiredCapabilities();
31 | caps.setCapability("platform", "Windows 10");
32 | caps.setCapability("browserName", "Chrome");
33 | caps.setCapability("version", "latest");
34 | caps.setCapability("build", "Extension Test");
35 | caps.setCapability("name", m.getName() + " - " + this.getClass().getName());
36 | caps.setCapability("plugin", "git-testng");
37 | caps.setCapability("timezone","UTC+03:00"); //Timezone capability to set the timezone
38 |
39 | String[] Tags = new String[] { "Feature", "Falcon", "Severe" };
40 | caps.setCapability("tags", Tags);
41 |
42 | driver = new RemoteWebDriver(new URL("https://" + username + ":" + authkey + hub), caps);
43 |
44 | }
45 |
46 | @Test
47 | public void timezoneTest() throws InterruptedException {
48 |
49 | System.out.println("Loading Url");
50 |
51 | driver.get("https://webbrowsertools.com/timezone/");
52 |
53 |
54 | Status = "passed";
55 | Thread.sleep(15000);
56 |
57 | System.out.println("TestFinished");
58 |
59 | }
60 |
61 | @AfterMethod
62 | public void tearDown() {
63 | driver.executeScript("lambda-status=" + Status);
64 | driver.quit();
65 | }
66 |
67 | }
--------------------------------------------------------------------------------
/timezone.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------