MortimerGoro / MGSwipeTableCell

An easy to use UITableViewCell subclass that allows to display swippable buttons with a variety of transitions.
MIT License
6.96k stars 1.08k forks source link

Accessing Buttons in UITests does not work #139

Open marbetschar opened 8 years ago

marbetschar commented 8 years ago

Hi!

I'm currently trying to build some tests using the new UITest feature in Xcode 7. Unfortunately I'm not able to figure out how to access the MGSwipeButton from it. What's wrong?

In cellForRowAtIndexPath:

let deleteButton = MGSwipeButton(title:NSLocalizedString("Delete",comment:"Delete"), backgroundColor:AppAppearance.deleteColor)
deleteButton.accessibilityLabel = NSLocalizedString("Delete",comment:"Delete")

cell?.rightButtons = [ deleteButton ]

And afterwards, if I try to record the test Xcode generates the following code:

let marcoBetschartStaticText = XCUIApplication().tables.staticTexts["Marco Betschart"]
marcoBetschartStaticText.swipeLeft()
marcoBetschartStaticText.tap()

Which - of course - just closes the swipeable button area when run.

So how to access the MGSwipeButton's in UITests?

marbetschar commented 8 years ago

The MGSwipeButton does not seem to be visible by default to Accessibility; which is explained in https://developer.apple.com/videos/wwdc/2015/?id=406 at 39:00

But I'm unable to "activate" the Accessibility for them :(

I've tried deleteButton.accessibilityElementsHidden = false but without success. Any suggestions?

marbetschar commented 8 years ago

Got the wrong property - but nevertheless: Setting deleteButton.isAccessibilityElement = true also doesn't have any effect at all.

marbetschar commented 8 years ago

Any news on this one...?

marbetschar commented 8 years ago

Is this framework even maintained anymore?

MortimerGoro commented 8 years ago

Yes, the project is maintained. I have been busy lately but I will check all the issues/pull request and release a new version soon.

marbetschar commented 8 years ago

Yeeeeehaaaaaaa!! Good news!!!!!!! :)

I've already started digging around for another project; but switching would cause a major rework of our app since we are heavily relying on your fabulous MGSwipeTableCell.

As upon now I haven't had a closer look at the other issues of this project; but I assume (and understand) UITesting might not got the highest priority in requested features.

Regardless of this, we created fairly complex user interactions based on swipe routines and hoped we are able to implement high level testing routines with the new UI Testing in Xcode. As UITests are not yet working with MGSwipeTableCell, this causes us to put a huge amount into manual testing.

Be able to implement MGSwipeTableCell into UITest's would be a huge benefit on our end - so it'll be very nice to see it as soon as somehow possible.

Feel free to get back to me, if I'm able to help in anything. I've already tried to fix it by myself, but my Objective-C / Cocoapods knowledge seems not to be good enough to wrap my head around the entire problem (started with plain Swift).

marbetschar commented 8 years ago

Any news in this one?

MortimerGoro commented 8 years ago

Can you send me a test project?

marbetschar commented 8 years ago

Unfortunately I can't find the Time - but it should easy to create one: Just Setup a clean project with a tableView and Swipe functionalities. Them try to Access These by using UI Tests

marbetschar commented 8 years ago

Any News on this?

eventomer commented 8 years ago

+1 for this feature

eventomer commented 8 years ago

I managed to tap the button with this code:

    XCUICoordinate *cordinate = [[self.app.tables.cells elementBoundByIndex:0] coordinateWithNormalizedOffset:CGVectorMake([UIScreen mainScreen].bounds.size.width-5, 0)];
    [cordinate tap];
marbetschar commented 8 years ago

@eventomer does this even work if you have multiple buttons? How would you distinguish between a "More" and "Delete" Button for example?

palfvin commented 8 years ago

+1 looking for a solution to this

Dennis-Kluge commented 8 years ago

+1 I face the same problem. On the the one side I'm unfortunately not able to test the UI of my app automatically on the other fastlanes snapshot is not integratable.

Do you see any way to make UI Tests workable? Maybe you could give a small hint how to integrate accessibility features.

Tjmoronez commented 8 years ago

+1 I am also running into this issue. To workaround this issue I am using a tap on coordinate function.

tateexon commented 8 years ago

I am running into a very similar problem when testing using Appium. Appium for whatever reason causes a nil hitTest event that MGSwipe reads as a reason to hide the buttons. So if you change the method: -(UIView *) hitTest:(CGPoint)point withEvent:(UIEvent *)event to have this at the beginning then the problem is fixed:

    if (event == nil){
        return nil;
    }

I can submit a fix if needed.

tateexon commented 8 years ago

Made a pull request to hopefully fix this: https://github.com/MortimerGoro/MGSwipeTableCell/pull/208

rafaelmersant commented 7 years ago

Please, @MortimerGoro, help us with this issue.

tateexon commented 7 years ago

@rafaelmersant could you see if my fix works for you?

MortimerGoro commented 7 years ago

@rafaelmersant does @tateexon 's fix work for you? I'll push a new version soon

StephenTrov commented 7 years ago

@tateexon your fix does not work for me when I tried it with XCTest.

tateexon commented 7 years ago

Interesting, I will have to put together a test with XCTest, was assuming apple used the same libraries underneath for UIAutomation and xcuitest and my assumption was wrong. I will debug into this later this week and see if I can come up with anything. I will be moving to over next month so I am assuming I will be running into this issue and will be needing it fixed when I get there.

edit: I was unable to figure out why xcuitest behaves the way it does with this library. Will be a while before I can try another deep dive so if anyone else wants to try to debug it, go ahead.

MortimerGoro commented 7 years ago

Finally I had some time to work on this issue. The problem seems that the default UITableViewCell implementation doesn't really use/return all cell.contentView subviews in the accessibility protocol implementation. I have overridden UIAccessibilityContainer protocol to use contentView when the cell is swipped and fallback to default implementation when a cell is not in a swipped state.

I have tested with the Accessibility Inspector and a new XCTest project and both seems to work well now.

Let me know if it works in your projects now ;)

The commit is the master branch by now, I want to work on other issue before pushing 1.5.6 to CocoaPods

midhun21 commented 7 years ago

In the first screenshot, when I swipe to left, appium recognizes the Block button in iOS (XCUITest)enter image description here. But in the second screenshot, appium does not recognize the Block button. How to solve this?

block button does not show up in another entry block button shows up in one entry
midhun21 commented 7 years ago

What I observed is, if I do Pull to refresh and then swipe, then Appium Inspector will recognize the button. But without Pull to refresh and swiping on the cell, Appium does not recognize the button. But when I execute the code, Appium does not recognize the button even after refreshing the screen and swiping on the cell