Swipe iphone home screen to left , XCode UI Testing - ios

Following is my piece of code . After the launch of application I click on the submit button which shows me an alert.
After I click ok on the UIAlertViewController I move to the home screen , and then I want to swipe left on the home screen.
Any idea how this can be done.
Any help will be appreciated
func testExample() {
let app = XCUIApplication()
app.buttons["Submit"].tap()
app.alerts["Please enable bluetooth"].buttons["OK"].tap()
XCUIDevice.sharedDevice().pressButton(XCUIDeviceButton.Home)
}

As of Xcode 8.0 you cannot interact with the UI outside of your application from the UI Test target. I filed a bug report http://www.openradar.me/radar?id=6180999608139776

Related

Swift: Touch not immediately registered for UIButtons located at bottom of UIViewController

I run into a strange behaviour I am not able to solve. If I place a UIButton at the bottom of the UIViewController of the Main Storyboard, touching it is not immediately registered. It takes about 0.5 seconds till the touch gets registered. You can see than from standard UIButtons when they change the text color. I don't have this issue with buttons anywhere else in the UIViewController.
All I did is adding a Vertical Stack View with 15 UIButtons to the Main View Controller of a new App. When I execute the App on an iPhone 6 or iPhone 8 (the actual devices), the lowest button behaves differently. Touching it doesn't change the text color immediately, while it does for all the other buttons.
Did anyone experience the same issue? Is there a way to solve this or did I just find a bug in the framework? I'm using Xcode 9.2 and deployment target is iOS 11.2.
Go to AppDelegate and try adding:
for gesture in self.window.gestureRecognizers {
gesture.delaysTouchesBegan = NO;
}
It will stop the system from checking to see if you are trying to open control centre.

Testing Action Extension with UI Tests

Is it possible to perform UI tests on Action Extension targets? I am unable to create a UI testing target with the Action Extension as the "Target to be Tested." I am trying to load the Action Extension from within Safari (or Photos, although Safari/both is prefered)
If I record my interactions I can get as far as:
app.icons["Safari"].tap()
I can then manually add:
XCUIDevice.sharedDevice().pressButton(.Home)
before the generated code, but it doesn't work as expected (the simulator is left on the home screen).
I have also tried:
UIApplication.sharedApplication().openURL(NSURL(string: "https://google.com")!)
but that also doesn't open Safari.
I'm not even sure if I'll be able to interact in an automated with with the Action Extension if it does get launched, but hopefully it'll be possible.
So, it's possible to switch apps with XCUITest, but it's undocumented. If you check out Facebook's WebDriverAgent, they did a header dump and made a helper for launching from the springboard. You can call:
XCUIApplication* safari = [[XCUIApplication alloc] initWithPrivatePath:nil bundleID:#"com.apple.safari"];
[safari launch];
And then interact with Safari just like you do your app. However, I've run into a similar problem where XCUITest won't actually launch the extension itself. Once open (i.e. you tap physically on the extension button while the test is running), the test runner works perfectly, and you can interact with your extension in the same context as your app. However, having the test runner tap to launch the extension does nothing. I've also got an Apple Dev Forum question going on this topic.
Update:
It turns out if you use the app to press the screen at the location of the button, the extension will load and you can interact with it! Note that the API for tapping a coordinate is very wonky. The x, y are multipliers of the frame of the thing that you created the coordinate from. Relevant sample code:
// app is your XCUIApplication
// In this case we are tapping in the horizontal middle and at the y coordinate 603 (this is for a 6+ screen size)
XCUICoordinate* coordinateOfRowThatLaunchesYourExtension = [app coordinateWithNormalizedOffset:CGVectorMake(0.5, 603.0 / 736.0)];
[coordinateOfRowThatLaunchesYourExtension tap];
This will press the button for your extension in the action sheet, after Apple's extension picker has been invoked. For whatever reason / bug in XCUITest simply pressing your app in the action sheet doesn't work:
[app.sheets.staticTexts[#"MyApp"] tap];

Weird animations when changing NavigationItem prompt

I have these ViewControllers added in storyboard:
None is connected with a custom class, everything is from pure storyboard.
Video on iPhone simulator on iOS7
This only happens when using AutoLayout on iOS7.
Anyone else seen this?
Download sample project of problem
I think this problem occurs when view is getting autolayout and setting it size to main screen size. In iOS 7 navigation push animation come before view size is set so we can see that animating. Don't worry it works well in iOS 8.0 and later. For iOS 7.0 you can give size of view in viewDidLoad so it can adjust size before it appears.
Edit 2:
As someone mentionned in the comments, I am unable to reproduce the problem with your sample project. One thing I noticed though, is that your project is configured with a deployment target that is iOS 8.3. Here are the steps to fix that :
Step 1: Select your project in Xcode's Project Navigator.
Step 2: Make sure you select your project in the left column of the project editor and not the target
Step 3: Select the Build Settings tab
Step 4: Modify the iOS Deployment Target to iOS 7.1 or iOS 7.0 depending on which OS you are testing with.
Step 5: Build and run.
Hopefully this will help you out.
Edit:
Step1. Select your UIViewController with the label 14 and in the third tab of the right pane of Xcode, enter a Storyboard ID such as vc14.
Step2. Select your UIViewController with the label 12 and in the same tab, enter a custom class such as ViewController.
Step3. Remove the trigger segue action from your Button and replace it by a #IBAction in ViewController
Step4. Add this code to your #IBAction in ViewController :
#IBAction func push(sender: AnyObject) {
var vc14 = self.storyboard?.instantiateViewControllerWithIdentifier("vc14") as! UIViewController
vc14.view.layoutIfNeeded()
self.navigationController?.pushViewController(vc14, animated: true)
}
Explanation:
The weird animation is occurring because layout has never occurred before the segue pushes the UIViewController in the UINavigationController. iOS 7 didn't protect appropriately against such a scenario by manually calling layoutIfNeeded before entering an animation block and when the layout finally occurs, it triggers implicit animations. In the code sample I have given you, I manually trigger layout before pushing the ViewController on the stack in order to avoid this issue.
i think you Press ⌘T. so the Slow animation is start. Check the all Simulator you Use.
Debug->Slow Animation
I attach Image check it.

Cancel button from UIActionSheet doesn't appear after long press on phone number in UITextView

I have a problem with the devices that have less then 4 inch display. When pressing long tap on phone number in UITextView, the UIActionSheet that appears doesn't show the Cancel button. The issue is that the actionSheet does showInView, instead of showFromTabBar.
In a demo app, this issue doesn't reproduce. Need help!
Check that the option 'Full Screen at Launch' is checked on the Window in you MainWindow.xib.
I had a similar problem and others when updating for iPhone 5 screen. Apparently the 'Simulated metrics' of Window will be the actual metrics when launching (provided you have not checked 'Full Screen at Launch').
Apple actually has a Note about it in the UIWindow Class Reference:
... If you choose to create a window in Interface Builder, be sure to select the Full Screen at Launch option in the Attributes inspector so that the window is sized appropriately for the current device. ...

iOS 7: keyboard shows in UIKeyboardAppearanceLight when an app is opening from multitasking screen

I've noticed an issue with the keyboard in ios 7, and I'm not sure if I'm doing something wrong.
Here's a simple scenario which replicates the issue on a blank xcode 5 project:
When you tap on a textfield added using interface builder (with keyboard appearance set to dark), the correct (dark) keyboard appears.
If you then resign the responder (add a button or something for that) > press the home button to get to home screen > double press the homebutton to get to the multitasking selection screen > tap on the app > tap on the textfield > it shows up the Light keyboard for a second, and then it draws the dark keyboard.
So is this an iOS bug or could it be something on my end?

Resources