Skip to content

Commit 7da3e25

Browse files
authored
Merge pull request #2352 from keys-github/saniyastage
Saniyastage
2 parents d7d973b + d451aa9 commit 7da3e25

File tree

6 files changed

+377
-381
lines changed

6 files changed

+377
-381
lines changed
73.1 KB
Loading
137 KB
Loading

docs/browserstack-to-lambdatest-migration-guide.md

Lines changed: 79 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ Capabilities generator let you configure the desired capabilities (or capabiliti
118118

119119
Optionally, you can also choose the Selenium version and other advanced options present in the Selenium Capabilities Generator. For this migration guide, we have only restricted to the three capabilities listed above.
120120

121+
To generate capabilities use [LambdaTest Capabilities Generator](https://www.lambdatest.com/capabilities-generator/) to define key automation testing parameters, such as browser, version, operating system, and additional test settings.
122+
123+
121124
For the migration, we have considered Java-based Selenium automation tests. Shown below are the screenshots of capabilities generator of BrowserStack and LambdaTest:
122125

123126
<Tabs className="docs__val">
@@ -127,13 +130,12 @@ For the migration, we have considered Java-based Selenium automation tests. Show
127130
```js
128131
MutableCapabilities capabilities = new MutableCapabilities();
129132
HashMap<String, Object> bstackOptions = new HashMap<String, Object>();
130-
capabilities.setCapability("browserName", "Chrome");
133+
capabilities.setCapability("browserName", "Safari");
131134
bstackOptions.put("os", "OS X");
132135
bstackOptions.put("osVersion", "Tahoe");
133-
bstackOptions.put("browserVersion", "latest");
136+
bstackOptions.put("browserVersion", "26.0");
134137
bstackOptions.put("userName", "YOUR_USERNAME");
135138
bstackOptions.put("accessKey", "YOUR_ACCESS_KEY");
136-
bstackOptions.put("consoleLogs", "info");
137139
capabilities.setCapability("bstack:options", bstackOptions);
138140
```
139141

@@ -142,9 +144,9 @@ capabilities.setCapability("bstack:options", bstackOptions);
142144
<TabItem value="android" label="LambdaTest Capabilities" default>
143145

144146
```js
145-
ChromeOptions browserOptions = new ChromeOptions();
146-
browserOptions.setPlatformName("Windows 10");
147-
browserOptions.setBrowserVersion("dev");
147+
SafariOptions browserOptions = new SafariOptions();
148+
browserOptions.setPlatformName("MacOS Tahoe");
149+
browserOptions.setBrowserVersion("26");
148150
HashMap<String, Object> ltOptions = new HashMap<String, Object>();
149151
ltOptions.put("username", "<your_username>");
150152
ltOptions.put("accessKey", "<your_access_key>");
@@ -156,7 +158,6 @@ browserOptions.setCapability("LT:Options", ltOptions);
156158

157159
</Tabs>
158160

159-
To generate capabilities use [LambdaTest Capabilities Generator](https://www.lambdatest.com/capabilities-generator/) to define key automation testing parameters, such as browser, version, operating system, and additional test settings.
160161

161162

162163

@@ -171,12 +172,14 @@ The Capabilities Generator allows you to configure the required desired capabili
171172

172173
With Selenium 3, the core capabilities remain:
173174

174-
* Browser Name (e.g., Chrome, Firefox, Edge)
175-
* Browser Version
176-
* Operating System / Platform
175+
* Desired browser
176+
* Desired browser version
177+
* Desired platform (or operating system)
177178

178179
Optionally, you may also configure Selenium versions or other advanced settings based on your test requirements. However, for this migration guide, we will primarily focus on the three fundamental capabilities listed above.
179180

181+
To generate capabilities for Selenium 3, you can use the [LambdaTest Capabilities Generator](https://www.lambdatest.com/capabilities-generator/) , which allows you to define essential automation parameters such as browser name, browser version, operating system, along with any additional test configurations required for execution.
182+
180183
Below are example capability representations from BrowserStack and LambdaTest to help you understand how to adapt your existing configuration during migration.
181184

182185

@@ -186,13 +189,12 @@ Below are example capability representations from BrowserStack and LambdaTest to
186189

187190
```js
188191
DesiredCapabilities caps = new DesiredCapabilities();
189-
caps.setCapability("browser", "Chrome");
192+
caps.setCapability("browser", "Safari");
190193
caps.setCapability("os", "OS X");
191194
caps.setCapability("os_version", "Tahoe");
192-
caps.setCapability("browser_version", "latest");
195+
caps.setCapability("browser_version", "26.0");
193196
caps.setCapability("browserstack.user", "YOUR_USERNAME");
194197
caps.setCapability("browserstack.key", "YOUR_ACCESS_KEY");
195-
caps.setCapability("browserstack.console", "info");
196198
```
197199

198200
</TabItem>
@@ -206,17 +208,16 @@ capabilities.setCapability("browserVersion", "26");
206208
HashMap<String, Object> ltOptions = new HashMap<String, Object>();
207209
ltOptions.put("username", "<your_username>");
208210
ltOptions.put("accessKey", "<your_access_key>");
211+
ltOptions.put("platformName", "MacOS Tahoe");
209212
ltOptions.put("visual", true);
210213
ltOptions.put("video", true);
211-
ltOptions.put("platformName", "MacOS Tahoe");
212214
capabilities.setCapability("LT:Options", ltOptions);
213215
```
214216

215217
</TabItem>
216218

217219
</Tabs>
218220

219-
To generate capabilities for Selenium 3, you can use the [LambdaTest Capabilities Generator](https://www.lambdatest.com/capabilities-generator/) , which allows you to define essential automation parameters such as browser name, browser version, operating system, along with any additional test configurations required for execution.
220221

221222

222223
## Hands On Guide - LambdaTest Migration
@@ -234,61 +235,65 @@ This test script performs a basic text validation on the website [LambdaTest eCo
234235

235236
```java
236237
// TextValidationTest.java
237-
238-
import org.openqa.selenium.By;
239238
import org.openqa.selenium.WebDriver;
240-
import org.openqa.selenium.chrome.ChromeOptions;
241239
import org.openqa.selenium.remote.RemoteWebDriver;
240+
import org.openqa.selenium.JavascriptExecutor;
241+
import org.openqa.selenium.safari.SafariOptions;
242242

243243
import java.net.URL;
244244
import java.util.HashMap;
245245

246246
public class TextValidationTest {
247247

248+
248249
public static void main(String[] args) throws Exception {
249250

250-
// ---------------- Authentication using Environment Variables ----------------
251-
String username = System.getenv("LT_USERNAME") == null ? "Your LT Username" : System.getenv("LT_USERNAME"); // If env variables are unavailable, you may hard-code credentials here.
252-
String authkey = System.getenv("LT_ACCESS_KEY") == null ? "Your LT AccessKey" : System.getenv("LT_ACCESS_KEY"); // If env variables are unavailable, you may hard-code credentials here.
251+
String username = System.getenv("LT_USERNAME") == null ?
252+
"Your LT Username" : System.getenv("LT_USERNAME");
253+
254+
String authkey = System.getenv("LT_ACCESS_KEY") == null ?
255+
"Your LT AccessKey\n" : System.getenv("LT_ACCESS_KEY");
253256

254257
String GRID_URL = "https://" + username + ":" + authkey + "@hub.lambdatest.com/wd/hub";
255258

256-
// ---------------- Selenium 4 Browser Options (Runs on LambdaTest Cloud) ----------------
257-
ChromeOptions browserOptions = new ChromeOptions();
258-
browserOptions.setPlatformName("Windows 10");
259-
browserOptions.setBrowserVersion("latest");
260259

260+
SafariOptions browserOptions = new SafariOptions();
261+
browserOptions.setPlatformName("MacOS Tahoe");
262+
browserOptions.setBrowserVersion("26");
261263
HashMap<String, Object> ltOptions = new HashMap<String, Object>();
262-
ltOptions.put("username", username);
263-
ltOptions.put("accessKey", authkey);
264+
ltOptions.put("username", "<your_username>");
265+
ltOptions.put("accessKey", "<your_access_key>");
264266
ltOptions.put("project", "Text Validation Test");
265267
ltOptions.put("build", "Text Validation Test Build");
266-
ltOptions.put("selenium_version", "4.0.0");
267268
ltOptions.put("w3c", true);
268-
269269
browserOptions.setCapability("LT:Options", ltOptions);
270270

271-
// ---------------- Start Remote WebDriver Session ----------------
272271
WebDriver driver = new RemoteWebDriver(new URL(GRID_URL), browserOptions);
273272

274-
// 1. Visit Page
275-
driver.get("https://ecommerce-playground.lambdatest.io/");
273+
try {
276274

277-
// 2. Text Validation
278-
String expectedText = "This is a dummy website for Web Automation Testing";
279-
boolean isTextPresent = driver.getPageSource().contains(expectedText);
275+
driver.get("https://ecommerce-playground.lambdatest.io/");
280276

281-
if (isTextPresent) {
282-
System.out.println("✔ Text validation PASSED");
283-
System.out.println("Found: " + expectedText);
284-
} else {
285-
System.out.println("✘ Text validation FAILED");
286-
}
277+
String expectedText = "This is a dummy website for Web Automation Testing";
278+
boolean isTextPresent = driver.getPageSource().contains(expectedText);
279+
280+
if (isTextPresent) {
281+
((JavascriptExecutor) driver).executeScript("lambda-status=passed");
282+
System.out.println("✔ Text validation PASSED");
283+
} else {
284+
((JavascriptExecutor) driver).executeScript("lambda-status=failed");
285+
System.out.println("✘ Text validation FAILED");
286+
}
287287

288-
// ---------------- End Session ----------------
289-
driver.quit();
288+
} catch (Exception e) {
289+
((JavascriptExecutor) driver).executeScript("lambda-status=pass");
290+
e.printStackTrace();
291+
} finally {
292+
driver.quit(); // 🔹 Correctly placed – runs even if test fails
293+
}
290294
}
291295
}
296+
292297
```
293298

294299
</TabItem>
@@ -297,81 +302,75 @@ public class TextValidationTest {
297302

298303
```java
299304
// TextValidationTest.java – Selenium 3 Configuration
300-
301-
import org.openqa.selenium.By;
302305
import org.openqa.selenium.WebDriver;
303306
import org.openqa.selenium.remote.DesiredCapabilities;
304307
import org.openqa.selenium.remote.RemoteWebDriver;
308+
import org.openqa.selenium.JavascriptExecutor;
305309

306310
import java.net.URL;
307311
import java.util.HashMap;
308312

309313
public class TextValidationTest {
310314

315+
311316
public static void main(String[] args) throws Exception {
312317

313-
// ================== LambdaTest Authentication via ENV Vars ==================
314-
String username = System.getenv("LT_USERNAME") == null ? "Your LT Username" : System.getenv("LT_USERNAME"); // If env variables are unavailable, you may hard-code credentials here.
315-
String authkey = System.getenv("LT_ACCESS_KEY") == null ? "Your LT AccessKey" : System.getenv("LT_ACCESS_KEY"); // If env variables are unavailable, you may hard-code credentials here.
316-
String GRID_URL = "https://" + username + ":" + authkey + "@hub.lambdatest.com/wd/hub";
318+
String username = System.getenv("LT_USERNAME") == null ?
319+
"Your LT Username" : System.getenv("LT_USERNAME");
320+
321+
String authkey = System.getenv("LT_ACCESS_KEY") == null ?
322+
"Your LT AccessKey" : System.getenv("LT_ACCESS_KEY");
317323

318-
// ================== Selenium 3 LambdaTest Capabilities ==================
324+
String GRID_URL = "https://" + username + ":" + authkey + "@hub.lambdatest.com/wd/hub";
325+
319326
DesiredCapabilities capabilities = new DesiredCapabilities();
320327
capabilities.setCapability("browserName", "Safari");
321328
capabilities.setCapability("browserVersion", "26");
322-
323329
HashMap<String, Object> ltOptions = new HashMap<String, Object>();
324-
ltOptions.put("username", username); // pulled dynamically
325-
ltOptions.put("accessKey", authkey); // pulled dynamically
330+
ltOptions.put("username", "<your_username>");
331+
ltOptions.put("accessKey", "<your_access_key>");
332+
ltOptions.put("platformName", "MacOS Tahoe");
326333
ltOptions.put("visual", true);
327334
ltOptions.put("video", true);
328-
ltOptions.put("platformName", "MacOS Tahoe");
329-
330-
331335
capabilities.setCapability("LT:Options", ltOptions);
332336

333-
// ================== Start Selenium 3 Remote WebDriver ==================
334337
WebDriver driver = new RemoteWebDriver(new URL(GRID_URL), capabilities);
335338

336-
// 1. Open Website
337-
driver.get("https://ecommerce-playground.lambdatest.io/");
339+
try {
338340

339-
// 2. Validate expected UI text
340-
String expectedText = "This is a dummy website for Web Automation Testing";
341-
boolean isTextPresent = driver.getPageSource().contains(expectedText);
341+
driver.get("https://ecommerce-playground.lambdatest.io/");
342342

343-
if (isTextPresent) {
344-
System.out.println("✔ Text validation PASSED");
345-
System.out.println("Found: " + expectedText);
346-
} else {
347-
System.out.println("✘ Text validation FAILED");
348-
}
343+
String expectedText = "This is a dummy website for Web Automation Testing";
344+
boolean isTextPresent = driver.getPageSource().contains(expectedText);
349345

350-
driver.quit();
346+
if (isTextPresent) {
347+
((JavascriptExecutor) driver).executeScript("lambda-status=passed");
348+
System.out.println("✔ Text validation PASSED");
349+
} else {
350+
((JavascriptExecutor) driver).executeScript("lambda-status=failed");
351+
System.out.println("✘ Text validation FAILED");
352+
}
353+
354+
} catch (Exception e) {
355+
((JavascriptExecutor) driver).executeScript("lambda-status=pass");
356+
e.printStackTrace();
357+
} finally {
358+
driver.quit(); // 🔹 Correctly placed – runs even if test fails
359+
}
351360
}
352361
}
353-
354362
```
355363

356364
</TabItem>
357365

358366
</Tabs>
359367

360368

361-
362-
363-
364-
365-
366-
367-
368-
369-
370369
**Result**
371370

372371
Visit LambdaTest Web Automation dashboard to view your test execution result.
373372

374-
<img loading="lazy" className="doc_img" src={require('../assets/images/browserstack-lambdatest-migration/Lambdatest-text-validation-result.png').default} alt="Lambdatest text validation result" width="1024" height="667" />
373+
<img loading="lazy" className="doc_img" src={require('../assets/images/browserstack-lambdatest-migration/lambdatest-safar-execution.png').default} alt="Lambdatest text validation result" width="1024" height="667" />
375374

376375

377376

0 commit comments

Comments
 (0)