I am trying to learn automated UI testing with KIF in sample app. My simple test is failing continuously. My code :
#import <XCTest/XCTest.h>
#import <KIF/KIF.h>
@interface AutomatedUITestsSampleUITests : KIFTestCase
@end
@implementation AutomatedUITestsSampleUITests
- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
// In UI tests it is usually best to stop immediately when a failure occurs.
self.continueAfterFailure = NO;
// UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
[[[XCUIApplication alloc] init] launch];
// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
}
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testExample {
[tester waitForViewWithAccessibilityLabel:@"LOGIN - Button"];
[tester tapViewWithAccessibilityLabel:@"LOGIN - Button" traits:UIAccessibilityTraitButton];
}
I have set Accessibility Label LOGIN - Button
to a UIButton in my storyboard also Accessibility is enabled.
I am getting this in console :
Test Case '-[AutomatedUITestsSampleUITests testExample]' started.
t = 0.00s Start Test at 2017-06-16 13:45:07.071
t = 0.00s Set Up
t = 0.04s Launch com.UITests.AutomatedUITestsSample
t = 4.63s Waiting for accessibility to load
t = 8.77s Wait for app to idle
t = 10.48s Tear Down
Test Case '-[AutomatedUITestsSampleUITests testExample]' failed (10.868 seconds).
Test Suite 'AutomatedUITestsSampleUITests' failed at 2017-06-16 13:45:17.939.
Executed 1 test, with 1 failure (1 unexpected) in 10.868 (12.735) seconds
Test Suite 'AutomatedUITestsSampleUITests.xctest' failed at 2017-06-16 13:45:17.940.
Executed 1 test, with 1 failure (1 unexpected) in 10.868 (12.739) seconds
Test Suite 'All tests' failed at 2017-06-16 13:45:17.941.
Executed 1 test, with 1 failure (1 unexpected) in 10.868 (12.743) seconds
It's a very simple test. Why is it failing? Thanks in advance.
If you have access to the XCUIApplication
there is something wrong with your project configuration. KIF tests target should be "Unit Test Target", not "UI Test Target". With correct configuration there is no need to launch the app (and no possibility of app launch manipulation) - it is launched when the unit tests begin. When you use UI test target your tests are running in separate process and KIF doesn't have access to your app.
I suggest to configure your test target again with this guide