Skip to content

Commit 4a7bfb2

Browse files
authored
Merge pull request #16 from BrowserStackCE/sarrvesh-test
geo-location feature added
2 parents a4fa838 + be48e27 commit 4a7bfb2

7 files changed

Lines changed: 179 additions & 6 deletions

File tree

browserstack.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# =============================
44
# Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME and
55
# BROWSERSTACK_ACCESS_KEY as env variables
6-
userName: BROWSERSTACK_USERNAME
7-
accessKey: BROWSERSTACK_ACCESS_KEY
6+
userName: ${BROWSERSTACK_USERNAME}
7+
accessKey: ${BROWSERSTACK_ACCESS_KEY}
88

99
# ======================
1010
# BrowserStack Reporting
@@ -27,8 +27,9 @@ source: testng:appium-sample-sdk:v1.1
2727
# Step 1: Use BaseApp → mvn test -P sampleBaseAppTest → Tests PASS (Agent learns)
2828
# Step 2: Use SelfHealApp → mvn test -P sampleSelfHealAppTest → Tests PASS (healed!)
2929
#
30-
app: ./apps/BaseApp.apk # BaseApp — original selectors (tests PASS)
30+
# app: ./apps/BaseApp.apk # BaseApp — original selectors (tests PASS)
3131
# app: ./apps/SelfHealApp.apk # SelfHealApp — changed selectors (tests FAIL without self-heal)
32+
app: ./apps/browserstack-demoapp.apk
3233

3334
# =======================================
3435
# Platforms

pom.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,5 +219,28 @@
219219
</plugins>
220220
</build>
221221
</profile>
222+
<profile>
223+
<id>geolocation</id>
224+
<build>
225+
<plugins>
226+
<plugin>
227+
<groupId>org.apache.maven.plugins</groupId>
228+
<artifactId>maven-surefire-plugin</artifactId>
229+
<configuration>
230+
<argLine>
231+
-javaagent:${com.browserstack:browserstack-java-sdk:jar}
232+
</argLine>
233+
<systemPropertyVariables>
234+
<browserstack-local>false</browserstack-local>
235+
<browserstack.config>${env.BROWSERSTACK_CONFIG_FILE}</browserstack.config>
236+
</systemPropertyVariables>
237+
<suiteXmlFiles>
238+
<suiteXmlFile>src/test/resources/conf/runners/geolocation-testng.xml</suiteXmlFile>
239+
</suiteXmlFiles>
240+
</configuration>
241+
</plugin>
242+
</plugins>
243+
</build>
244+
</profile>
222245
</profiles>
223246
</project>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package com.browserstack.advance_use_cases;
2+
3+
import com.browserstack.test.suites.TestBase;
4+
import io.appium.java_client.MobileBy;
5+
import org.openqa.selenium.By;
6+
import org.openqa.selenium.WebElement;
7+
import org.testng.Assert;
8+
import org.testng.annotations.Test;
9+
10+
import java.util.List;
11+
12+
@Test
13+
public class GeoLocationTest extends TestBase {
14+
15+
@Test
16+
public void listAllOffersAfterLogin() throws InterruptedException {
17+
// Define platform-specific selectors for Offers menu item
18+
By offersMenuItem = mobileHelper.isAndroid() ?
19+
MobileBy.xpath("//*[@text = 'Offers']") :
20+
MobileBy.id("Offers");
21+
22+
// Step 1: Open hamburger menu
23+
driver.findElement(MobileBy.AccessibilityId("menu")).click();
24+
25+
// Step 2: Click on Sign In
26+
driver.findElement(MobileBy.AccessibilityId("nav-signin")).click();
27+
28+
// Step 3: Login with first dropdown values for username
29+
driver.findElement(MobileBy.AccessibilityId("username-input")).click();
30+
mobileHelper.selectFromPickerWheel(
31+
"//XCUIElementTypePickerWheel[@value='Accepted usernames are']",
32+
"fav_user"
33+
);
34+
35+
// Step 4: Login with first dropdown values for password
36+
driver.findElement(MobileBy.AccessibilityId("password-input")).click();
37+
mobileHelper.selectFromPickerWheel(
38+
"//XCUIElementTypePickerWheel[@value='Password for all users']",
39+
"testingisfun99"
40+
);
41+
42+
// Step 5: Click login button
43+
driver.findElement(MobileBy.AccessibilityId("login-btn")).click();
44+
45+
// Step 6: Open hamburger menu again
46+
driver.findElement(MobileBy.AccessibilityId("menu")).click();
47+
48+
// Step 7: Click on Offers
49+
driver.findElement(offersMenuItem).click();
50+
51+
// Step 8: Handle location permission if prompted
52+
Thread.sleep(2000); // Wait for permission dialog
53+
if (mobileHelper.isiOS()) {
54+
try {
55+
driver.findElement(By.id("Allow Once")).click();
56+
} catch (Exception e) {
57+
// Permission dialog may not appear
58+
}
59+
} else if (mobileHelper.isAndroid()) {
60+
try {
61+
driver.findElement(By.id("com.android.permissioncontroller:id/permission_allow_foreground_only_button")).click();
62+
} catch (Exception e) {
63+
// Permission dialog may not appear
64+
}
65+
}
66+
67+
// Step 9: Wait for offers to load
68+
Thread.sleep(3000);
69+
70+
// Step 10: List all offers
71+
List<WebElement> offers = driver.findElements(MobileBy.AccessibilityId("offer"));
72+
73+
System.out.println("=== OFFERS LIST ===");
74+
System.out.println("Total offers found: " + offers.size());
75+
76+
for (int i = 0; i < offers.size(); i++) {
77+
WebElement offer = offers.get(i);
78+
System.out.println("Offer " + (i + 1) + ": " + offer.getText());
79+
}
80+
System.out.println("===================");
81+
82+
// Verify that offers are displayed
83+
Assert.assertTrue(offers.size() > 0, "No offers found on the page");
84+
}
85+
}

src/test/java/com/browserstack/advance_use_cases/geo-location.java

Whitespace-only changes.

src/test/resources/conf/capabilities/browserstack.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# =============================
44
# Add your BrowserStack userName and acccessKey here or set BROWSERSTACK_USERNAME and
55
# BROWSERSTACK_ACCESS_KEY as env variables
6-
userName: BROWSERSTACK_USERNAME
7-
accessKey: BROWSERSTACK_ACCESS_KEY
6+
userName: ${BROWSERSTACK_USERNAME}
7+
accessKey: ${BROWSERSTACK_ACCESS_KEY}
88

99
# ======================
1010
# Organizing your tests
@@ -97,4 +97,4 @@ accessibilityOptions:
9797
bestPractice: false
9898
# Scanner processing timeout at end of test case (0-30 seconds, `default: 10`)
9999
# Optional numeric value
100-
scannerProcessingTimeout: 10
100+
scannerProcessingTimeout: 10
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# =============================
2+
# Set BrowserStack Credentials
3+
# =============================
4+
userName: ${BROWSERSTACK_USERNAME}
5+
accessKey: ${BROWSERSTACK_ACCESS_KEY}
6+
7+
# ======================
8+
# Organizing your tests
9+
# ======================
10+
buildName: GeoLocation-Test-Demo
11+
projectName: GeoLocation-Test-Demo
12+
buildIdentifier: '#${BUILD_NUMBER}'
13+
14+
testObservability: true
15+
framework: testng
16+
17+
app: ./apps/browserstack-demoapp.apk
18+
19+
# =======================================
20+
# Platforms (Browsers / Devices to test)
21+
# =======================================
22+
platforms:
23+
- deviceName: Google Pixel 7
24+
osVersion: 13.0
25+
platformName: android
26+
27+
28+
# =======================
29+
# Parallels per Platform
30+
# =======================
31+
parallelsPerPlatform: 1
32+
33+
# ==========================================
34+
# BrowserStack Local
35+
# ==========================================
36+
browserstackLocal: false
37+
geoLocation: IN
38+
39+
# ===================
40+
# Debugging features
41+
# ===================
42+
debug: true
43+
networkLogs: true
44+
consoleLogs: verbose
45+
46+
# Test observability and visual testing
47+
percy: true
48+
percyCaptureMode: auto
49+
50+
accessibility: true
51+
accessibilityOptions:
52+
wcagVersion: wcag21aa
53+
includeIssueType:
54+
bestPractice: false
55+
scannerProcessingTimeout: 10
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
3+
<suite name="GeoLocation Tests">
4+
<test name="GeoLocation Test Suite">
5+
<classes>
6+
<class name="com.browserstack.advance_use_cases.GeoLocationTest"/>
7+
</classes>
8+
</test>
9+
</suite>

0 commit comments

Comments
 (0)