Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uia('uia.alert().defaultButton().tap()') command fails with an error on 8.0 simulator #558

Closed
JaniJegoroff opened this issue Oct 14, 2014 · 4 comments

Comments

@JaniJegoroff
Copy link

uia('uia.alert().defaultButton().tap()') command fails on 8.0 simulator with an error. Same command works fine in 7.1 simulator.

Environment:
Calabash 0.11.0
run_loop 1.0.9
Xcode 6.0.1
iPad Retina (8.0 Simulator)

Steps to reproduce:

  1. Build app to iPad Retina 8.0 simulator
  2. Execute: DEBUG=1 DEVICE_TARGET='iPad Retina (8.0 Simulator)' calabash-ios console
  3. Execute: start_test_server_in_background
  4. Open alert view in your app
  5. Execute: uia('uia.alert().defaultButton().tap()')

Expected result:
5. Command is executed successfully and default button is tapped in alert view

Actual result:
5. Command fails with an error

Console trace:

janis-air:myApp janijegoroff$ DEBUG=1 DEVICE_TARGET='iPad Retina (8.0 Simulator)' calabash-ios console
Running irb...
irb(main):001:0> start_test_server_in_background

INFO: Using uia strategy: 'preferences'
Sending 'QUIT' to instruments process '78036'
Waiting for instruments '78036' to terminate
Preparation took 3.135206 seconds
{
                        :app => "/Users/janijegoroff/Library/Developer/Xcode/DerivedData/myApp-civuqgdjemtasdaqyhpsrgakmnyv/Build/Products/Calabash-iphonesimulator/myApp.app",
                       :args => [],
    :bundle_dir_or_bundle_id => "/Users/janijegoroff/Library/Developer/Xcode/DerivedData/myApp-civuqgdjemtasdaqyhpsrgakmnyv/Build/Products/Calabash-iphonesimulator/myApp.app",
                  :bundle_id => "my-bundle-id",
                     :device => "iphone",
              :device_target => "iPad Retina (8.0 Simulator)",
              :launch_method => :instruments,
             :launch_retries => 5,
                   :log_file => "/var/folders/66/62hrz8650r72_srksbdfwpjm0000gn/T/run_loop20141014-78698-x42grc/run_loop.out",
                  :no_launch => false,
                    :no_stop => false,
                      :reset => false,
                :results_dir => "/var/folders/66/62hrz8650r72_srksbdfwpjm0000gn/T/run_loop20141014-78698-x42grc",
          :results_dir_trace => "/var/folders/66/62hrz8650r72_srksbdfwpjm0000gn/T/run_loop20141014-78698-x42grc/trace",
                     :script => "/var/folders/66/62hrz8650r72_srksbdfwpjm0000gn/T/run_loop20141014-78698-x42grc/_run_loop.js",
                :sdk_version => nil,
                       :udid => "iPad Retina (8.0 Simulator)",
               :uia_strategy => :preferences,
                      :xcode => "6.0.1",
                 :xcode_path => "/Applications/Xcode601/Xcode.app/Contents/Developer"
}

### Starting on iPad Retina (8.0 Simulator) App: /Users/janijegoroff/Library/Developer/Xcode/DerivedData/myApp-civuqgdjemtasdaqyhpsrgakmnyv/Build/Products/Calabash-iphonesimulator/myApp.app ###
2014-10-14 11:18:45 +0100 xcrun instruments -w "iPad Retina (8.0 Simulator)" -D "/var/folders/66/62hrz8650r72_srksbdfwpjm0000gn/T/run_loop20141014-78698-x42grc/trace" -t "Automation" "/Users/janijegoroff/Library/Developer/Xcode/DerivedData/myApp-civuqgdjemtasdaqyhpsrgakmnyv/Build/Products/Calabash-iphonesimulator/myApp.app" -e UIARESULTSPATH /var/folders/66/62hrz8650r72_srksbdfwpjm0000gn/T/run_loop20141014-78698-x42grc -e UIASCRIPT /var/folders/66/62hrz8650r72_srksbdfwpjm0000gn/T/run_loop20141014-78698-x42grc/_run_loop.js  &> /var/folders/66/62hrz8650r72_srksbdfwpjm0000gn/T/run_loop20141014-78698-x42grc/run_loop.out
Launching took 7.274896 seconds
Calabash::Cucumber::Launcher: Launch Method instruments
Log file: /var/folders/66/62hrz8650r72_srksbdfwpjm0000gn/T/run_loop20141014-78698-x42grc/run_loop.out
irb(main):002:0> uia('uia.alert().defaultButton().tap()')
{
       "status" => "error",
        "value" => "VerboseError: Cannot perform action on invalid element: UIAElementNil from target.frontMostApp().alert().defaultButton()",
    "backtrace" => "tap@[native code]\neval code\neval@[native code]\nglobal code@file:///Users/janijegoroff/myApp/66BB437F-FB56-467A-9C62-34F50B6747FC/_run_loop.js:23632:27",
        "index" => 0
}
irb(main):003:0>

run_loop trace:

janis-air:myApp janijegoroff$ cat /var/folders/66/62hrz8650r72_srksbdfwpjm0000gn/T/run_loop20141014-78698-x42grc/run_loop.out
Waiting for device to boot...
2014-10-14 10:18:52 +0000 Default: OUTPUT_JSON:
{"status":"success","value":true,"index":0}
END_OUTPUT
2014-10-14 10:18:52 +0000 Default: **************
2014-10-14 10:19:12 +0000 Default: OUTPUT_JSON:
{"output":{"output":"on alert"},"last_index":0}
END_OUTPUT
2014-10-14 10:19:12 +0000 Default: **************
2014-10-14 10:19:23 +0000 Default: OUTPUT_JSON:
{"output":{"output":"alert: null"},"last_index":0}
END_OUTPUT
2014-10-14 10:19:23 +0000 Default: **************
2014-10-14 10:19:27 +0000 Default: index 0 is command: uia.alert().defaultButton().tap()
2014-10-14 10:19:27 +0000 Debug: Cannot perform action on invalid element: UIAElementNil from target.frontMostApp().alert().defaultButton()
2014-10-14 10:19:27 +0000 Default: OUTPUT_JSON:
{"output":{"output":"Failure: VerboseError: Cannot perform action on invalid element: UIAElementNil from target.frontMostApp().alert().defaultButton()  tap@[native code]\neval code\neval@[native code]\nglobal code@file:///Users/janijegoroff/myApp/66BB437F-FB56-467A-9C62-34F50B6747FC/_run_loop.js:23632:27"},"last_index":0}
END_OUTPUT
2014-10-14 10:19:27 +0000 Default: **************
2014-10-14 10:19:27 +0000 Default: Write result...
2014-10-14 10:19:27 +0000 Default: Check successful storage...
2014-10-14 10:19:27 +0000 Default: Storage succeeded: 0
janis-air:myApp janijegoroff$
@krukow
Copy link
Contributor

krukow commented Oct 22, 2014

I've reproduced this! My conclusion is that it is a bug in UIAutomation.

You can verify it by running this script which doesn't involve Calabash:

UIALogger.logMessage("Start");

UIATarget.onAlert = function(alertViewShown) {
    UIALogger.logMessage("Saw alert view with: " + alertViewShown.buttons().length + " buttons");
    return true;
};

target = UIATarget.localTarget();

app = target.frontMostApp();

UIALogger.logMessage("Tapping alert view button");

// activate your alert view
// manually or using UIAutomation

target.delay(5); //manual case



app = target.frontMostApp();

UIALogger.logMessage("app: "+app.bundleID()+ " "+ app.version());

UIALogger.logWarning("alert view: " + app.alert() + " default button "+app.alert().defaultButton());

UIALogger.logWarning("alert view: " + app.alert() + " cancel button "+app.alert().cancelButton());

output (notice that we can detect two buttons but default and cancel both return a nil element).

➜  XMSample git:(master) ✗ xcrun instruments -w "2471BD90-9A5E-484A-B31B-2B65CA39FBAE" -t "Automation" "com.xamarin.XMSample" -e UIASCRIPT alert-bug.js
2014-10-21 23:57:59 +0000 Default: Start
2014-10-21 23:57:59 +0000 Default: Tapping alert view button
2014-10-21 23:58:04 +0000 Default: app: com.xamarin.XMSample 1.0
2014-10-21 23:58:14 +0000 Warning: alert view: [object UIAElementNil] default button [object UIAElementNil]
2014-10-21 23:58:25 +0000 Warning: alert view: [object UIAElementNil] cancel button [object UIAElementNil]
Instruments Trace Complete (Duration : 30.579439s; Output : /Users/krukow/code/calabash-ios-xamarin-example/XMSample/instrumentscli8.trace)

My conclusion is that this is (another) bug in UIAutomation in 8.0 and above that.

Closing. Please re-open if you disagree.

@jmoody could you file an rdar?

@krukow krukow closed this as completed Oct 22, 2014
@jmoody
Copy link
Contributor

jmoody commented Oct 22, 2014

Re-opening until I file the radar - otherwise I will forget.

@janmichaelkolbe
Copy link

Hi! Have you already reported this to Apple?

@jmoody
Copy link
Contributor

jmoody commented Sep 21, 2015

Works in Xcode 7.

@jmoody jmoody closed this as completed Sep 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants