Calabash not touching buttons properly after background - ruby

My environment: Xcode: 7.2.1
Simulator: iOS iPad Air 9.1
Calabash: 0.17.1
Currently, I'm having an issue with my iOS application not touching buttons correctly after I background my application. Here are the general cucumber steps where the issue happens:
When I send the app to the background for 2 seconds
And I skip logging in to MyApp
And I wait and wait
And I should see "Speed"
And I wait for 10 seconds
And I touch "Speed"
Here is the code for the sending the app to background step:
Given /^I send the app to the background for ([\d\.]+) second(?:s)?$/ do |num_seconds|
num_seconds = num_seconds.to_f
send_app_to_background(num_seconds)
end
Basically the touching hits a snag only after I send the app to background. If I take that step out, Calabash touches the button like expected. I included the step where it sees "Speed", just to make sure that Calabash can actually see the button, which it could, since it goes green for that step, as well as the waiting step. But on touching "Speed", Calabash goes into a state where it keeps trying to touch it, but since it doesn't, it hangs on that step indefinitely. I suspect this may be either be a Calabash or UIAutomation bug (https://github.com/calabash/calabash-ios/issues/836), since everything works as expected until or unless I send my app to background, but I wanted to be 100% sure, in case I'm doing something wrong that I'm not seeing.
Does anyone have any ideas as to what the issue may be?
Update:
According to https://groups.google.com/forum/#!topic/calabash-ios/NZAmTp6ckrk, sending app to background is still unimplemented, and when I check the code for send_app_to_background, it does look like it:
def send_app_to_background(secs)
raise 'Not implemented when running without instruments / UIA'
end
Does anyone have a way to work around this for their tests? Running this on a physical device is not an option for me, it has to be done with a simulator.
Update:
Following https://github.com/calabash/calabash-ios/issues/556, I changed sending the app to background code to follow a workaround:
Given /^I send the app to the background for ([\d\.]+) second(?:s)?$/ do |num_seconds|
num_seconds = num_seconds.to_f
uia_send_app_to_background(num_seconds)
end
And the implementation of uia_send_app_to_background is:
def uia_send_app_to_background(secs)
#uia_handle_command(:deactivate, secs)
#Temporary workaround: https://github.com/calabash/calabash-ios/issues/556
js_deactivate = %Q[var x = target.deactivateAppForDuration(#{secs}); var MAX_RETRY=5, retry_count = 0; while (!x && retry_count < MAX_RETRY) { x = target.deactivateAppForDuration(#{secs}); retry_count += 1}; x]
uia(js_deactivate)
end
However, for me, this workaround doesn't seem to work. The app gets pushed to the background, but never goes back to foreground. When I stop that step in irb after a few minutes of waiting, I get this error:
When I send the app to the background for 2 seconds # features/step_definitions/common.rb:91
Could not parse response ''; the app has probably crashed (RuntimeError)
./features/step_definitions/common.rb:93:in `/^I send the app to the background for ([\d\.]+) second(?:s)?$/'
features/display_mapping_units_from_2630.feature:216:in `When I send the app to the background for 2 seconds'
Update
I tried these workaround steps, but touching after backgrounding still doesn't work, and I also tried this on 8.4 simulator, where it doesn't work either, which makes me suspect even more it's an Xcode 7+ issue that needs to be resolved:
When(/^I background the app$/) do
open_app_via_simctl("com.apple.mobilesafari")
sleep(2)
end
When(/^I launch the app$/) do
open_app_via_simctl("com.me.MyApp-cal")
sleep(2)
end
Steps:
And I background the app
And I wait
And I launch the app
And I wait
And I should see "Button1"
And I wait for 10 seconds
And I touch "Button1"
Calabash succeeds in seeing Button1, but when it tries to touch Button1, in 9.1 simulator, Calabash hangs indefinitely, trying to find the button, and in 8.4 simulator, I get an error right away that Calabash can't find the view "Button1".

Issue #836 was closed fixed in November. The Google forum post from 2013 and issue #556 is from 2014. Anything later than a couple months ago should be treated with suspicion.
Don't call the uia_send_app_to_background, that API is broken (by Apple). In general stick with the non-UIA API (don't call uia_* methods unless absolutely necessary).
Update Calabash to latest released version (0.18.1 as of today) and try your tests again.
$ be calabash-ios console
> start_test_server_in_background
# Can touch before background
> touch("view marked:'my view'")
> send_app_to_background(1)
# Can touch after resuming from background
> touch("view marked:'my view'")
The solutions below will not work. Your app will go to the background if you open another app. However, if you open your app with simctl, instruments will no longer have a connection to the application and gestures will fail.
When(/^I background the app$/) do
open_app_via_simctl("com.apple.mobilesafari")
sleep(2)
end
When(/^I launch the app$/) do
open_app_via_simctl("com.me.MyApp-cal")
sleep(2)
end

Related

How to disable notifications in Guard (Ruby)?

I can't find how to disable notifications when running Guard 2.4.4 with Ruby 2.5.1 on Linux within byobu (if that makes a difference).
The wiki says to put notification :off to disable notifications. If I put it in my Guardfile, it has no effect. If I put it in my ~/.guardrc file, I get a NoMethodError for notification. If I type notification :off at the guard prompt, it says notifications are off, but I still get them to show on every run.
They're annoying because they stay on screen for 10 seconds every time: I can never tell if it's from the latest run or if it's from a couple of runs ago when making small changes. They're fully opaque too so I have to wait for them to clear before I can click button on the area the notifications hide.
Any success in disabling Guard notifications?
There was a bug in 2.4.4, updating to 2.4.6 fixed the issue, and notification :off in my ~/.guard.rb (not ~/.guardrc, this one is to configure pry) is no longer ignored.
After getting here found full description on wiki
https://github.com/guard/guard/wiki/System-notifications
notification :off
is correct, but may also be put in a Guardfile

Applscript workflow not working from menu

I'm new to apple scripting. I'm trying to write a couple of scripts to let you skip forward/back 5 seconds in iTunes using a global hot key. Here's the script for jumping backwards:
tell application "iTunes"
if player state is stopped then return
try
set player position to (get player position) + (-5)
end try
end tell
It works just fine when running from within Automator and iTunes responds by rewinding 5 seconds. And I have successfully saved it as a service and it's sitting in /Library/Services.
However, when I run the script from the Services menu, nothing happens.
Any ideas?
A reboot of my computer fixed the issue.

QMediaPlayer doesn't change status at the end of file

I'm using Qt 5.1 (from here) on a MacBook Pro (OSX 10.8.4).
I have a movie player application consisting of little more than a QMediaPlayer and a QVideoWidget. Video from a local file URL plays fine.
I can connect and monitor the player's mediaStatusChanged and positionChanged signals, and increase the rate at which they're reported with QMediaPlayer::setNotifyInterval to several times per second.
This all seems to work fine except for one annoying thing:
When the player reaches the end of the file, it doesn't change status, it just reports the same position repeatedly. Only (and this is where things get strange) if I resize the window or minimise/maximise it, does it seem to "flush out" the expected status change to QMediaPlayer::EndOfMedia. Even just raising another application to cover the video app seems to flush the status change.
Any suggestions? Bug in QMediaPlayer? Me doing something wrong? Suggestions for workrounds?
Update: Now reported in Qt Jira.

Windows Phone XNA Games Hangs on Resume when Guide is Visible on WP7.x

My Windows Phone XNA game calls Guide.BeginShowKeyboardInput to get the user's name. While the Guide's input screen is shown, if the user presses the Home or Search (hardware) buttons, the game is deactivated as usual - but if the user then presses the Back (hardware) button, the game should resume but it doesn't. Instead it shows the "Resuming..." message until Windows Phone gives up trying to resume the game and kills the process.
Please note:
My app is failing Microsoft certification because of this problem - I really need to fix it!
This only happens in my game when the Guide input screen is shown - when it's not shown, the game
resumes properly after being deactivated.
This problem only occurs when the game is run on WP7.x (verified problem on WP7.5 and
WP7.8) - although the game seems to resume properly on WP8 devices.
I've created a blank XNA game project, called Guide.BeginShowKeyboardInput and tested it using WP7.x devices, and this problem-behavior doesn't occur.
I've tested the game without enabling Music & my Trial License manager (they use timers) and it still does this.
Exact same behavior occurs in the emulator (resume-failure on WP7.x emulators, works fine on WP8
emulator)
I used threads to asynchronously download content during the loading screen - but they already completed and exited.
I don't believe other threads are running, although this seems like
it could be a thread-blocking issue.
Any other ideas on what could be blocking the game from resuming when the Guide.IsVisible or how to debug/resolve this problem?
The solution to this issue was simply to NOT use SuppressDraw when dealing with any operation that passes control outside of the app, e.g. Launchers, Choosers and the Guide.
Have you tried calling "Guide.EndShowKeyboardInput" in either the Deactivating or closing events?
So that the guide is closed before the app suspends, you do get 10 seconds to suspend so this might be worth looking into.
If you want the guide to re-show on resume, then in your state saving code just have a flag and open the guide if it's set.

Debugging mobile software in the VS device emulator - app switching to background

I have this issue when debugging mobile apps on the emulator. When I press F5, the build starts, then the deploy, then the app pops up in the emulator.
Because this takes a minute or 2, I am checking my SO score and maybe ask a question while I wait, and the emulator is in the background. When I finally switch back to the emulator, it shows the start page, not my app.
I figured out that by pressing the back button I can bring the debugged application to the foreground, but still, I don't know what is pushing it into the background to begin with. Has anybody noticed this, and found a way to prevent it?
The default behavior in WinMo is that if the device has no activity for a certain period of time (set in Settings->Today->Items->Today Timeout), the Today screen will come to the fore. Check to see if that's what's happening (though I think the smallest interval is still larger than a couple minutes).

Resources