FBSafariAlertTests.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import <XCTest/XCTest.h>
  10. #import "FBIntegrationTestCase.h"
  11. #import "FBTestMacros.h"
  12. #import "FBMacros.h"
  13. #import "FBSession.h"
  14. #import "FBXCodeCompatibility.h"
  15. #import "XCUIElement+FBTyping.h"
  16. #import "FBAlert.h"
  17. #import "XCUIApplication+FBAlert.h"
  18. @interface FBSafariAlertIntegrationTests : FBIntegrationTestCase
  19. @property (nonatomic) FBSession *session;
  20. @property (nonatomic) XCUIApplication *safariApp;
  21. @end
  22. static NSString *const SAFARI_BUNDLE_ID = @"com.apple.mobilesafari";
  23. @implementation FBSafariAlertIntegrationTests
  24. - (void)setUp
  25. {
  26. [super setUp];
  27. self.session = [FBSession initWithApplication:XCUIApplication.fb_activeApplication];
  28. [self.session launchApplicationWithBundleId:SAFARI_BUNDLE_ID
  29. shouldWaitForQuiescence:nil
  30. arguments:nil
  31. environment:nil];
  32. self.safariApp = self.session.activeApplication;
  33. }
  34. - (void)tearDown
  35. {
  36. [self.session terminateApplicationWithBundleId:SAFARI_BUNDLE_ID];
  37. }
  38. - (void)disabled_testCanHandleSafariInputPrompt
  39. {
  40. XCUIElement *urlInput = [[self.safariApp
  41. descendantsMatchingType:XCUIElementTypeTextField]
  42. matchingPredicate:[
  43. NSPredicate predicateWithFormat:@"label == 'Address' or label == 'URL'"
  44. ]].firstMatch;
  45. if (!urlInput.exists) {
  46. [[[self.safariApp descendantsMatchingType:XCUIElementTypeButton] matchingPredicate:[
  47. NSPredicate predicateWithFormat:@"label == 'Address' or label == 'URL'"]].firstMatch tap];
  48. }
  49. XCTAssertTrue([urlInput fb_typeText:@"https://www.w3schools.com/js/tryit.asp?filename=tryjs_alert"
  50. shouldClear:YES
  51. error:nil]);
  52. [[[self.safariApp descendantsMatchingType:XCUIElementTypeButton] matchingIdentifier:@"Go"].firstMatch tap];
  53. XCUIElement *clickMeButton = [[self.safariApp descendantsMatchingType:XCUIElementTypeButton]
  54. matchingPredicate:[NSPredicate predicateWithFormat:@"label == 'Try it'"]].firstMatch;
  55. XCTAssertTrue([clickMeButton waitForExistenceWithTimeout:15.0]);
  56. [clickMeButton tap];
  57. FBAlert *alert = [FBAlert alertWithApplication:self.safariApp];
  58. FBAssertWaitTillBecomesTrue([alert.text isEqualToString:@"I am an alert box!"]);
  59. NSArray *buttonLabels = alert.buttonLabels;
  60. XCTAssertEqualObjects(buttonLabels.firstObject, @"Close");
  61. XCTAssertNotNil([self.safariApp fb_descendantsMatchingXPathQuery:@"//XCUIElementTypeButton[@label='Close']"
  62. shouldReturnAfterFirstMatch:YES].firstObject);
  63. XCTAssertTrue([alert acceptWithError:nil]);
  64. }
  65. @end