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+ }
0 commit comments