xcode-ui-testing

How to tap on a specific point using Xcode UITests

China☆狼群 提交于 2019-11-27 22:46:15
I want to use Xcode UI tests with the Fastlane Snapshot to make screenshots of the Cordova app. Basically, as my entire app is just a web view, all the Xcode UI test helper methods become irrelevant, and I just want to tap on specific points, e.g. tap(x: 10, y: 10) should produce a tap at the point {10px; 10px} . That's probably very simple, but I can't figure out how to do it. Thanks. You can tap a specific point with the XCUICoordinate API . Unfortunately you can't just say "tap 10,10" referencing a pixel coordinate. You will need to create the coordinate with a relative offset to an actual

How to select a picker view item in an iOS UI test in Xcode?

无人久伴 提交于 2019-11-27 22:39:31
I have a picker view with few items: "Red", "Green", "Yellow", "Black". In my UI test I need to select a specific item "Green" from it. I am using the XCTest UI testing APIs that were intruduced with Xcode 7. What I managed to do so far is to swipe the whole picker view up in the unit test. It is not ideal because it always changes the picker view to the bottom item (when swiping up). let app = XCUIApplication() app.launch() app.pickers.elementAtIndex(0).swipeUp() XCTAssert(app.staticTexts["Selected: Black"].exists) Another but very similar way of changing the picker view is to call

Xcode7 | Xcode UI Tests | How to handle location service alert?

…衆ロ難τιáo~ 提交于 2019-11-27 18:32:15
I am writing UI Test Cases for one one of my app using the XCUIApplication, XCUIElement and XCUIElementQuery introduced in Xcode7/iOS 9. I have hit a road block. One of the screens in test case requires iOS's Location Services. As expected the user is prompted about allowing use of location service with alert titled: Allow “App name” to access your location while you use the app? with Allow & Don't Allow buttons. Problem is or so it seems that since the alert is presented by OS itself it is not present in Application's element sub-tree. I have logged following: print("XYZ:\(app.alerts.count)")

XCUIElement - Obtain Image value

别等时光非礼了梦想. 提交于 2019-11-27 17:42:50
问题 I have an variable that's of type .Image and class XCUIElement . Something like this: var image = app.descendantsMatchingType(.Image).elementAtIndex(0) Is there a way I can extract the actual image so I can compare it to another image? I've tried caling the value method, but it returns a string. Casting it to a UIImage always fails. 回答1: I have had a conversation about this with the Apple Developer Tools evangelist recently. There is currently no way of accessing the actual image from an

Xcode UI Test example

做~自己de王妃 提交于 2019-11-27 12:48:58
I have just recently learned about Unit Testing in Xcode . Now I am trying out Xcode 7 and I see there is a new group for UI Tests when I create a new project. I watched the WWDC 2015 video and it was pretty good, but do you have a super simple example that I could go through myself? The video examples were a little too complex for me. Notes The answer below is my attempt to figure this out, but I welcome any better answers. I have read these SO questions about UI Testing in Xcode but they are different: docs , reloading , App vs UI , ViewController , multiple , values and properties , pre

How to detect if iOS app is running in UI Testing mode

独自空忆成欢 提交于 2019-11-27 11:55:16
问题 I would like my app to run special code (e.g. resetting its state) when running in UI Testing mode. I looked at environment variables that are set when the app is running from UI Testing and there aren't any obvious parameters to differentiate between the app running normally vs in UI Testing. Is there a way to find out? Two workarounds that I'm not satisfied with are: Set XCUIApplication.launchEnvironment with some variable that I later check in the app. This isn't good because you have to

UI Testing Failure - Neither element nor any descendant has keyboard focus on secureTextField

人盡茶涼 提交于 2019-11-27 09:10:25
问题 This is my case: let passwordSecureTextField = app.secureTextFields["password"] passwordSecureTextField.tap() passwordSecureTextField.typeText("wrong_password") //here is an error UI Testing Failure - Neither element nor any descendant has keyboard focus. Element: What is wrong? This is working nice for normal textFields , but problem arise only with secureTextFields . Any workarounds? 回答1: This issue caused me a world of pain, but I've managed to figure out a proper solution. In the

How do I mock network requests in Xcode UI tests while the tests are running?

荒凉一梦 提交于 2019-11-27 07:08:29
问题 We've got a suite of UI tests for our app written using KIF which I'd like to convert to use the new Xcode UI test framework. The app is a client of a Rest AI whose responses we're currently mocking by using NSURLProtocol to serve predefined JSON files in response to the GETs, POSTs, PUTs, etc... All the tests are defined using the data in these files, so I want to continue using them. The same endpoints on the server return different data at different points in the tests, so I can't mock

Xcode 7 UI Testing: Dismiss Push and Location alerts

社会主义新天地 提交于 2019-11-27 02:09:35
问题 I encountered a problem with Xcode 7 UI Testing. The app displays two alerts after my user logs in, the Request Location Alert and the Push Notifications Alert. Those notifications are shown one right after the other. The Location one appears first. I try to dismiss them automatically to start my tests. In order to do that, I add two UIInterruptionMonitor , the first one for the Location Alert and the second one for the Notification Push Alert. addUIInterruptionMonitorWithDescription(

How do I reset the application data after each test with Xcode 7 UI Testing?

百般思念 提交于 2019-11-27 00:55:23
问题 Apple introduced in Xcode 7 new UI Testing but I have a struggle whenever the tests launches the app, it starts with data that the application had before. It means tests cannot be independent and can be influenced by other tests. It is not possible to access user defaults and other data because the application that is running tests has no access to the bundle of the tested application. Scripts are also out of question because they can be run before or after testing. And there is no way how to