How to deal with custom system alerts

Hello,
In my tested app there is pop up of the system where I have dialer and than I have two lines in my pop up :

  1. call to “number”
  2. cancel
    also there is pop up that comes from bluethooth that wants to pair with my device and the options there are :
  3. pair
  4. cancel
    How to handke these two pop ups?
    and also I tried in the first pop up to click on “call” and I managed to do these in while loop (with no connection to alerts) does it mean something that that is not a system pop up because finally it was managed to click?
  • Platform = iOS
  • Appium version: 1.21
  • Real Device
  • Client langauage : JAVA
  • OS = MAC

Thanks

You can always identify an alert from iOS by the presence of an ‘XCUIElementTypeAlert’ element. Once you’ve identified it as an alert, treat it like any other screen, identify it by either text or accessibility id, and then interact with it. For example you may want to have a test where you ‘cancel’ the call. In that case you would:

  1. Identify that you are on an alert screen
  2. Identify which alert screen
  3. Interact with the screen according to the test
  4. Move on to next screen

@wreed Thank you, and how do I move to the alert? because I tried the approach that you offer and sometimes it succed and sometimes not (that why I use for loop)

The alert should be on top when it shows. Maybe you are moving too fast? Try an implicit wait:

https://appium.io/docs/en/commands/session/timeouts/implicit-wait/

@wreed I see the alert and it’s on top, there is need to move to element (to the alert)?
I saw post that wait for the alert here

Sorry if I’m not being clear, I’m going to reference some code that might help. Once you’ve identified that you have an alert, then you need to do something like this (in Java):

driver.SwitchTo().Alert().Accept();

You may want to create a method like this one: Alert Method
^^^Very similar to @Aleksei’s code that you referenced above.

Or if you are using Page Object model, then create a class that represents the alert and can make decisions based on elements found in the alert (like the text).

Thank you @wreed , I did something simmilar where I send to the method (it’s Page Object Model) the element to click on it and click on it.
so questions:

  1. do I need to tap on it or click on it?
  2. after I click / tap on the alert, and let’s say the alert is gone, do I need to switch the driver back to the main app or its move automaticly?

These are good questions that I haven’t thought about in a long time. Let me answer in order:

  1. I have never used the ‘tap’ feature in Appium. My work is mostly in iOS, and I only use click so I would think that would be the way to go. Edited to add: Actually, you don’t need to use ‘click’ or ‘tap’. The ‘Alert().accept()’ (or ‘Alert().dismiss()’) will take care of that for you. It seems that may also get you out of alert mode. I took a look at the Appium github page but I couldn’t find exactly what happens there.
  2. I looked through my code for this. We do the in the constructor (Ruby) but we don’t ever switch back. I think once the alert is dismissed you automatically go back to the main driver.