Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Mikey-San
Nov 3, 2005

I'm Edith Head!

modig posted:

Ohh ok, so I need to put it in a .mm file I guess. I'll mess with that later today, thanks.

You use .mm when you need Objective-C++. If you're just mixing some straight C into your Objective-C, .m is fine.

quote:

I thought functions had names like ImAFunctionAndITakeArg1:Arg2: etc.

This construct is known in Objective-C as a selector. It's known as such because it allows the runtime to select the code to execute; the method that will be called when the program runs is not determined until runtime.

You send a message to a receiver ("invoke/call a method") like so:

code:
[myObj setValue:@"foo" forKey:@"bar"];
At compile time, this gets converted into a call to a function named objc_msgSend. The arguments to the call include the object itself, the selector name, and all of the arguments you provided. The function looks like this:

code:
id objc_msgSend(id theReceiver, SEL theSelector, ...)
In the example, the selector name is the fully qualified string "setValue:ForKey:", colons included. Selectors actually have a special type once compiled, known as SEL. When you need to refer to a selector for some reason, you use the @selector() compiler directive. I'll just quote the documentation for SEL here, since I would just be rephrasing it:

ADC posted:

Method selectors are used to represent the name of a method at runtime. A method selector is a C string that has been registered (or “mapped“) with the Objective-C runtime.

Going back to the example, the code generated by the compiler is equivalent to (for our purposes here):

code:
objc_msgSend(myObj, @selector(setValue:forKey:), @"foo", @"bar");
At runtime, objc_msgSend resolves the selector to a method implementation, which is the actual executable code for the method being invoked.

Homework:

The Objective-C Programming Language
The Objective-C Runtime Programming Guide

Mikey-San fucked around with this message at 09:02 on Apr 22, 2011

Adbot
ADBOT LOVES YOU

Mikey-San
Nov 3, 2005

I'm Edith Head!

modig posted:

Thanks, still wrapping my head around the basics.

I admit that I was a little worried my reply was overkill. The most relevant part is the "construct" bit explaining the higher-level idea of a selector.

Once I started going, I couldn't stop . . .

Mikey-San
Nov 3, 2005

I'm Edith Head!

modig posted:

As far as memory management goes, the guidelines seem to be that I should release any object I own. What does it mean for me to own it? I'm guessing that if I call the alloc function directly, I probably own it. Also I guess any @property with retain counts. What else counts as me owning it?

You need to read the memory management documentation.

Memory Management Programming Guide

(It's generally not a good idea to attempt to summarize or restate them, so I prefer linking to them.)

Mikey-San
Nov 3, 2005

I'm Edith Head!

Toady posted:

Simply follow object ownership rules, which state that new/alloc/copy/mutableCopy return objects that you own

This isn't quite what the memory management rules say about new/alloc/copy/mutableCopy. The rule, as of this post, is:

ADC posted:

You take ownership of an object if you create it using a method whose name begins with “alloc”, “new”, “copy”, or “mutableCopy” (for example, alloc, newObject, or mutableCopy), or if you send it a retain message.

(Emphasis mine.)

The alloc/new/copy/mutableCopy bit used to be a little different, where the word "copy" anywhere in the method name signified a +1 ownership reference, but that is no longer the case. It's important to keep this in mind, because the clang static analyzer definitely does. ;)

quote:

and convenience constructors return objects you don't own.

This is definitely a misrepresentation of the rules. Being a convenience method, regardless of whether it is responsible for the construction of an object, is not relevant to whether or not it returns an object with a positive ownership reference. Just follow the contract.

edit: added link

edit: removed redundant -retainCount advice

Mikey-San fucked around with this message at 01:22 on Jun 2, 2011

Mikey-San
Nov 3, 2005

I'm Edith Head!
Ultimately, that just means the convience constructors you see provided by Apple's frameworks (e.g., stuff like +[NSArray arrayWith*:]) are following the fundamental rule, and don't start with the four horsemen (new/alloc/copy/mutableCopy). Otherwise, they wouldn't be very convenient! That doesn't make them special, per se, it just makes them well-named. :)

edit:

To be clear, I'm speaking strictly in terms of what you (in the royal sense, of course) should be most concerned with. I don't think I can come up with a single convenience constructor in Foundation, for example, that returns an object with a positive ownership reference. Those also follow the fundamental rule(s), so if you stick to that, you're golden. No need to consider whether it's a convenience method or not.

quote:

P.S. God can -release all the kittens he wants.

Just something that had been on my mind. Not a reply to you in particular!

Mikey-San fucked around with this message at 03:04 on Jun 2, 2011

Mikey-San
Nov 3, 2005

I'm Edith Head!

Toady posted:

It was a good line! Put it on a t-shirt in time for WWDC.

If only I had the time!

So, you're all going, riiiight? ;)

Mikey-San
Nov 3, 2005

I'm Edith Head!

Bob Morales posted:

I have two beginning Mac programming books, but neither of them cover dragging a file onto an app (the actual app, not the dock icon). I'm trying to do something where you could drag a URL from a browser's address bar onto a UIView of some sort (or a link, like if you dragged a torrent URL into a Torrent client, and it started downloading it automatically).

Where should I start?

Introduction to Drag and Drop

e:f,b

Mikey-San
Nov 3, 2005

I'm Edith Head!

lord funk posted:

Yesss. I don't think my wife understands why I want to watch videos of people giving powerpoint presentations, but I love these videos.

Tell her these are Keynote presentations. Totally better.

Mikey-San
Nov 3, 2005

I'm Edith Head!

quote:

code:
// Release the image now that we have a UIImageView that contains it.
[img release];

You don't own that image. Don't release it.

Mikey-San
Nov 3, 2005

I'm Edith Head!

McFunkerson posted:

I'm smashing my head against a wall trying to get a subview to draw and I just don't understand what I'm doing wrong.

I have subclassed NSView and have a subview I am trying to draw in that view. I know the subview works fine because if I do:
code:
-(void) drawRect: (NSRect)dirtyRect
{
    rect.size.width = 832;
    rect.size.height = 120;
    NSPoint point = { 0, 0 };
    rect.origin = point;
    TabloidProgressView *newJob = [[TabloidProgressView alloc] initWithFrame:rect];
    [self addSubview:newJob];
{

You should not add subviews in -drawRect: methods. This is not how the AppKit view drawing model is intended to work, and you will suffer performance penalties (and who knows how many other problems) by doing it. (Also, you're leaking a TabloidProgressView every single time you draw.)

If you want a view to be drawn, it should exist in your view hierarchy prior to the view attempting to draw itself.

Mikey-San
Nov 3, 2005

I'm Edith Head!
Here's the documentation you should read:

Introduction to View Programming Guide for Cocoa

Mikey-San
Nov 3, 2005

I'm Edith Head!

Small White Dragon posted:

EDIT: What's the "correct" way to release a CTFont? CFRelease?

The CTFont class documentation states it's derived from CFTypeRef, so absent a custom release function, CFRelease is the right way to release it.

Mikey-San fucked around with this message at 22:22 on Jul 24, 2011

Mikey-San
Nov 3, 2005

I'm Edith Head!

Martytoof posted:

Ah, fair enough.

I wonder if there is a way to deliver suggestions like this to Apple. It doesn't feel like something that ought to go into the Bug Reporter but I think that's actually exactly where it needs to be suggested.

Bug Reporter is the right place to file enhancement requests.

Mikey-San
Nov 3, 2005

I'm Edith Head!
e: didn't notice the link to the other thread was related to the Script Editor confusion

Mikey-San fucked around with this message at 07:02 on Apr 23, 2013

Mikey-San
Nov 3, 2005

I'm Edith Head!

lord funk posted:

Long distance high five, but it looks like I'll be putting all my preset documents in the user documents folder for easy editing / saving / deleting. Good to know that I should leave a note to the reviewers.

What makes it necessary to copy all the files during launch?

Mikey-San
Nov 3, 2005

I'm Edith Head!

eschaton posted:

haveblue posted:

I was hoping for something like the Xcode plist editor- a heirarchal semi-shell over the raw text that handles all the braces, brackets, and commas for you.
You could edit it as a plist in Xcode and use plutil to convert it to JSON at build time.

I know this is last-page, but I second this recommendation.

(In fact, I said the same thing to our good friend Hippieman when he asked me the very same question last week. It's worked out well for him, I think.)

Mikey-San
Nov 3, 2005

I'm Edith Head!

pokeyman posted:

Is there an official pluralization mentioned anywhere? I've always hoped it's meant to be "iPods Touch".

(I say as I knowingly break the branding guideline that says it's "iPod touch".)

The Apple Style Guide might cover this:

https://help.apple.com/asg/mac/2013/ASG_2013.pdf

Page 121:

quote:

Trademarked product names: Form the plural of trademarked product names by adding the plural generic noun to the singular product name.
Correct: Mac computers, MacBook Pro computers, iMac computers
Incorrect: Macs, MacBook Pros, iMacs

"iPod touch devices" sounds acceptable, but I am not an authority.

Edit: I think the best answer is to avoid sentence construction that forces you to use plurality.

Mikey-San fucked around with this message at 01:36 on Apr 9, 2014

Mikey-San
Nov 3, 2005

I'm Edith Head!
Eschaton might know a simple way to reinstall those pages, but if you have a Time Machine backup, you could do a quick restore of that stuff:

code:
sudo tmutil restore <snapshot_path>/<that_disk>/usr/share/man/man2 /usr/share/man/man2

Mikey-San
Nov 3, 2005

I'm Edith Head!
attn people who like to write tests

If you do testing with Xcode using XCTest, you don't want to miss session 409, "What's New in Testing". It is absolutely crammed with new stuff. Should be something interesting there for everyone.

Mikey-San
Nov 3, 2005

I'm Edith Head!
Thanks! I don't think it's a stretch to say this is a really big release for us.

If anyone has questions about new XCTest APIs, I'll try to answer them as time permits. Updated (beta) documentation, including new APIs, is also live:

https://developer.apple.com/documentation/xctest

(Spoiler: You can stop using -[XCUIApplication initPrivateWithPath:bundleID:] now.)

Mikey-San
Nov 3, 2005

I'm Edith Head!

Axiem posted:

I got the impression that with the Simulator being able to run multiple simulators, there would be a way in a UI test to run the same app on two different simulators in order to test things like syncing between devices. But I didn't see this discussed in the What's New In Testing session—did I misunderstand, or was it just not covered?

Apologies if it was unclear. We had SO MUCH stuff to cover in the session that we had to compress some details, but here's what's newly supported in Xcode 9:

- Running a set of tests on multiple devices or simulators simultaneously, via xcodebuild or Xcode Server. The use case we're trying to cover here is reducing the time it takes to run all your tests across all the devices you support.

- Within a UI test, controlling multiple applications that are running on the same device. You can control applications already installed on the device (e.g., Settings or Safari) or you can control multiple applications that you build in your project.

We don't currently support controlling applications across devices but that's a request we heard several times. I encourage you to file an enhancement request with details about what kinds of things you'd be doing with it.

quote:

Also, I am super impressed with the Xcode 9 editor. I was skeptical at first, but it really does feel a lot faster and better. And it screws up no more often than Xcode 8's does for me, which is a big plus.

My only real complaint so far is that if someone has a `#pragma mark - ProtocolName`, you can't command-click on the ProtocolName to jump to that protocol to check it out, like you can in Xcode 8. However, I don't think this ends up being a problem in Swift.

That's unfortunate. I would file a bug noting the behavior regressed.

quote:

The enhancements to the XCTestExpectation API in 8.3 has been a huge help for us. It's often the little things.

I'm glad to hear! We think the new XCTWaiter and expectation APIs are the kinds of APIs that help people write tests and testing libraries that are as good as their production code.

edit: minor grammar/typo stuff, accuracy

Mikey-San fucked around with this message at 19:58 on Jun 10, 2017

Mikey-San
Nov 3, 2005

I'm Edith Head!
Speaking of "the little things", the block-based teardown API Wil mentioned in the session is this:

https://developer.apple.com/documentation/xctest/xctestcase/2887226-addteardownblock

I thought I'd point this one out since it's pretty easily missed. There's even an example in the docs.

Mikey-San
Nov 3, 2005

I'm Edith Head!

Axiem posted:

A bit of feedback: so the Test Navigator page? I never knew that existed. There's no obvious way to get to it (I would never think to right-click the test diamond to navigate elsewhere) or its functionality. So when I saw it in the WWDC session, my mind was blown—knowing about that would have made debugging UI tests so much easier! I knew it was taking screenshots, I just assumed there was no way to actually view them in Xcode.

The way people typically access the test report is through the Report Navigator. It's the rightmost icon at the top of the sidebar. (Cmd-8 in Xcode 8, cmd-9 in Xcode 9. I just noticed the numbering coincidence, heh.) In the Report Navigator, you can click the "Test" entries for your schemes and see the test report. Few people know it's accessible via the test diamond contextual menu so we wanted to show that in the session.

quote:

If there were some more obvious way to get there, it would be fantastic. But I don't know how to actually suggest that, because I'm not sure design-wise what that would look like.

In general, don't feel like you need to have a suggestion to file a bug. "I didn't know XYZ existed" is a valid bug!

edit: left out the "dont" there originally, whoops

quote:

However, now that I know that exists, would it be worthwhile filing a radar asking for the ability to import saved test runs? I ask because we use Jenkins for our CI (we don't use Xcode Server for various good reasons, some of which are out of our control), and for our UI tests, we had set up the archiving to include the test result plists and screenshots (which we would manually trawl through on CI failures occasionally to try to track something down. It wasn't easy). It would have been fantastic to actually load up that directory in Xcode to not have to do a bunch of UUID lookups manually.

It's absolutely a worthwhile request, and I believe people have asked for that as well. I can dupe your request to the existing one. (We like dupes.)

Mikey-San fucked around with this message at 03:09 on Jun 11, 2017

Mikey-San
Nov 3, 2005

I'm Edith Head!
(OOPS, I meant to say don't feel like you need to have a suggestion to file a bug. I accidentally'ed the important word there.)

Mikey-San
Nov 3, 2005

I'm Edith Head!

Axiem posted:

I've filed radars 32696637 and 32696678 for the "Wait, there's a Test Report?!" and "Can I import Test Reports from CI?" issues. If there are ways I can make them (/future Radars) better, let me know. I know I'm a little flippant about Xcode version, but mostly because I don't actually remember what version of Xcode I was using back when I first noticed it. Or should I just say whatever my current version is?

Current version is fine when you're asking for an enhancement or UI improvement.

quote:

By the way, if you know the people who did the "Engineering for Testability" talk, that one was fantastic, and I hope the community architects things more in that way over time, and I'm glad there's at least some institutional support from within Apple on it. Please let them know that it was great.

Brian is on my team, actually, and Greg is right down the hall. I'll pass it on. :)

Mikey-San
Nov 3, 2005

I'm Edith Head!

Axiem posted:

Edit: Oh! Is it documented anywhere what the bundle IDs for common apps are? I mean, I know it was called out that we might want to fiddle with Settings (oh holy poo poo thank you thank you thank you for this), but where can we find out the bundle IDs for Settings/Messages/etc. so we can take advantage of it?

I don't think there's an official list. I got this question a few times in the labs at WWDC, so I'm compiling feedback. On macOS, you can just look at an application's Info.plist file. This isn't so easy on iOS/tvOS devices, though, I realize. Stay tuned?

There's a pretty good list on Stack Overflow:

https://stackoverflow.com/questions/9910366/what-is-the-bundle-identifier-of-apples-default-applications-in-ios

Mikey-San
Nov 3, 2005

I'm Edith Head!

Axiem posted:

Along these lines: can this functionality be used to open up Control Center? Or interact with local notifications? Again in the realm of "tests we have to do manually and would love to automate", but I don't know if the current (expanded) functionality solves the problem.

Control Center: I think so. I believe you can do a coordinate (XCUICoordinate) drag up from the bottom of the screen (main window bottom edge) and that will pull up Control Center. I can't remember what application owns the Control Center UI off the top of my head, though, so I'm not sure what bundle ID applies to it.

Notifications: Basically the same answer as above.

I'll see if I can put an example together some time this week.

Mikey-San
Nov 3, 2005

I'm Edith Head!

Axiem posted:

Incidentally, since I'm feeling all Radar happy, I've filed 32696928 for a feature that our QA has grumbled about not having forever that would be nice to have (being able to manipulate date/time in UI tests to test those sorts of things), though I see it as a pie-in-the-sky sort of thing. I'd be shocked if it hasn't been requested before, though.

It's a pretty reasonable thing to want to do in your test cases. Thanks for the (many) bugs you've written today, by the way.

In the meantime, perhaps you could have a helper method that automated Settings.app to change the time/date in your tests.

Mikey-San
Nov 3, 2005

I'm Edith Head!

Axiem posted:

Settings.app doesn't allow us to change the date/time in the simulator is the thing. Arguably, we could run the tests on actual devices (gasp!), though we've run into other issues with trying to do that on our CI box (which may actually be a VM in a data center somewhere), such as dealing with device updates and that sort of thing.

Ah yes, the simulator is a wrench in the workflow here. (The problem is really more of a simulator thing, but I know that's not really an important distinction for test authors.) In general, when there's a lack of parity in testing capability between device and simulator, we consider that an area of potential improvement.

Mikey-San
Nov 3, 2005

I'm Edith Head!

Axiem posted:

Along these lines: can this functionality be used to open up Control Center? Or interact with local notifications? Again in the realm of "tests we have to do manually and would love to automate", but I don't know if the current (expanded) functionality solves the problem.

Sorry it took me a while to get back to you about this. Here are examples of automating Control Center and Notification Center alert windows.

code:
- (void)testControlCenter
{
    // Control Center is owned by Springboard.
    XCUIApplication *springboard = [[XCUIApplication alloc] initWithBundleIdentifier:@"com.apple.springboard"];
    XCUIApplication *app = [[XCUIApplication alloc] init];
    [app launch];
    
    // Pull up from the bottom edge of the screen to bring up the Control Center window.
    XCUICoordinate *bottomEdge = [app coordinateWithNormalizedOffset:CGVectorMake(0.5, 1.0)];
    XCUICoordinate *destination = [app coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.8)];
    [bottomEdge pressForDuration:0.0 thenDragToCoordinate:destination];
    
    // Manipulate controls inside Control Center.
    [springboard.buttons[@"flashlight"] tap];
}

- (void)testNotification
{
    // Rough outline:
    //
    //    1. Tap a button in our app that delivers a notification.
    //    2. Back out to the home screen and wait for the notification window to appear.
    //    3. Tap the notification to reopen our app.
    
    // Notification windows (and the pull-down panel) are owned by Springboard.
    XCUIApplication *springboard = [[XCUIApplication alloc] initWithBundleIdentifier:@"com.apple.springboard"];
    XCUIApplication *app = [[XCUIApplication alloc] init];
    
    // Launch our little demo app and press a button that schedules a local notification for 5 seconds from now.
    [app launch];
    [app.buttons[@"smash"] tap];
    
    // Jump back to the home screen so the notification window appears.
    [XCUIDevice.sharedDevice pressButton:XCUIDeviceButtonHome];
    
    // Notification windows are owned by Springboard. Here's what they look like, as seen via the .debugDescription property:
    //
    // Window, 0x60800018b2c0, traits: 8589934592, Main Window, {{0.0, 0.0}, {375.0, 667.0}}
    //   Other, 0x60800018b390, traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
    //     Other, 0x60800018b460, traits: 35192962023424, {{8.0, 8.0}, {359.0, 659.0}}, label: 'Notification'
    //       ScrollView, 0x60800018b530, traits: 8589934592, {{8.0, 8.0}, {359.0, 659.0}}
    //         Other, 0x60800018b600, traits: 8589934592, {{8.0, 8.0}, {359.0, 87.0}},
    //                   identifier: 'NotificationShortLookView', label: 'MYDEMOAPP, now, Hey Now, You're an all-star'
    //
    // If you're pretty confident your setup will have just one window, you could locate the element via its identifier:
    //
    //     [springboard.otherElements[@"NotificationShortLookView"]
    //
    // But this example will use something more specific, and match against the actual text in the notification label.
    XCUIElement *notification = springboard.otherElements[@"MYDEMOAPP, now, Hey Now, You're an all-star"];
    XCTAssertTrue([notification waitForExistenceWithTimeout:15], @"Expected all-star notification window to appear");
    [notification tap];
    
    // Tapping the notification reopens our app. Because we didn't call -activate or -launch, we should wait for it to become foreground.
    NSPredicate *statePredicate = [NSPredicate predicateWithFormat:@"state == %d", XCUIApplicationStateRunningForeground];
    XCTNSPredicateExpectation *stateExpectation = [[XCTNSPredicateExpectation alloc] initWithPredicate:statePredicate object:app];
    [self waitForExpectations:@[ stateExpectation ] timeout:10];
    
    // More test code here.
}

edit: slightly less table breakage, test method rename, assert the existence of the notification window

Mikey-San fucked around with this message at 22:08 on Jun 16, 2017

Mikey-San
Nov 3, 2005

I'm Edith Head!

Axiem posted:

This is super awesome, and no worries on the delay. Thanks so much; this will be a huuuuuuuge help.

Sure. I updated the example to assert the result of -waitForExistenceWithTimeout:, to signal failure earlier and more descriptively.

If anyone's wondering where that method came from, it's new in Xcode 9.

Mikey-San
Nov 3, 2005

I'm Edith Head!
Echoing what rjmccall, Simulated, and eschaton said. DevTools is a very professional environment staffed and run by competent adults who don't care whether you run the Barkley Marathons or whatever in your spare time. I worked in the macOS org for a long time prior to DT and it's the same there, too.

Mikey-San
Nov 3, 2005

I'm Edith Head!

FAT32 SHAMER posted:

Hey so this is an ancient post, but I want to play with UI Testing by automating some button presses in an app like Gmail. Is there a way to do this with an already existing app that I have no source code for or am i pretty much hosed?

In Xcode 9, we introduced an initializer for XCUIApplication that allows you to query and control applications that are already installed on the device. You can refer to apps like Safari and Settings this way.

https://developer.apple.com/documentation/xctest/xcuiapplication/2879415-init

E.g.,

code:
XCUIApplication *safari = [[XCUIApplication alloc] initWithBundleIdentifier:@"com.apple.mobilesafari"];
[safari activate]; // or -launch, look at XCUIApplication.h to see how they differ

// this will give you a picture of how UIs look in XCTest. do not use this for actual test code.
NSString *hierarchy = safari.debugDescription;
You might find it easier to experiment with UI testing with something less complex than Gmail.

Mikey-San fucked around with this message at 21:15 on Jul 31, 2017

Mikey-San
Nov 3, 2005

I'm Edith Head!

FAT32 SHAMER posted:

The documentation for UITest is really bad

Or at least it's bad to me, a beginner

It's not you! We think there's a lot of room for improvement in our UI testing documentation. The class reference documentation does what it does, but one can imagine a variety of improvements that would help people go from 0 to 60 much more quickly.

There are a few WWDC sessions from the past that are worth watching:

https://developer.apple.com/videos/play/wwdc2015/406/
https://developer.apple.com/videos/play/wwdc2016/409/
https://developer.apple.com/videos/play/wwdc2017/409/

They cover a wide variety of topics at various levels of expertise, so come back to them as you get more comfortable. (The 2017 session, for example, is geared toward an audience with prior experience using XCTest for unit and UI tests.)

If you have specific questions, at any level, post 'em here and I'll do my best.

Mikey-San
Nov 3, 2005

I'm Edith Head!
Yeah, but I'll be honest here: getting two apps side-by-side in UI testing requires some fairly advanced effort. It's way harder than it should be. You essentially have to automate every painstaking step: perform a screen-edge drag to bring up the multitasking dock, find an app icon inside the dock (owned by Springboard), drag that to the screen, put the UI into split mode, etc. The difficulty curve and tedium is not lost on us!

e: typo

e2: This is definitely an area I think we can improve upon.

Mikey-San fucked around with this message at 07:51 on Aug 2, 2017

Mikey-San
Nov 3, 2005

I'm Edith Head!

FAT32 SHAMER posted:

Oh perfect, hopefully these will point me further in the right direction. Thanks again!

edit: holy loving poo poo xcode writes it all for you based on what you click on? :stonk: I thought android's uiautomator was pretty good but jesus.

UI recording is a good place to start to learn how queries are constructed. It has its limitations, so it's best as a jumping-off point. (E.g., it doesn't know anything about whether you need to wait for an element to exist before attempting to interact with it.) It also can't reason about the best way to structure your tests. It just emits what you did.

quote:

I still havent figured out how to set an app that exists on my device as the target for my tests but these have already opened my eyes :eyepop:

edit: if anyone would like an ez stackoverflow question answered https://stackoverflow.com/questions/45469481/how-to-perform-uitesting-on-an-app-i-dont-have-source-code-for/45469559#45469559

Automating an application that is already on the device doesn't involve messing with the "Target Application" setting. That setting controls what -[XCUIApplication init] does and references something in your project. If you want to reference an application that isn't from your project, you would use -[XCUIApplication initWithBundleIdentifier:] instead. E.g.,

code:
XCUIApplication *settings = [[XCUIApplication alloc] initWithBundleIdentifier:@"com.apple.Preferences"];
Or if you're Swifty:

code:
let settings = XCUIApplication(bundleIdentifier: "com.apple.Preferences")
You can also use this for another app in your scheme that isn't the default "Target Application".

e: clarity

Mikey-San fucked around with this message at 21:36 on Aug 2, 2017

Mikey-San
Nov 3, 2005

I'm Edith Head!
I should also mention that UI recording only works for the default "Target Application" currently.

Mikey-San
Nov 3, 2005

I'm Edith Head!

eschaton posted:

What are the failures that you’re running into?

If there are particular elements that aren’t showing up in the element hierarchy at the point your test is trying to interact with them, you can create a predicate expectation and then wait on that before actually querying that element.

And if you just need to wait for an element to show up, -[XCUIElement waitForExistenceWithTimeout:] handles things for you.

Mikey-San fucked around with this message at 23:43 on Dec 21, 2018

Adbot
ADBOT LOVES YOU

Mikey-San
Nov 3, 2005

I'm Edith Head!

TheReverend posted:

Yeah we use the expectations with generous timeout values and it works but only 90% of the time.

Can you give a specific example? Without more detail, all we can do is speculate about common problems people encounter. (One or more of the issues may not be timeout-related at all.)

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply