calabash / calabash-ios

Calabash for iOS
Other
1.81k stars 369 forks source link

Unable to Check the Splash Screen displaying or not, after launching the app using calabash #1384

Open edrum opened 6 years ago

edrum commented 6 years ago

Automating the Test case(splash screen is visible or not & how much time it is displaying) using calabash. First I'm trying to verify whether the splash screen is displaying or not after launching the app. But i couldn't achieve. Please help me in doing only in calabash-ios or calabash-android

zedtux commented 6 years ago

Hey @edrum,

I had the same issue than you, and I solved it (well for now the CI isn't complaining) today with the following step definition :

Given(/^the app has launched$/) do
  wait_for(timeout: 120) do
    !query('*').empty?
  end

  wait_for(timeout: 120) do
    query("UILabel {text LIKE 'Loading *% (*)…'}").empty?
  end

  wait_for(timeout: 120) do
    query("UILabel marked:'Loading from localhost:8081...'").empty?
  end
end

Give it a try and le me know 😃

zedtux commented 6 years ago

I had to improve it a bit as I discovered that sometimes you can have another "Downloading JavaScript bundle" banner, and also I have a loading screen that I need to wait for.

To summarise my app workflow at boot:

  1. React Native splash screen
  2. My app loading screen (loading translations and more)
  3. Login screen

Here is my step that seems to be quite stable :

Given(/^the app has launched with locale (.*)$/) do |locale|
  # Wait for anything on the screen
  wait_for(timeout: 120) { !query('*').empty? }

  # Wait until the "Loading 0% (0/0)…" is gone if present
  loading_query = "UILabel {text LIKE 'Loading *% (*)…'}"
  unless query(loading_query).empty?
    wait_for(timeout: 120) { query(loading_query).empty? }
  end

  # Wait until the "Loading from localhost:8081..." is gone if present
  loading_from_query = "UILabel marked:'Loading from localhost:8081...'"
  unless query(loading_from_query).empty?
    wait_for(timeout: 120) { query(loading_from_query).empty? }
  end

  # Wait until the "Downloading JavaScript bundle 0% (0/0)…" is gone if present
  downloading_query = "UILabel {text LIKE 'Downloading JavaScript bundle *% (*)…'}"
  unless query(downloading_query).empty?
    wait_for(timeout: 120) { query(downloading_query).empty? }
  end

  @locale = locale
  @translations = load_translation_for(locale)
  if @translations.nil?
    screenshot_and_raise("No translations found for locale #{locale}.")
  end

  if @translations[@locale]['screens'].key?('loading')
    if @translations[@locale]['screens']['loading'].key?('title')
      # Wait until the "Loading" screen is gone if present
      loading_screen_title = @translations[@locale]['screens']['loading']['title']
      loading_screen_query = "UINavigationBar marked:'#{loading_screen_title}'"
      unless query(loading_screen_query).empty?
        wait_for(timeout: 120) { query(loading_screen_query).empty? }
      end
    else
      screenshot_and_raise("The #{@locale} translation is missing the " \
                           "'title' key for the loading screen")
    end
  else
    screenshot_and_raise("The #{@locale} translation is missing the 'loading'" \
                         ' key')
  end
end

If it's not clear, feel free to ask 🙂

edrum commented 6 years ago

Dear @zedtux, Thanks for your Reply. i think misunderstood somewhere, my point is, if i give send a command - _start_test_serverbackground, until it returns 'nill' the next command is not running. By that time, the splash screen is ending up & navigating to LOGIN screen.

zedtux commented 6 years ago

Oh, I maybe better understood.

Then, what I do is not using the start_test_server_background command but put some puts query('*') in the step the app has launched, so that during the boot step (so while start_test_server_background is running), you can get some details about what is on the screen.

Other than that, yeah, you can't inspect the splash screen.