1
1
/*
2
- * Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ * Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License").
5
5
* You may not use this file except in compliance with the License.
17
17
18
18
import io .appium .java_client .AppiumDriver ;
19
19
import io .appium .java_client .MobileElement ;
20
- import io .appium .java_client .pagefactory .AndroidFindBy ;
20
+
21
+ import java .util .List ;
21
22
22
23
/**
23
24
* A page representing the fixtures
24
25
*/
25
26
public class FixturesPage extends BasePage {
26
- /**
27
- * wifi value
28
- */
29
- @ AndroidFindBy (id = "wifi" )
30
- private MobileElement wifi ;
31
-
32
- /**
33
- * bluetooth value
34
- */
35
- @ AndroidFindBy (id = "bluetooth" )
36
- private MobileElement bluetooth ;
37
-
38
- /**
39
- * gps value
40
- */
41
- @ AndroidFindBy (id = "gps" )
42
- private MobileElement gps ;
43
-
44
- /**
45
- * nfc value
46
- */
47
- @ AndroidFindBy (id = "nfc" )
48
- private MobileElement nfc ;
49
27
50
28
public FixturesPage (AppiumDriver driver ) {
51
29
super (driver );
@@ -56,30 +34,53 @@ public FixturesPage(AppiumDriver driver) {
56
34
* @return wifi status
57
35
*/
58
36
public String getWifi () {
59
- return wifi . getText ( );
37
+ return getStatus ( "Wifi:" );
60
38
}
61
39
62
40
/**
63
41
*
64
42
* @return bluetooth status
65
43
*/
66
44
public String getBluetooth () {
67
- return bluetooth . getText ( );
45
+ return getStatus ( "Bluetooth:" );
68
46
}
69
47
70
48
/**
71
49
*
72
- * @return gps statsu
50
+ * @return gps status
73
51
*/
74
52
public String getGps () {
75
- return gps . getText ( );
53
+ return getStatus ( "GPS:" );
76
54
}
77
55
78
56
/**
79
57
*
80
58
* @return nfc status
81
59
*/
82
60
public String getNfc () {
83
- return nfc .getText ();
61
+ return getStatus ("NFC:" );
62
+ }
63
+
64
+ /**
65
+ * Helper function to retrieve the status of inputted radio name.
66
+ *
67
+ * @param radioName should be followed by a colon, for example: "NFC:"
68
+ * @return status of radio signal as a String
69
+ */
70
+ private String getStatus (String radioName ) {
71
+ driver .scrollTo (radioName );
72
+ List textViews = driver .findElementsByClassName ("android.widget.TextView" );
73
+
74
+ int idx ;
75
+
76
+ // Retrieve index of desired radio text view
77
+ for (idx = textViews .size () - 1 ; idx >= 0 ; idx --) {
78
+ if (((MobileElement ) textViews .get (idx )).getText ().equals (radioName )) {
79
+ break ;
80
+ }
81
+ }
82
+
83
+ // Desired radio status comes immediately after its name. For example: NFC: true
84
+ return ((MobileElement ) textViews .get (idx + 1 )).getText ();
84
85
}
85
86
}
0 commit comments