Best EarlGrey code snippet using performAction.grey_turnSwitchOn
BasicInteractionTest.m
Source:BasicInteractionTest.m
...239 return error == nil;240 }];241 // Switch text and wait.242 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]243 performAction:grey_turnSwitchOn(NO)];244 XCTAssertTrue([waitCondition waitWithTimeout:10.0],245 @"Switch not manipulated within the allotted time for a Condition.");246}247/**248 * Use a GREYCondition to check if an element is visible on the screen. Change a stepper value for249 * the element to be visible.250 */251- (void)testEarlGreyInvocationInsideConditionUsingWaitWithLargeTimeout {252 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];253 GREYCondition *waitCondition = [GREYCondition254 conditionWithName:@"conditionWithAction"255 block:^BOOL {256 static double stepperValue = 51;257 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]258 performAction:grey_setStepperValue(++stepperValue)];259 return stepperValue == 55;260 }];261 XCTAssertTrue([waitCondition waitWithTimeout:15.0],262 @"Stepper Change not completed within the allotted time for the Condition.");263 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]264 assertWithMatcher:grey_stepperValue(55)];265}266/**267 * Ensure basic interaction with a stepper.268 */269- (void)testBasicInteractionWithStepper {270 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];271 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]272 performAction:grey_setStepperValue(87)];273 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Value Label")]274 assertWithMatcher:grey_text(@"Value: 87%")];275 [[[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]276 performAction:grey_setStepperValue(16)] assertWithMatcher:grey_stepperValue(16)];277}278/**279 * Ensure basic interaction with a switch.280 */281- (void)testInteractionWithSwitch {282 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];283 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];284 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]285 performAction:grey_turnSwitchOn(NO)] assertWithMatcher:grey_switchWithOnState(NO)];286 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]287 performAction:grey_turnSwitchOn(YES)] assertWithMatcher:grey_switchWithOnState(YES)];288 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]289 performAction:grey_turnSwitchOn(YES)] assertWithMatcher:grey_switchWithOnState(YES)];290 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]291 performAction:grey_turnSwitchOn(NO)] assertWithMatcher:grey_switchWithOnState(NO)];292}293/**294 * Ensure basic interaction with a hidden label.295 */296- (void)testInteractionWithHiddenLabel {297 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];298 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Hidden Label")]299 assertWithMatcher:grey_text(@"Hidden Label")];300}301/**302 * Ensure basic interaction with a view who's parent has alpha set to zero.303 */304- (void)testInteractionWithLabelWithParentWithAlphaZero {305 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];306 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]307 assertWithMatcher:grey_not(grey_sufficientlyVisible())];308}309/**310 * Ensure basic interaction using a remote matcher.311 */312- (void)testEarlGreyRemoteMatcher {313 id<GREYMatcher> matcher =314 [[GREYHostApplicationDistantObject sharedInstance] matcherForFirstElement];315 [[EarlGrey selectElementWithMatcher:grey_allOf(grey_kindOfClass([UITableViewCell class]), matcher,316 nil)] performAction:grey_tap()];317 NSError *error;318 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] assertWithMatcher:grey_notNil()319 error:&error];320 XCTAssertEqual(error.code, kGREYInteractionElementNotFoundErrorCode,321 @"No table view cell from the main Table can be visible.");322}323/**324 * Ensure basic interaction using a remote action.325 */326- (void)testEarlGreyRemoteAction {327 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];328 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];329 id<GREYAction> action =330 [[GREYHostApplicationDistantObject sharedInstance] actionForTapOnAccessibleElement];331 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")] performAction:action];332}333/**334 * Ensure basic interaction using a remote assertion.335 */336- (void)testEarlGreyRemoteAssertion {337 id<GREYAssertion> assertion =338 [[GREYHostApplicationDistantObject sharedInstance] assertionThatAlphaIsGreaterThanZero];339 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] assert:assertion];340}341/**342 * Ensure tapping on a disabled UIControl fails.343 */344- (void)testTappingOnADisabledButton {345 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];346 NSError *error;347 [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"Disabled")] performAction:grey_tap()348 error:&error];349 XCTAssertEqualObjects(error.domain, kGREYInteractionErrorDomain);350 XCTAssertEqual(error.code, kGREYInteractionConstraintsFailedErrorCode);351}352/**353 * Checks the working of a condition with a large timeout.354 */355- (void)testEarlGreyInvocationInsideGREYConditionUsingWaitWithLargeTimeout {356 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];357 GREYCondition *condition = [GREYCondition358 conditionWithName:@"conditionWithAction"359 block:^BOOL {360 static double stepperValue = 51;361 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]362 performAction:grey_setStepperValue(++stepperValue)];363 return stepperValue == 55;364 }];365 XCTAssertTrue([condition waitWithTimeout:10.0]);366 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]367 assertWithMatcher:grey_stepperValue(55)];368}369/**370 * Checks the working of a condition with a normal timeout.371 */372- (void)testEarlGreyInvocationInsideGREYConditionUsingWaitWithTimeout {373 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];374 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];375 id<GREYAction> action = [[GREYHostApplicationDistantObject sharedInstance] actionToGetLabelText];376 // Setup a condition to wait until a specific label says specific text.377 GREYCondition *waitCondition = [GREYCondition378 conditionWithName:@"WaitForLabelText"379 block:^BOOL() {380 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"sampleLabel")]381 performAction:action];382 NSString *text = [[GREYHostApplicationDistantObject sharedInstance] labelText];383 return [text isEqualToString:@"OFF"];384 }];385 // Switch text and wait.386 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]387 performAction:grey_turnSwitchOn(NO)];388 XCTAssertTrue([waitCondition waitWithTimeout:10.0]);389}390/**391 * Check tapping on a new custom window that covers the whole screen.392 */393- (void)testTapOnWindow {394 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];395 [[EarlGrey selectElementWithMatcher:grey_keyWindow()] performAction:grey_tap()];396 UIWindow *window = [[GREYHostApplicationDistantObject sharedInstance] setupGestureRecognizer];397 XCTAssertNotNil(window);398 // Tap on topmost window.399 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TopMostWindow")]400 performAction:grey_tap()];401 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TopMostWindow")]402 assertWithMatcher:grey_notVisible()];403}404/**405 * Check setting of the root view controller multiple times in the main window.406 */407- (void)testRootViewControllerSetMultipleTimesOnMainWindow {408 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];409 UIViewController *originalVC =410 [[GREYHostApplicationDistantObject sharedInstance] originalVCAfterSettingNewVCAsRoot];411 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_nil()];412 [[GREYHostApplicationDistantObject sharedInstance] setRootViewController:nil];413 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_nil()];414 [[GREYHostApplicationDistantObject sharedInstance] setRootViewController:originalVC];415 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_notNil()];416}417/**418 * Check setting of the root view controller in different windows.419 */420- (void)testRootViewControllerSetOnMultipleWindows {421 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];422 UIWindow *window = nil;423 UIViewController *originalVC = [[GREYHostApplicationDistantObject sharedInstance]424 originalVCAfterSettingRootVCInAnotherWindow:window];425 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_nil()];426 [[GREYHostApplicationDistantObject sharedInstance] setRootViewController:nil inWindow:window];427 [[GREYHostApplicationDistantObject sharedInstance] setRootViewController:originalVC];428 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_notNil()];429}430/**431 * Ensures basic interactions with views.432 */433- (void)testBasicInteractionWithViews {434 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];435 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];436 GREYElementInteraction *typeHere =437 [EarlGrey selectElementWithMatcher:grey_allOf(grey_accessibilityLabel(@"Type Something Here"),438 grey_kindOfClass([UITextField class]), nil)];439 [[typeHere performAction:grey_replaceText(@"Hello 2")] assertWithMatcher:grey_text(@"Hello 2")];440 [typeHere performAction:grey_clearText()];441 [[typeHere performAction:grey_tapAtPoint(CGPointMake(0, 0))]442 performAction:grey_replaceText(@"Hello!")];443 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"return")] performAction:grey_tap()];444 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Send")]445 performAction:grey_tapAtPoint(CGPointMake(5, 5))];446 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Simple Label")]447 assertWithMatcher:grey_text(@"Hello!")];448 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]449 performAction:grey_turnSwitchOn(NO)];450 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Simple Label")]451 assertWithMatcher:grey_text(@"OFF")];452 [[[EarlGrey selectElementWithMatcher:grey_text(@"Long Press")]453 performAction:grey_longPressWithDuration(1.1f)] assertWithMatcher:grey_notVisible()];454 [[[EarlGrey selectElementWithMatcher:grey_text(@"Double Tap")] performAction:grey_doubleTap()]455 assertWithMatcher:grey_notVisible()];456}457/**458 * Checks a custom action.459 */460- (void)testEarlGreyInvocationInsideCustomAction {461 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];462 id<GREYAction> action =463 [[GREYHostApplicationDistantObject sharedInstance] actionForCheckingIfElementHidden];...
FTRBasicInteractionTest.m
Source:FTRBasicInteractionTest.m
...230 return error == nil;231 }];232 // Switch text and wait.233 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]234 performAction:grey_turnSwitchOn(NO)];235 XCTAssertTrue([waitCondition waitWithTimeout:10.0],236 @"Switch not manipulated within the allotted time for a Condition.");237}238/**239 * Use a GREYCondition to check if an element is visible on the screen. Change a stepper value for240 * the element to be visible.241 */242- (void)testEarlGreyInvocationInsideConditionUsingWaitWithLargeTimeout {243 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];244 GREYCondition *waitCondition = [GREYCondition245 conditionWithName:@"conditionWithAction"246 block:^BOOL {247 static double stepperValue = 51;248 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]249 performAction:grey_setStepperValue(++stepperValue)];250 return stepperValue == 55;251 }];252 XCTAssertTrue([waitCondition waitWithTimeout:15.0],253 @"Stepper Change not completed within the allotted time for the Condition.");254 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]255 assertWithMatcher:grey_stepperValue(55)];256}257/**258 * Ensure basic interaction with a stepper.259 */260- (void)testBasicInteractionWithStepper {261 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];262 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]263 performAction:grey_setStepperValue(87)];264 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Value Label")]265 assertWithMatcher:grey_text(@"Value: 87%")];266 [[[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]267 performAction:grey_setStepperValue(16)] assertWithMatcher:grey_stepperValue(16)];268}269/**270 * Ensure basic interaction with a switch.271 */272- (void)testInteractionWithSwitch {273 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];274 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];275 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]276 performAction:grey_turnSwitchOn(NO)] assertWithMatcher:grey_switchWithOnState(NO)];277 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]278 performAction:grey_turnSwitchOn(YES)] assertWithMatcher:grey_switchWithOnState(YES)];279 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]280 performAction:grey_turnSwitchOn(YES)] assertWithMatcher:grey_switchWithOnState(YES)];281 [[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]282 performAction:grey_turnSwitchOn(NO)] assertWithMatcher:grey_switchWithOnState(NO)];283}284/**285 * Ensure basic interaction with a hidden label.286 */287- (void)testInteractionWithHiddenLabel {288 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];289 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Hidden Label")]290 assertWithMatcher:grey_text(@"Hidden Label")];291}292/**293 * Ensure basic interaction with a view who's parent has alpha set to zero.294 */295- (void)testInteractionWithLabelWithParentWithAlphaZero {296 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];297 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Long Press")]298 assertWithMatcher:grey_not(grey_sufficientlyVisible())];299}300/**301 * Ensure basic interaction using a remote matcher.302 */303- (void)testEarlGreyRemoteMatcher {304 id<GREYMatcher> matcher =305 [[GREYHostApplicationDistantObject sharedInstance] matcherForFirstElement];306 [[EarlGrey selectElementWithMatcher:grey_allOf(grey_kindOfClass([UITableViewCell class]), matcher,307 nil)] performAction:grey_tap()];308 NSError *error;309 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] assertWithMatcher:grey_notNil()310 error:&error];311 XCTAssertEqual(error.code, kGREYInteractionElementNotFoundErrorCode,312 @"No table view cell from the main Table can be visible.");313}314/**315 * Ensure basic interaction using a remote action.316 */317- (void)testEarlGreyRemoteAction {318 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];319 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];320 id<GREYAction> action =321 [[GREYHostApplicationDistantObject sharedInstance] actionForTapOnAccessibleElement];322 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")] performAction:action];323}324/**325 * Ensure basic interaction using a remote assertion.326 */327- (void)testEarlGreyRemoteAssertion {328 id<GREYAssertion> assertion =329 [[GREYHostApplicationDistantObject sharedInstance] assertionThatAlphaIsGreaterThanZero];330 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] assert:assertion];331}332/**333 * Ensure tapping on a disabled UIControl fails.334 */335- (void)testTappingOnADisabledButton {336 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];337 NSError *error;338 [[EarlGrey selectElementWithMatcher:grey_buttonTitle(@"Disabled")] performAction:grey_tap()339 error:&error];340 XCTAssertEqualObjects(error.domain, kGREYInteractionErrorDomain);341 XCTAssertEqual(error.code, kGREYInteractionConstraintsFailedErrorCode);342}343/**344 * Checks the working of a condition with a large timeout.345 */346- (void)testEarlGreyInvocationInsideGREYConditionUsingWaitWithLargeTimeout {347 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];348 GREYCondition *condition = [GREYCondition349 conditionWithName:@"conditionWithAction"350 block:^BOOL {351 static double stepperValue = 51;352 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]353 performAction:grey_setStepperValue(++stepperValue)];354 return stepperValue == 55;355 }];356 XCTAssertTrue([condition waitWithTimeout:10.0]);357 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([UIStepper class])]358 assertWithMatcher:grey_stepperValue(55)];359}360/**361 * Checks the working of a condition with a normal timeout.362 */363- (void)testEarlGreyInvocationInsideGREYConditionUsingWaitWithTimeout {364 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];365 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];366 id<GREYAction> action = [[GREYHostApplicationDistantObject sharedInstance] actionToGetLabelText];367 // Setup a condition to wait until a specific label says specific text.368 GREYCondition *waitCondition = [GREYCondition369 conditionWithName:@"WaitForLabelText"370 block:^BOOL() {371 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"sampleLabel")]372 performAction:action];373 NSString *text = [[GREYHostApplicationDistantObject sharedInstance] labelText];374 return [text isEqualToString:@"OFF"];375 }];376 // Switch text and wait.377 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]378 performAction:grey_turnSwitchOn(NO)];379 XCTAssertTrue([waitCondition waitWithTimeout:10.0]);380}381/**382 * Check tapping on a new custom window that covers the whole screen.383 */384- (void)testTapOnWindow {385 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];386 [[EarlGrey selectElementWithMatcher:grey_keyWindow()] performAction:grey_tap()];387 UIWindow *window = [[GREYHostApplicationDistantObject sharedInstance] setupGestureRecognizer];388 XCTAssertNotNil(window);389 // Tap on topmost window.390 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TopMostWindow")]391 performAction:grey_tap()];392 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"TopMostWindow")]393 assertWithMatcher:grey_notVisible()];394}395/**396 * Check setting of the root view controller multiple times in the main window.397 */398- (void)testRootViewControllerSetMultipleTimesOnMainWindow {399 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];400 UIViewController *originalVC =401 [[GREYHostApplicationDistantObject sharedInstance] originalVCAfterSettingNewVCAsRoot];402 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_nil()];403 [[GREYHostApplicationDistantObject sharedInstance] setRootViewController:nil];404 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_nil()];405 [[GREYHostApplicationDistantObject sharedInstance] setRootViewController:originalVC];406 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_notNil()];407}408/**409 * Check setting of the root view controller in different windows.410 */411- (void)testRootViewControllerSetOnMultipleWindows {412 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];413 UIWindow *window = nil;414 UIViewController *originalVC = [[GREYHostApplicationDistantObject sharedInstance]415 originalVCAfterSettingRootVCInAnotherWindow:window];416 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_nil()];417 [[GREYHostApplicationDistantObject sharedInstance] setRootViewController:nil inWindow:window];418 [[GREYHostApplicationDistantObject sharedInstance] setRootViewController:originalVC];419 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] assertWithMatcher:grey_notNil()];420}421/**422 * Ensures basic interactions with views.423 */424- (void)testBasicInteractionWithViews {425 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];426 [[EarlGrey selectElementWithMatcher:grey_text(@"Tab 2")] performAction:grey_tap()];427 GREYElementInteraction *typeHere =428 [EarlGrey selectElementWithMatcher:grey_allOf(grey_accessibilityLabel(@"Type Something Here"),429 grey_kindOfClass([UITextField class]), nil)];430 [[typeHere performAction:grey_replaceText(@"Hello 2")] assertWithMatcher:grey_text(@"Hello 2")];431 [typeHere performAction:grey_clearText()];432 [[typeHere performAction:grey_tapAtPoint(CGPointMake(0, 0))]433 performAction:grey_replaceText(@"Hello!")];434 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"return")] performAction:grey_tap()];435 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Send")]436 performAction:grey_tapAtPoint(CGPointMake(5, 5))];437 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Simple Label")]438 assertWithMatcher:grey_text(@"Hello!")];439 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Switch")]440 performAction:grey_turnSwitchOn(NO)];441 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Simple Label")]442 assertWithMatcher:grey_text(@"OFF")];443 [[[EarlGrey selectElementWithMatcher:grey_text(@"Long Press")]444 performAction:grey_longPressWithDuration(1.1f)] assertWithMatcher:grey_notVisible()];445 [[[EarlGrey selectElementWithMatcher:grey_text(@"Double Tap")] performAction:grey_doubleTap()]446 assertWithMatcher:grey_notVisible()];447}448/**449 * Checks a custom action.450 */451- (void)testEarlGreyInvocationInsideCustomAction {452 [[EarlGrey selectElementWithMatcher:grey_text(@"Basic Views")] performAction:grey_tap()];453 id<GREYAction> action =454 [[GREYHostApplicationDistantObject sharedInstance] actionForCheckingIfElementHidden];...
FTRPickerViewInteractionTest.m
Source:FTRPickerViewInteractionTest.m
...122}123- (void)testNoPickerViewComponentDelegateMethodsAreDefined {124 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];125 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"noDelegateMethodDefinedSwitch")]126 performAction:grey_turnSwitchOn(YES)];127 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]128 assertWithMatcher:grey_pickerColumnSetToValue(0, nil)];129 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]130 assertWithMatcher:grey_pickerColumnSetToValue(1, nil)];131}132- (void)testViewForRowDefined {133 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];134 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"viewForRowDelegateSwitch")]135 performAction:grey_turnSwitchOn(YES)];136 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]137 performAction:grey_setPickerColumnToValue(0, @"Green")];138 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]139 performAction:grey_setPickerColumnToValue(1, @"4")];140 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]141 assertWithMatcher:grey_pickerColumnSetToValue(0, @"Green")];142 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]143 assertWithMatcher:grey_pickerColumnSetToValue(1, @"4")];144}145- (void)testAttributedTitleForRowDefined {146 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];147 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"attributedTitleForRowDelegateSwitch")]148 performAction:grey_turnSwitchOn(YES)];149 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]150 performAction:grey_setPickerColumnToValue(0, @"Green")];151 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]152 performAction:grey_setPickerColumnToValue(1, @"4")];153 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]154 assertWithMatcher:grey_pickerColumnSetToValue(0, @"Green")];155 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]156 assertWithMatcher:grey_pickerColumnSetToValue(1, @"4")];157}158- (void)testTitleForRowDefined {159 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];160 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"titleForRowDelegateSwitch")]161 performAction:grey_turnSwitchOn(YES)];162 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]163 performAction:grey_setPickerColumnToValue(0, @"Green")];164 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]165 performAction:grey_setPickerColumnToValue(1, @"4")];166 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]167 assertWithMatcher:grey_pickerColumnSetToValue(0, @"Green")];168 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]169 assertWithMatcher:grey_pickerColumnSetToValue(1, @"4")];170}171@end...
PickerViewInteractionTest.m
Source:PickerViewInteractionTest.m
...121}122- (void)testNoPickerViewComponentDelegateMethodsAreDefined {123 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];124 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"noDelegateMethodDefinedSwitch")]125 performAction:grey_turnSwitchOn(YES)];126 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]127 assertWithMatcher:grey_pickerColumnSetToValue(0, nil)];128 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]129 assertWithMatcher:grey_pickerColumnSetToValue(1, nil)];130}131- (void)testViewForRowDefined {132 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];133 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"viewForRowDelegateSwitch")]134 performAction:grey_turnSwitchOn(YES)];135 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]136 performAction:grey_setPickerColumnToValue(0, @"Green")];137 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]138 performAction:grey_setPickerColumnToValue(1, @"4")];139 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]140 assertWithMatcher:grey_pickerColumnSetToValue(0, @"Green")];141 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]142 assertWithMatcher:grey_pickerColumnSetToValue(1, @"4")];143}144- (void)testAttributedTitleForRowDefined {145 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];146 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"attributedTitleForRowDelegateSwitch")]147 performAction:grey_turnSwitchOn(YES)];148 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]149 performAction:grey_setPickerColumnToValue(0, @"Green")];150 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]151 performAction:grey_setPickerColumnToValue(1, @"4")];152 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]153 assertWithMatcher:grey_pickerColumnSetToValue(0, @"Green")];154 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]155 assertWithMatcher:grey_pickerColumnSetToValue(1, @"4")];156}157- (void)testTitleForRowDefined {158 [[EarlGrey selectElementWithMatcher:grey_text(@"Custom")] performAction:grey_tap()];159 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"titleForRowDelegateSwitch")]160 performAction:grey_turnSwitchOn(YES)];161 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]162 performAction:grey_setPickerColumnToValue(0, @"Green")];163 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]164 performAction:grey_setPickerColumnToValue(1, @"4")];165 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]166 assertWithMatcher:grey_pickerColumnSetToValue(0, @"Green")];167 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"CustomPickerId")]168 assertWithMatcher:grey_pickerColumnSetToValue(1, @"4")];169}170@end...
FTRUITableViewTest.m
Source:FTRUITableViewTest.m
...64 // Add positive insets using this format {top,left,bottom,right}65 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"insets value")]66 performAction:grey_typeText(@"{100,0,0,0}\n")];67 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"insets toggle")]68 performAction:grey_turnSwitchOn(YES)];69 // Scroll down.70 [[self ftr_scrollToCellAtIndex:20 byScrollingInAmounts:200 InDirection:kGREYDirectionDown]71 assertWithMatcher:grey_notNil()];72 // Scroll to top and verify that we are at the top.73 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"main_table_view")]74 performAction:grey_scrollToContentEdge(kGREYContentEdgeTop)]75 assertWithMatcher:grey_scrolledToContentEdge(kGREYContentEdgeTop)];76}77- (void)testScrollToTopWithNegativeInsets {78 // Add negative insets using this format {top,left,bottom,right}79 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"insets value")]80 performAction:grey_typeText(@"{-100,0,0,0}\n")];81 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"insets toggle")]82 performAction:grey_turnSwitchOn(YES)];83 // Scroll down.84 [[self ftr_scrollToCellAtIndex:20 byScrollingInAmounts:200 InDirection:kGREYDirectionDown]85 assertWithMatcher:grey_notNil()];86 // Scroll to top and verify that we are at the top.87 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"main_table_view")]88 performAction:grey_scrollToContentEdge(kGREYContentEdgeTop)]89 assertWithMatcher:grey_scrolledToContentEdge(kGREYContentEdgeTop)];90}91- (void)testScrollToTopWhenAlreadyAtTheTopWithoutBounce {92 GREYActionBlock *bounceOff =93 [[GREYActionBlock alloc] initWithName:@"toggleBounces"94 constraints:grey_kindOfClass([UIScrollView class])95 performBlock:^BOOL(UIScrollView *scrollView,96 NSError *__strong *error) {...
UITableViewTest.m
Source:UITableViewTest.m
...63 // Add positive insets using this format {top,left,bottom,right}64 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"insets value")]65 performAction:grey_typeText(@"{100,0,0,0}\n")];66 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"insets toggle")]67 performAction:grey_turnSwitchOn(YES)];68 // Scroll down.69 [[self ftr_scrollToCellAtIndex:20 byScrollingInAmounts:20070 InDirection:kGREYDirectionDown] assertWithMatcher:grey_notNil()];71 // Scroll to top and verify that we are at the top.72 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"main_table_view")]73 performAction:grey_scrollToContentEdge(kGREYContentEdgeTop)]74 assertWithMatcher:grey_scrolledToContentEdge(kGREYContentEdgeTop)];75}76- (void)testScrollToTopWithNegativeInsets {77 // Add negative insets using this format {top,left,bottom,right}78 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"insets value")]79 performAction:grey_typeText(@"{-100,0,0,0}\n")];80 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"insets toggle")]81 performAction:grey_turnSwitchOn(YES)];82 // Scroll down.83 [[self ftr_scrollToCellAtIndex:20 byScrollingInAmounts:20084 InDirection:kGREYDirectionDown] assertWithMatcher:grey_notNil()];85 // Scroll to top and verify that we are at the top.86 [[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"main_table_view")]87 performAction:grey_scrollToContentEdge(kGREYContentEdgeTop)]88 assertWithMatcher:grey_scrolledToContentEdge(kGREYContentEdgeTop)];89}90- (void)testScrollToTopWhenAlreadyAtTheTopWithoutBounce {91 id<GREYAction> bounceOff =92 [GREYHostApplicationDistantObject.sharedInstance actionForTableViewBoundOff];93 // Verify this test with and without bounce enabled by toggling it.94 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"main_table_view")]95 performAction:bounceOff];...
FirstEarlGreyTest.m
Source:FirstEarlGreyTest.m
...14// [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"switch")]15// assertWithMatcher:grey_sufficientlyVisible()];16 //æ¾å°æ§ä»¶ï¼æ§è¡å
³æä½17 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"switch")]18 performAction:grey_turnSwitchOn(YES) ];19 //对æ§ä»¶çç¶æè¿è¡æè¨20 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"switch")]21 assertWithMatcher:grey_switchWithOnState(YES) ];22}23@end...
grey_turnSwitchOn
Using AI Code Generation
1[GREYElementInteraction interactionWithElementMatcher:grey_accessibilityID(@"switch")]2 .performAction(grey_turnSwitchOn());3- (id<GREYAction>)performAction:(id<GREYAction>)action {4 return [GREYPerformActionAction actionWithAction:action];5}6+ (instancetype)actionWithAction:(id<GREYAction>)action {7 return [[GREYPerformActionAction alloc] initWithAction:action];8}9- (instancetype)initWithAction:(id<GREYAction>)action {10 NSString *name = [NSString stringWithFormat:@"Perform Action: %@", [action name]];11 self = [super initWithName:name constraints:grey_respondsToSelector(@selector(accessibilityElement))];12 if (self) {13 _action = action;14 }15 return self;16}17- (BOOL)perform:(id)element error:(__strong NSError **)errorOrNil {18 return [_action perform:element error:errorOrNil];19}20id<GREYAction> grey_turnSwitchOn() {21 constraints:grey_respondsToSelector(@selector(isOn))22 perform:^BOOL(UISwitch *switchElement, __strong NSError **errorOrNil) {23 if (!switchElement.isOn) {24 [switchElement setOn:YES animated:YES];25 }26 return YES;27 }];28}29+ (instancetype)actionWithName:(NSString *)name30 constraints:(id<GREYMatcher>)constraints31 perform:(GREYPerformBlock)performBlock {32 perform:performBlock];33}34- (instancetype)initWithName:(NSString *)name35 constraints:(id<GREYMatcher>)constraints36 perform:(GREYPerformBlock)performBlock {37 self = [super init];38 if (self) {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!