InAppMessagingDisplayUITestsBase.swift 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright 2018 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import Foundation
  17. import XCTest
  18. class InAppMessagingDisplayUITestsBase: XCTestCase {
  19. func waitForElementToAppear(_ element: XCUIElement, _ timeoutInSeconds: TimeInterval = 60) {
  20. let existsPredicate = NSPredicate(format: "exists == true")
  21. expectation(for: existsPredicate, evaluatedWith: element, handler: nil)
  22. waitForExpectations(timeout: timeoutInSeconds, handler: nil)
  23. }
  24. func waitForElementToDisappear(_ element: XCUIElement, _ timeoutInSeconds: TimeInterval = 60) {
  25. let existsPredicate = NSPredicate(format: "exists == false")
  26. expectation(for: existsPredicate, evaluatedWith: element, handler: nil)
  27. waitForExpectations(timeout: timeoutInSeconds, handler: nil)
  28. }
  29. func childFrameWithinParentBound(parent: XCUIElement, child: XCUIElement) -> Bool {
  30. return parent.frame.contains(child.frame)
  31. }
  32. func isUIElementWithinUIWindow(_ uiElement: XCUIElement) -> Bool {
  33. let app = XCUIApplication()
  34. let window = app.windows.element(boundBy: 0)
  35. return window.frame.contains(uiElement.frame)
  36. }
  37. func isElementExistentAndHavingSize(_ uiElement: XCUIElement) -> Bool {
  38. // on iOS 9.3 for a XCUIElement whose height or width <=0, uiElement.exists still returns true
  39. // on iOS 10.3, for such an element uiElement.exists returns false
  40. // this function is to handle the existence (in our semanatic visible) testing for both cases
  41. return uiElement.exists && uiElement.frame.size.height > 0.1 && uiElement.frame.size.width > 0.1
  42. }
  43. }