How to debug Siri extension in 'Type to Siri' mode? - ios

There is an option in iOS 11 global preferences: General/Accessibility/Type to Siri. If it is enabled, when you open Siri it shows you a text field into which you can type your request instead of saying it.
This option works fine when I run Siri with the device's home button. But when Siri is started through the Xcode's bebug session of my extension, the textfield is not shown and I need to speak to it.
Is there a way to force siri to be opened it the Type mode when started from the Xcode debugger?

I have found a workaround:
When you start Siri from the debugger, wait for it to show you the label 'What can I help you with?'. Then tap on this label and drag it to the bottom of the screen and release it there. The label will disappear and the textfield 'Type to Siri' will be shown.
For this trick to work you still have to enable General/Accessibility/Type to Siri option in iOS preferences.
Alternatively, if you want to debug your Siri extension with a specific fixed query, you can set it as a debug schema parameter. Click on your intent extension schema, click edit schema, Run debug > Info tab> Siri Intent Query

Related

UI testing of a UIKeyCommand added via keyCommands

I have freshly added a bunch of key commands (Cmd-..., etc) in the app by implementing
-(NSArray<UIKeyCommand*>*)keyCommands;
on a UIViewController subclass. Everything works wonderfully when manually tested in the app. The problem is how to UI test this in the iOS simulator.
I don't seem to be able invoke these commands using a method on XCUIElement. According to its documentation, there only seems to be one text input method on iOS
- (void)typeText:(NSString *)text;
with no (apparent) way to bless the input character with a key modifier flag (XCUIKeyModifierFlags) for Cmd, Alt, etc keys.
The method
- (void)typeKey:(NSString *)key modifierFlags:(XCUIKeyModifierFlags)flags;
appears to be macOS only. It would be a shame to provide these commands but not be able to test them in our UI testing suite.
Any ideas that can help me make some progress would be hugely welcome.
The keyboard input of the iphone emulator requires some settings. Make sure you currently select the simulator, and then set it in the upper left corner toolbar:
I/O -> Input -> Send Keyboard Input to Device
I/O -> Keyboard -> Connect Hardware Keyboard

Appium iOS Safari Open new tab, accept alerts and switch between two tabs

So I'm testing a web app for which I have to open a new tab, switch to it, do some input, than switch back to the first tab and this more than once.
I try to open the new tab this way:
((JavascriptExecutor) AppiumTestBase.getDriver()).executeScript("window.open('http://google.com', '_blank')");
This causes the following alert to appear:
But I'm not able to accept it through automation with Appium. Things that I have tried:
Using the following capabilities: "safariAllowPopups" and "autoAcceptAlerts"
Changing the according settings for safari in the iOS sim
.switchTo().alert().accept(); I also waited for the Popup.
Switchting to native context before accepting the popup
Clicking the pop up by name .findElement(By.name("Allow")).click();
What I have not tried:
Taping on the screen according to the pop-up coordinates. I didn't try this since I'm not sure on how to get the position of the "Allow" button.
And my other question is how would I switch between two tabs? I haven't tried anything yet, but research would suggest that I try it with window contexts.
Some other information:
Currently testing with a iPhoneSE iOS 9.3 Simulator, the solution should work for several configurations
Appium is on the most recent version
The class "AppiumTestBase"s only purpose is to set capabilities and initialize the AppiumDriver
Please try this cap after i change to this no popup from safari anymore
desired_capabilities=automationName:XCUITest,browserName:safari,platformName:iOS,platformVersion:11.1,deviceName:iPhone 6,nativeWebTap:True,safariIngoreFraudWarning:True
I tried the solution suggested by Atthaboon Sanurt, but it didn't help.
There was no alert, but the new window/tab didn't open either.
Here where the problem is reported:
https://github.com/appium/appium/issues/6864
So far it looks like there is no solution and plans to fix it.

Issue to type text in a webpage loaded in a UIWebView using UI Testing in Xcode

I'm struggling to type text in a UIWebView that is embedded in a native UIViewController. I loaded google in the web view, and I'm simply trying to enter "Hello". Recording suggests using app.typeText("Hello") but I keep getting the error
UI Testing Failure - Neither element nor any descendant has keyboard focus.
Any suggestions?
Project showing the issue, please test your possible answer by checking out this source by running from Terminal:
git clone git#bitbucket.org:Smaljaars/uitestingexample.git
UPDATE I found a workaround for typing text in a text field inside a web view:
func testWorkAroundForProblem() {
let app = XCUIApplication()
app.otherElements["Zoek"].tap() //this is language dependent! (no accessibility identifiers within webview)
// UGLY WORKAROUND FOR THE PROBLEM
let textToType = "XCTest slow search Google"
for character in textToType.characters {
if character == " " {
app.descendants(matching: .any)["space"].tap()
continue
}
app.descendants(matching: .any)[character.description.lowercased()].tap()
}
app.webViews.buttons["Google zoeken"].tap() //this is language dependent! (no accessibility identifiers within webview)
}
First make sure the search box has focused. The Accessibility Inspector shows that you should be able to access it via "Search". Oddly, Google marks the field as a combo box.
let app = XCUIApplication()
app.comboBoxes["Search"].tap()
app.typeText("Hello")
On the iOS Simulator menu, go to the Hardware dropdown and toggle the 'Connect Hardware Keyboard' setting.
This sometimes prevents UI tests from typing in text boxes.

Use existing custom keyboard code xcode

I have only custom keyboard code not full project code. I don't know how to integrate in my app or in new app. In custom keyboard some code is used that is not reachable for custom keyboards. Can any tell me how can i use this code. I know that i can make a new project with custom keyboard templCete but it doesn't work for me
In your current app add new keyboard extension as follows
go to file/New/target/Application Extension/Custom keyboard
give some name for keyboard.
Then in your app file list "KeyboardViewController" class added.
open that KeyboardViewController.m file and just replace that keyboard code which you have.
Before running app in simulator or device first go to device
Setting->General->keyboard->keyboards->add new keyboard
add your custom keyboard there
and run the app.

Dismiss alert on initial launch on iOS simulator

I'm working on the automated UI tests for my app and I'm having trouble when trying to set up the environment for running the tests. The plan is roughly this:
build the application
shutdown simulator if running
erase the simulator to make a clean install
install my app on the simulator
run UIAutomation tests
Everything is working except when the application is launched by instruments to execute the tests, the alert appears to ask if the user allows notifications. This is all as expected, but I can't find the way to get rid of the alert.
Things I have already tried:
creating onAlert as a first thing in my test script, in case it appears before the my alert callback is defined
delay the target by 5 seconds in case the tests actually run even before the UI of the app is visible in the simulator
I also went through all the permutations of the above that can be found on SO, I never get my onAlert callback invoked, no matter what I do. So another thing I tried was:
try dismissing the alert with applescript
The script I wrote:
tell application "System Events"
tell process "iOS Simulator"
set allUIElements to entire contents of window 1
repeat with anElement in allUIElements
try
log anElement
end try
end repeat
end tell
end tell
and it displays:
static text “MyApp” Would Like to Send You Notifications of window iOS Simulator - iPhone 6 - iPhone 6 / iOS 8.1 (12B411) of application process iOS Simulator
static text Notifications may include alerts, sounds, and icon badges. These can be configured in Settings. of window iOS Simulator - iPhone 6 - iPhone 6 / iOS 8.1 (12B411) of application process iOS Simulator
UI element 3 of window iOS Simulator - iPhone 6 - iPhone 6 / iOS 8.1 (12B411) of application process iOS Simulator
Looks like the buttons are placed inside the "UI element 3" but I can't retrieve any elements from inside it, let alone clicking on it. So I checked with Accessibility Manager:
It sits there as one of the children, the other ones are notification title and message. But when I go to that element, it is highlighted and I see this:
It is identified as generic element, it doesn't have any children...
The interesting thing is when I choose the OK button in the Accessibility Inspector, I can actually see it's a child of the window, yet it is never listed:
Can someone please shed some light on what is going on here? How can I press that button with Applescript?
If you are doing automation using Instrument, the you will need to register callback (onAlert) for performing any action on alerts.
But the problem in your case is that the alert appears before your script actually start executing and at that time no callback is registered for alert.
So if the alert can come with a delay of around 10 sec when you start application, then only it can be handled. But this can only be controlled through source code and not by your Automation code.
So only option which is left is you need to manual dismiss the alert once fresh application is installed
I am also facing same problem and found it to be a limitation of the tool
There are too many limitaion of this tool and thats why i shifted to UFT
I had a similar problem. I just wanted position of the last control on the alert. So I came up with following piece of code:
on get_simulator_last_object_rect(simulator_index)
tell application "System Events"
set ProcessList to (unix id of processes whose name is "iOS Simulator")
set myProcessId to item simulator_index of ProcessList
tell window 1 of (processes whose unix id is myProcessId)
-- Forcefully print the UI elements so that Accessibility hierarchy is built
UI elements
-- Then wait precisely to let the Accessibility view hierarchy is ready
delay 0.5
set lowest_label_lowest_position to 0
set _x to 0
set _y to 0
set _width to 0
set _height to 0
repeat with element in UI elements
set {_x, _y} to position of element
set {_width, _height} to size of element
set current_control_lowest_position to _y + _height
if current_control_lowest_position > lowest_label_lowest_position then set lowest_label_lowest_position to current_control_lowest_position - _height / 2
end repeat
return {{_x, _y}, {_width, lowest_label_lowest_position}}
end tell
end tell
end get_simulator_alert_ok_button_position
I have a desktop app to control my actions. I use this apple script in my Desktop app to get the frame of the last control. Now that I have the frame, I create a mouse event and perform click on the frame, after activating the simulator.
Although I have not yet tried, but I am pretty sure that you can create mouse events from apple script and perform click on the frame / center of the frame.
Hope this helps.
Thanks,
RKS

Resources