Skip to content
This repository has been archived by the owner on Jul 20, 2020. It is now read-only.

Adopt some conveniences via masilotti.com #104

Open
ianfixes opened this issue Dec 31, 2016 · 6 comments
Open

Adopt some conveniences via masilotti.com #104

ianfixes opened this issue Dec 31, 2016 · 6 comments

Comments

@ianfixes
Copy link
Contributor

ianfixes commented Dec 31, 2016

http://masilotti.com/ui-testing-cheat-sheet/

Specifically, pull-to-refresh for scrollable elements (tables, collectionViews)

let firstCell = app.staticTexts["Adrienne"]
let start = firstCell.coordinate(withNormalizedOffset: CGVectorMake(0, 0))
let finish = firstCell.coordinate(withNormalizedOffset: CGVectorMake(0, 6))
start.press(forDuration: 0, thenDragTo: finish)

And possibly multi-wheel pickers, if we can make a general solution

extension ManageTeamViewController: UIPickerViewAccessibilityDelegate {
    func pickerView(_ pickerView: UIPickerView, accessibilityHintForComponent component: Int) -> String? {
        return component == 0 ? "Attackers Formation" : "Setters Formation"
    }
}

/*
This then sets the first wheel's accessibility title to "Attackers Formation, 4 attackers." 
Notice how the selected value sneaks in? To actually select the element we will need to 
match it with a BEGINSWITH predicate.
*/

let attackers = NSPredicate(format: "label BEGINSWITH 'Attackers Formation'")
let attackersPicker = app.pickerWheels.element(matchingPredicate: attackers)
attackersPicker.adjust(toPickerWheelValue: "5 attackers")

let setters = NSPredicate(format: "label BEGINSWITH 'Setters Formation'")
let settersPicker = app.pickerWheels.element(matchingPredicate: setters)
settersPicker.adjust(toPickerWheelValue: "1 setter")
@joemasilotti
Copy link

Happy to help if you have any specific questions!

@ianfixes
Copy link
Contributor Author

ianfixes commented Jan 4, 2017

Thanks :)

My suspicion is that you found this via a google alert (and not because you're already a fan of this project), but I'm still interested to hear what you think of this framework in general.

@ianfixes
Copy link
Contributor Author

ianfixes commented Jan 8, 2017

@joemasilotti This code seems to pass when it shouldn't -- in my tests, it returns true even when the element is several swipes off screen:

let window = app.windows.element(boundBy: 0)
let element = app.buttons["On"]
XCTAssert(CGRectContainsRect(window.frame, element.frame))

In #107 I'm using .hittable instead. Does .hittable replace the code above?

@joemasilotti
Copy link

I've noticed that frame isn't calculated each time you call it. In your example, you might be getting a cached version. You can try to force the screen to "re-draw" by tapping on it, app.tap().

@ianfixes
Copy link
Contributor Author

Does that represent the case where the element is created within the main window but pushed out of view by other elements?

@joemasilotti
Copy link

Perhaps... its hard to tell, sometimes. If you can update, UI Testing feels a little more reliable in Xcode 8.3. Granted, you won't be able to release to the App Store until it comes out of beta.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants