0

I'm in the middle of automating the Google Registration and I'm running into an issue...

As part of the registration, you need to sign into Wi-Fi and then wait until you are connected. After entering the Wi-Fi credentials, I do a wait in a while loop for the screen to change:

    print("Waiting for Wi-Fi to connect...")  
    while vc.findViewWithText("Select Wi-Fi") is not None:
        MonkeyRunner.sleep(5)
        vc.dump()    

    print("In Connecting...")
    while vc.findViewWithText("Connecting") is not None:
        MonkeyRunner.sleep(5)
        vc.dump()

    print("Connected")
    MonkeyRunner.sleep(1)

Sometimes this works, sometimes it doesn't. When it doesn't work, I get the following error:

Waiting for Wi-Fi to connect...
package="com.android.settings" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[332,1248][396,1312]" /><node index="1" text="Other network" class="android.widget.TextView" package="com.android.settings" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[426,1255][2196,1304]" /></node></node></node></node></node></node></node></node></node></node></hierarchy>

there are 65 views in this dump
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.FrameLayout id=id/no_id/1 ]   parent=None has attr=text == Select Wi-Fi
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.LinearLayout id=id/no_id/2 ]   parent=android.widget.FrameLayout has attr=text == Select Wi-Fi
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.FrameLayout id=id/no_id/3 ]   parent=android.widget.LinearLayout has attr=text == Select Wi-Fi
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.LinearLayout id=id/no_id/4 ]   parent=android.widget.FrameLayout has attr=text == Select Wi-Fi
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.LinearLayout id=id/no_id/5 ]   parent=android.widget.LinearLayout has attr=text == Select Wi-Fi
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.LinearLayout id=id/no_id/6 ]   parent=android.widget.LinearLayout has attr=text == Select Wi-Fi
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.FrameLayout id=id/no_id/7 ]   parent=android.widget.LinearLayout has attr=text == Select Wi-Fi
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.RelativeLayout id=id/no_id/8 ]   parent=android.widget.FrameLayout has attr=text == Select Wi-Fi
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.RelativeLayout id=id/no_id/9 ]   parent=android.widget.RelativeLayout has attr=text == Select Wi-Fi
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.LinearLayout id=id/no_id/10 ]   parent=android.widget.RelativeLayout has attr=text == Select Wi-Fi
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.TextView id=id/no_id/11 ]   parent=android.widget.LinearLayout has attr=text == Select Wi-Fi
__findViewWithAttributeInTree:  FOUND: View[ class=android.widget.TextView id=id/no_id/11 ]   parent=android.widget.LinearLayout
received 9 chars

Killed 


130621 11:22:03.616:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] Script terminated due to an exception
130621 11:22:03.616:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions]Traceback (most recent call last):
  File "/home/allen/projects/cts-scripts/4.2/cts-setup.py", line 824, in <module>
    main()
  File "/home/allen/projects/cts-scripts/4.2/cts-setup.py", line 802, in main
    do_registration(vc, device)
  File "/home/allen/projects/cts-scripts/4.2/cts-setup.py", line 703, in do_registration
    login_to_wifi(vc, device, wireless_ap_name, wireless_pw)
  File "/home/allen/projects/cts-scripts/4.2/cts-setup.py", line 783, in login_to_wifi
    vc.dump()    
  File "/home/allen/projects/AndroidViewClient/AndroidViewClient/src/com/dtmilano/android/viewclient.py", line 1780, in dump
    self.setViewsFromUiAutomatorDump(received)
  File "/home/allen/projects/AndroidViewClient/AndroidViewClient/src/com/dtmilano/android/viewclient.py", line 1530, in setViewsFromUiAutomatorDump
    self.__parseTreeFromUiAutomatorDump(received)
  File "/home/allen/projects/AndroidViewClient/AndroidViewClient/src/com/dtmilano/android/viewclient.py", line 1688, in _ViewClient__parseTreeFromUiAutomatorDump
    self.root = parser.Parse(receivedXml)
  File "/home/allen/projects/AndroidViewClient/AndroidViewClient/src/com/dtmilano/android/viewclient.py", line 988, in Parse
    parserStatus = parser.Parse(uiautomatorxml, 1)
  File "/home/allen/android/android-sdks/tools/lib/jython-standalone-2.5.4-rc1.jar/Lib/xml/parsers/expat.py", line 212, in Parse
xml.parsers.expat.ExpatError: Content is not allowed in prolog.

Am I using the API incorrectly or is there a MonkeyRunner/AndroidViewClient method I don't know about that can be used to check for the Wi-Fi connectivity state?

Android Noob
  • 3,271
  • 4
  • 34
  • 60
  • Not entirely sure if I fixed it BUT what i did was I moved the device.wake code above the MonkeyRunner.sleep(5) line. – Android Noob Jun 21 '13 at 01:22
  • Many times problems like this are due to timing. You can probably set **Stay awake** and don't have to worry about it. Though, there's something I don't undertand, the View is FOUND and then you receive the error, but the while loop should have been exited, so probably the error is in the next statement[s]. Enabling DEBUG and DEBUG_RECEIVED may help find out the cause. – Diego Torres Milano Jun 21 '13 at 03:10
  • Updated question. I'm getting the error after waiting for the screen to change after about 3-5 minutes. No idea what's causing this. My code never leaves the while loop if the connection is bad. If it does work, the rest of the automation works perfectly. – Android Noob Jun 21 '13 at 18:27

0 Answers0