1
1
import java .net .URL ;
2
2
import java .util .List ;
3
3
import java .net .MalformedURLException ;
4
+
5
+ import io .appium .java_client .MobileBy ;
4
6
import io .appium .java_client .android .AndroidDriver ;
7
+ import io .appium .java_client .android .AndroidElement ;
5
8
6
- import org .openqa .selenium .By ;
7
- import org .openqa .selenium .WebElement ;
8
9
import org .openqa .selenium .support .ui .ExpectedConditions ;
9
10
import org .openqa .selenium .support .ui .WebDriverWait ;
10
11
import org .openqa .selenium .remote .DesiredCapabilities ;
11
12
12
13
public class BrowserStackAndroid {
13
-
14
+
14
15
public static String accessKey = "BROWSERSTACK_USERNAME" ;
15
16
public static String userName = "BROWSERSTACK_ACCESS_KEY" ;
16
17
@@ -21,17 +22,17 @@ public static void main(String args[]) throws MalformedURLException, Interrupted
21
22
capabilities .setCapability ("device" , "Samsung Galaxy S7" );
22
23
capabilities .setCapability ("app" , "bs://<hashed app-id>" );
23
24
24
- AndroidDriver driver = new AndroidDriver (new URL ("https://" +userName +":" +accessKey +"@hub.browserstack.com/wd/hub" ), capabilities );
25
+ AndroidDriver driver = new AndroidDriver < AndroidElement > (new URL ("https://" +userName +":" +accessKey +"@hub.browserstack.com/wd/hub" ), capabilities );
25
26
26
- WebElement searchElement = new WebDriverWait (driver , 30 ).until (
27
- ExpectedConditions .elementToBeClickable (By . id ("Search Wikipedia" )));
27
+ AndroidElement searchElement = ( AndroidElement ) new WebDriverWait (driver , 30 ).until (
28
+ ExpectedConditions .elementToBeClickable (MobileBy . AccessibilityId ("Search Wikipedia" )));
28
29
searchElement .click ();
29
- WebElement insertTextElement = new WebDriverWait (driver , 30 ).until (
30
- ExpectedConditions .elementToBeClickable (By .id ("org.wikipedia.alpha:id/search_src_text" )));
30
+ AndroidElement insertTextElement = ( AndroidElement ) new WebDriverWait (driver , 30 ).until (
31
+ ExpectedConditions .elementToBeClickable (MobileBy .id ("org.wikipedia.alpha:id/search_src_text" )));
31
32
insertTextElement .sendKeys ("BrowserStack" );
32
33
Thread .sleep (5000 );
33
34
34
- List <WebElement > allProductsName = driver .findElements ( By . className ( "android.widget.TextView" ) );
35
+ List <AndroidElement > allProductsName = driver .findElementsByClassName ( "android.widget.TextView" );
35
36
assert (allProductsName .size () > 0 );
36
37
37
38
driver .quit ();
0 commit comments