FBSafariAlertTests.m 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. @implementation FBSafariAlertIntegrationTests
  23. - (void)setUp
  24. {
  25. [super setUp];
  26. self.session = [FBSession initWithApplication:XCUIApplication.fb_activeApplication];
  27. [self.session launchApplicationWithBundleId:FB_SAFARI_BUNDLE_ID
  28. shouldWaitForQuiescence:nil
  29. arguments:nil
  30. environment:nil];
  31. self.safariApp = self.session.activeApplication;
  32. }
  33. - (void)tearDown
  34. {
  35. [self.session terminateApplicationWithBundleId:FB_SAFARI_BUNDLE_ID];
  36. }
  37. - (void)disabled_testCanHandleSafariInputPrompt
  38. {
  39. XCUIElement *urlInput = [[self.safariApp
  40. descendantsMatchingType:XCUIElementTypeTextField]
  41. matchingPredicate:[
  42. NSPredicate predicateWithFormat:@"label == 'Address' or label == 'URL'"
  43. ]].firstMatch;
  44. if (!urlInput.exists) {
  45. [[[self.safariApp descendantsMatchingType:XCUIElementTypeButton] matchingPredicate:[
  46. NSPredicate predicateWithFormat:@"label == 'Address' or label == 'URL'"]].firstMatch tap];
  47. }
  48. XCTAssertTrue([urlInput fb_typeText:@"https://www.w3schools.com/js/tryit.asp?filename=tryjs_alert"
  49. shouldClear:YES
  50. error:nil]);
  51. [[[self.safariApp descendantsMatchingType:XCUIElementTypeButton] matchingIdentifier:@"Go"].firstMatch tap];
  52. XCUIElement *clickMeButton = [[self.safariApp descendantsMatchingType:XCUIElementTypeButton]
  53. matchingPredicate:[NSPredicate predicateWithFormat:@"label == 'Try it'"]].firstMatch;
  54. XCTAssertTrue([clickMeButton waitForExistenceWithTimeout:15.0]);
  55. [clickMeButton tap];
  56. FBAlert *alert = [FBAlert alertWithApplication:self.safariApp];
  57. FBAssertWaitTillBecomesTrue([alert.text isEqualToString:@"I am an alert box!"]);
  58. NSArray *buttonLabels = alert.buttonLabels;
  59. XCTAssertEqualObjects(buttonLabels.firstObject, @"Close");
  60. XCTAssertNotNil([self.safariApp fb_descendantsMatchingXPathQuery:@"//XCUIElementTypeButton[@label='Close']"
  61. shouldReturnAfterFirstMatch:YES].firstObject);
  62. XCTAssertTrue([alert acceptWithError:nil]);
  63. }
  64. @end