9

My android app project programmatically starts system dialog to install trusted CA certificate:

Intent intent = KeyChain.createInstallIntent();
intent.putExtra(KeyChain.EXTRA_PKCS12, certificate);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

This code pops up the system dialog as showing below: enter image description here

Above thing is about my Android app project. Now, about test:

I am using Calabash to write automated acceptance tests for my project.

I know Calabash provids pre-defined step definitions. But those steps provide keywords to interact with app's UI components (e.g. input text, press button). I can't find how to use those pre-defined steps to test whether the system dialog is showing.

My questions:

Q1. How to use Calabash pre-defined step definitions to check the system dialog is showing? How to input text into the dialog?

Q2. If answer to Q1 is "it's impossible", then, how can I use Calabash to test it? Looks like I need to write my own Ruby function to test it? If so, how to write Ruby function to test this system dialog is showing & how to interact with the system dialog in test with Calabash?

Leem.fin
  • 40,781
  • 83
  • 202
  • 354

1 Answers1

0

You'll need to write your code for that. Assuming this is a default alert dialog:

This will assert if an view of the type AlertDialog is visible.

def check_if_dialog_open
   check_element_exists('*AlertDialog')
end

This will input some text to the first EditText if finds and hide the keyboard after.

def input_into_dialog(some_text)
    enter_text("android.widget.EditText *", some_text)
    hide_soft_keyboard
end

You could then write your own step for that:

Then(/^I check if my dialog is open and input some text$/) do
  check_if_dialog_open

  input_into_dialog('my text')

  sleep(STEP_PAUSE)
end

To input in that dialog you could query for an EditText visible.

It's just a matter of refining your queries. You can confirm if this is a default Android's AlertDialog using calabash console.

Learn more about console and query syntax here and check for more about Ruby API go here.

Rogério Peixoto
  • 2,176
  • 2
  • 23
  • 31
  • thanks. But how can I figure out what is the name of the system dialog? Or do you mean `*AlertDialog` can be used which can match any system dialog currently showing on the screen? – Leem.fin Jul 24 '16 at 08:19
  • Yes this was a generic example... But unless theres a hidden dialog it will work. If you want to improve need to you need to filter your query based on the calabash console output... Enter calabash console... Use query("*") to bring all the elements... Look for something that can identify your dialog... Like a text property and add it to the query. – Rogério Peixoto Jul 24 '16 at 13:13
  • I did some search, many people say that system UI elements are invisible to calabash...do I misunderstand something? – Leem.fin Aug 29 '16 at 15:36
  • Were you able to list it in Calabash console? – Rogério Peixoto Aug 29 '16 at 15:40
  • I use calabash-android query, I can only see app's UI elements, there is no system UI elements listed. – Leem.fin Aug 30 '16 at 08:46