Auto Accept Alerts (OFF) sometimes automatically accepts alerts

1,277 views
Skip to first unread message

James Barker

unread,
Feb 14, 2014, 6:23:08 AM2/14/14
to appium-...@googlegroups.com
Hi there,

I have written a new a test that checks a certain pop up occurs on iOS start up. I have set the appium capability autoAcceptAlerts = false so I can check in my test that the app produces the alert. My test works most of the time, but sometimes appium still automatically accepts the alert automatically and my tests fails.

Has anyone else found this issue also?

I'm working with:
  • appium from the master branch
  • iOS Simulator 7.0.3.
thanks,
James.

Jonathan Lipps

unread,
Feb 14, 2014, 11:50:34 AM2/14/14
to James Barker, appium-...@googlegroups.com
what kind of popup is it?

--
http://appium.io
---
You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appium-discus...@googlegroups.com.
Visit this group at http://groups.google.com/group/appium-discuss.
For more options, visit https://groups.google.com/groups/opt_out.

Jonathan Lipps

unread,
Feb 14, 2014, 12:13:36 PM2/14/14
to James Barker, appium-...@googlegroups.com
Not sure why you'd be seeing inconsistent behavior. The code is pretty straightforward:

UIATarget.onAlert = function (alert) {
  if (alert.name() && alert.name().indexOf("attempting to open a pop-up") !== -1) {
    alert.defaultButton().tap();
  } else if (bootstrapSettings.autoAcceptAlerts) {
    alert.defaultButton().tap();
  }
  return true;
};

are you seeing in the logs that the bootstrap.js is getting the correct autoAcceptAlerts value every time?

On Feb 14, 2014, at 8:58 AM, James Barker <jarb...@gmail.com> wrote:

UIAlertView

Jonathan Lipps

unread,
Feb 14, 2014, 12:46:20 PM2/14/14
to James Barker, appium-...@googlegroups.com
I just committed some new code to master that defaults 'autoAcceptAlerts' to false. But it shouldn't change anything. There's no time at which that would have evaluated as true during session startup. It could be that the alert is popping up before uiautomation is running at all, however, and that's something we can't do anything about if that's the case.

On Feb 14, 2014, at 9:30 AM, James Barker <jarb...@gmail.com> wrote:

I did take a look at the code and saw that too. It is quite frustrating. The logs are also inconsistent.  Meaning they are different every run.

Because the alert is shown very quickly on startup, things are still initialising according to the appium logs. I though maybe there was a small window of opportunity where the alert could be some how automatically accepted.

James Barker

unread,
Feb 17, 2014, 6:25:32 AM2/17/14
to appium-...@googlegroups.com, James Barker
Hi Jonathan,

thank you for adding this change.  I re-ran the test and like you thought it made no difference.  I investigated the issue again by running the appium server and the application in the same terminal window so that both the appium and the application logs were shown in chronological order.  What I observed is the application begins and starts processing information such as an HTTP requests and creating alerts before Web Driver comes back after starting the application. This is expected. However I also noticed a "ScriptAgent handleAlert" log before the appium server log which sent the command to instruments to set autoAcceptAlerts to false. I'm not sure what the log "This script has no onAlert" means. Is it automatically accepting the alert? It happens at around the same time of the alert being accepted automatically. 

Here is the log produced by the combined appium and application log (I have put "APPLICATION LOG:" infront of the log produced by the the application and have highlighted some other parts of the log I believe may help shed some light in solving why the on app launch alerts still being automatically accepted) :

debug: Appium request initiated at /wd/hub/session
debug: Request received with params: {"desiredCapabilities":{"launch":true,"device":"ipad","browserName":"","version":"6.1","deviceName":"ipad","app":"http://10.65.80.36:8080/job/APP-Build-BDD-Artifacts/lastSuccessfulBuild/artifact/iphonesimulator7.0BDD.zip","newCommandTimeout":120,"autoAcceptAlerts":false}}
info: http://10.65.80.36:8080/job/APP-Build-BDD-Artifacts/lastSuccessfulBuild/artifact/iphonesimulator7.0BDD.zip downloaded to /var/folders/rl/b5zs9n8j5451f1bccvl2v04c0000gn/T/114117-419-1rf15tk/appium-app.zip
info: Unzipping /var/folders/rl/b5zs9n8j5451f1bccvl2v04c0000gn/T/114117-419-1rf15tk/appium-app.zip
info: Testing zip archive: /var/folders/rl/b5zs9n8j5451f1bccvl2v04c0000gn/T/114117-419-1rf15tk/appium-app.zip
info: Zip archive tested clean
info: Unzip successful
info: Using extracted app: /var/folders/rl/b5zs9n8j5451f1bccvl2v04c0000gn/T/114117-419-1rf15tk/MyAppMyApp.app
info: Creating new appium session adbc352a-7094-492b-be3d-7c11201827be
info: Removing any remaining instruments sockets
info: Cleaned up instruments socket /tmp/instruments_sock
info: Cleaning up any tracedirs
info: Cleaned up /Users/James/appium/instrumentscli0.trace
info: Parsed app Localizable.strings
info: Not setting locale
info: Setting iOS and app preferences
info: Starting iOS 7.* simulator log capture
info: Killing the simulator process and daemons
info: Cleaning app state.
info: No folders found to remove
debug: Launching device: iPad
info: Parsed app Info.plist
info: Wrote new app Info.plist with device type
info: Simulator is now ready.
debug: No device id or app, not installing to real device.
debug: Creating instruments
info: Instruments is at: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments
info: [INSTSERVER] Instruments socket server started at /tmp/instruments_sock
info: Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate /var/folders/rl/b5zs9n8j5451f1bccvl2v04c0000gn/T/114117-419-1rf15tk/MyApp.app -e UIASCRIPT /Users/James/appium/lib/devices/ios/uiauto/bootstrap.js -e UIARESULTSPATH /tmp/appium-instruments/
info: And extra without-delay env: {"DYLD_INSERT_LIBRARIES":"/Users/James/appium/build/iwd/InstrumentsShim.dylib","LIB_PATH":"/Users/James/appium/build/iwd"}
info: And launch timeout: 90000ms
info: [INST STDERR] 2014-02-17 10:12:27.932 ScriptAgent[1607:2e07] CLTilesManagerClient: initialize, sSharedTilesManagerClient

info: [INST STDERR] 2014-02-17 10:12:27.933 ScriptAgent[1607:2e07] CLTilesManagerClient: init

info: [INST STDERR] 2014-02-17 10:12:27.933 ScriptAgent[1607:2e07] CLTilesManagerClient: reconnecting, 0x963cbb0

*** APPLICATION LOG: HTTP REQUESTED AND PROCESSED BY MYAPP WHICH WILL CAUSE AN ALERT TO APPEAR ***
*** APPLICATION LOG: ALERT DISPLAYED ***

info: [INSTSERVER] Instruments is ready to receive commands
info: Instruments launched. Starting poll loop for new commands.
info: Pushing command to appium work queue: "au.bundleId()"
debug: Sending command to instruments: au.bundleId()
info: [INSTSERVER] Socket data received (15 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Sending command to instruments: au.bundleId()
info: [INST STDERR] 2014-02-17 10:12:29.604 ScriptAgent[1607:2e07] -[ScriptAgent handleAlert:]: script status is 2

info: [INST STDERR] 2014-02-17 10:12:29.605 ScriptAgent[1607:2e07] -[ScriptAgent handleAlert:]: This script has no onAlert

   (THIS IS NOT A LOG: Did the last log dismiss the alert automatically?)

info: [INSTSERVER] Socket data received (68 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":"com.mycompany.MyApp--bdd"}
info: Bundle ID for open app is com.mycompany.MyApp--bdd

info: Setting bootstrap config keys/values
info: Pushing command to appium work queue: "setBootstrapConfig: autoAcceptAlerts=false"
debug: Sending command to instruments: setBootstrapConfig: autoAcceptAlerts=false
info: [INSTSERVER] Sending command to instruments: setBootstrapConfig: autoAcceptAlerts=false

info: [INSTSERVER] Socket data received (68 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":"com.mycompany.MyApp--bdd"}
info: Setting initial orientation to PORTRAIT
info: Pushing command to appium work queue: "au.setScreenOrientation('PORTRAIT')"
debug: Sending command to instruments: au.setScreenOrientation('PORTRAIT')
info: [INSTSERVER] Sending command to instruments: au.setScreenOrientation('PORTRAIT')
info: [INSTSERVER] Socket data received (56 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":"PORTRAIT"}
info: Device launched! Ready for commands (will time out in 60secs)
info: Appium session started with sessionId adbc352a-7094-492b-be3d-7c11201827be
info: Setting command timeout to 120 secs
POST /wd/hub/session 303 30535ms - 9b
debug: Appium request initiated at /wd/hub/session/adbc352a-7094-492b-be3d-7c11201827be
debug: Request received with params: {}
info: Responding to client with success: {"status":0,"value":{"version":"7.0","webStorageEnabled":false,"locationContextEnabled":false,"browserName":"","platform":"MAC","javascriptEnabled":true,"databaseEnabled":false,"takesScreenshot":true,"launch":true,"device":"ipad","deviceName":"ipad","app":"http://10.65.80.36:8080/job/APP-Build-BDD-Artifacts/lastSuccessfulBuild/artifact/iphonesimulator7.0BDD.zip","newCommandTimeout":120,"autoAcceptAlerts":false},"sessionId":"adbc352a-7094-492b-be3d-7c11201827be"}
GET /wd/hub/session/adbc352a-7094-492b-be3d-7c11201827be 200 2ms - 566b

*** APPLICATION LOG:  IS NOW OPEN ACCORDING TO APPIUM/WEBDRIVER (As Selenium::WebDriver command has completed) ***

debug: Appium request initiated at /wd/hub/session/adbc352a-7094-492b-be3d-7c11201827be/element
debug: Request received with params: {"using":"xpath","value":"//text[contains(@text,\"Content Deleted\")]"}
info: Pushing command to appium work queue: "au.getElementByXpath('\\/\\/text[contains(@text,\\\"Content Deleted\\\")]')"
debug: Sending command to instruments: au.getElementByXpath('\/\/text[contains(@text,\"Content Deleted\")]')
info: [INSTSERVER] Sending command to instruments: au.getElementByXpath('\/\/text[contains(@text,\"Content Deleted\")]')
info: [INSTSERVER] Socket data received (50 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":7,"value":null}

info: Responding to client with error: {"status":7,"value":{"message":"An element could not be located on the page using the given search parameters."},"sessionId":"adbc352a-7094-492b-be3d-7c11201827be"}


TEST FAILED:  Can't find the Alert (As it has been dismissed automatically)

Jonathan Lipps

unread,
Feb 18, 2014, 1:24:05 PM2/18/14
to James Barker, appium-...@googlegroups.com
I think what this means is that your alert is popping up before the UIAutomation script has a chance to set an alert handler. I don't think there's any way around this other than intentionally delaying the time the alert pops up.

James Barker

unread,
Feb 18, 2014, 2:03:00 PM2/18/14
to Jonathan Lipps, appium-...@googlegroups.com

Hi Jonathan,

That worked. I delayed the notification and that solved the test from failing.

Thank you
James.

Reply all
Reply to author
Forward
0 new messages