InAppMessagingDisplayCardViewUITests.swift 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Copyright 2019 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 XCTest
  17. class InAppMessagingDisplayCardViewUITests: InAppMessagingDisplayUITestsBase {
  18. var app: XCUIApplication!
  19. var verificationLabel: XCUIElement!
  20. var messageCardView: XCUIElement!
  21. var cardImageView: XCUIElement!
  22. var cardTitleLabel: XCUIElement!
  23. var cardBodyTextView: XCUIElement!
  24. var cardPrimaryActionButton: XCUIElement!
  25. var cardSecondaryActionButton: XCUIElement!
  26. var onScreenElements: [XCUIElement]!
  27. override func setUp() {
  28. super.setUp()
  29. app = XCUIApplication()
  30. verificationLabel = app.staticTexts["verification-label-modal"]
  31. messageCardView = app.otherElements["message-card-view"]
  32. cardImageView = app.images["card-image-view"]
  33. cardTitleLabel = app.staticTexts["card-title-label"]
  34. cardBodyTextView = app.textViews["card-body-text-view"]
  35. cardPrimaryActionButton = app.buttons["card-primary-action-button"]
  36. cardSecondaryActionButton = app.buttons["card-secondary-action-button"]
  37. onScreenElements = [
  38. cardImageView,
  39. cardTitleLabel,
  40. cardBodyTextView,
  41. cardPrimaryActionButton,
  42. cardSecondaryActionButton,
  43. ]
  44. continueAfterFailure = false
  45. app.launch()
  46. }
  47. func testRegularOneButtonWithBothImages() {
  48. app.tabBars.buttons["Card Messages"].tap()
  49. app.buttons["Regular one button with both images"].tap()
  50. waitForElementToAppear(messageCardView)
  51. verifyOnScreenElementsExcluding(excluding: [cardSecondaryActionButton])
  52. cardPrimaryActionButton.tap()
  53. waitForElementToDisappear(messageCardView)
  54. XCTAssertTrue(verificationLabel.label.contains("clicked"))
  55. }
  56. func testRegularOneButtonWithOnlyPortrait() {
  57. app.tabBars.buttons["Card Messages"].tap()
  58. app.buttons["Regular one button with only portrait"].tap()
  59. waitForElementToAppear(messageCardView)
  60. verifyOnScreenElementsExcluding(excluding: [cardSecondaryActionButton])
  61. cardPrimaryActionButton.tap()
  62. waitForElementToDisappear(messageCardView)
  63. XCTAssertTrue(verificationLabel.label.contains("clicked"))
  64. }
  65. func testRegularTwoButtonWithBothImages() {
  66. app.tabBars.buttons["Card Messages"].tap()
  67. app.buttons["Regular two button with both images"].tap()
  68. waitForElementToAppear(messageCardView)
  69. verifyOnScreenElementsExcluding(excluding: [])
  70. cardSecondaryActionButton.tap()
  71. waitForElementToDisappear(messageCardView)
  72. XCTAssertTrue(verificationLabel.label.contains("dismissed"))
  73. }
  74. func testLongTitleRegularBody() {
  75. app.tabBars.buttons["Card Messages"].tap()
  76. app.buttons["Long title, regular body"].tap()
  77. waitForElementToAppear(messageCardView)
  78. verifyOnScreenElementsExcluding(excluding: [])
  79. cardSecondaryActionButton.tap()
  80. waitForElementToDisappear(messageCardView)
  81. XCTAssertTrue(verificationLabel.label.contains("dismissed"))
  82. }
  83. func testRegularTitleLongBody() {
  84. app.tabBars.buttons["Card Messages"].tap()
  85. app.buttons["Regular title, long body"].tap()
  86. waitForElementToAppear(messageCardView)
  87. verifyOnScreenElementsExcluding(excluding: [])
  88. cardSecondaryActionButton.tap()
  89. waitForElementToDisappear(messageCardView)
  90. XCTAssertTrue(verificationLabel.label.contains("dismissed"))
  91. }
  92. func testLongTitleNoBody() {
  93. app.tabBars.buttons["Card Messages"].tap()
  94. app.buttons["Long title, no body"].tap()
  95. waitForElementToAppear(messageCardView)
  96. verifyOnScreenElementsExcluding(excluding: [cardBodyTextView])
  97. cardSecondaryActionButton.tap()
  98. waitForElementToDisappear(messageCardView)
  99. XCTAssertTrue(verificationLabel.label.contains("dismissed"))
  100. }
  101. func testLongPrimaryButton() {
  102. app.tabBars.buttons["Card Messages"].tap()
  103. app.buttons["Long primary button"].tap()
  104. waitForElementToAppear(messageCardView)
  105. verifyOnScreenElementsExcluding(excluding: [])
  106. cardSecondaryActionButton.tap()
  107. waitForElementToDisappear(messageCardView)
  108. XCTAssertTrue(verificationLabel.label.contains("dismissed"))
  109. }
  110. func testLongSecondaryButton() {
  111. app.tabBars.buttons["Card Messages"].tap()
  112. app.buttons["Long secondary button"].tap()
  113. waitForElementToAppear(messageCardView)
  114. verifyOnScreenElementsExcluding(excluding: [])
  115. cardPrimaryActionButton.tap()
  116. waitForElementToDisappear(messageCardView)
  117. XCTAssertTrue(verificationLabel.label.contains("clicked"))
  118. }
  119. func testSmallImage() {
  120. app.tabBars.buttons["Card Messages"].tap()
  121. app.buttons["Small image"].tap()
  122. waitForElementToAppear(messageCardView)
  123. verifyOnScreenElementsExcluding(excluding: [cardSecondaryActionButton])
  124. cardPrimaryActionButton.tap()
  125. waitForElementToDisappear(messageCardView)
  126. XCTAssertTrue(verificationLabel.label.contains("clicked"))
  127. }
  128. func testHugeImage() {
  129. app.tabBars.buttons["Card Messages"].tap()
  130. app.buttons["Huge image"].tap()
  131. waitForElementToAppear(messageCardView)
  132. verifyOnScreenElementsExcluding(excluding: [cardSecondaryActionButton])
  133. cardPrimaryActionButton.tap()
  134. waitForElementToDisappear(messageCardView)
  135. XCTAssertTrue(verificationLabel.label.contains("clicked"))
  136. }
  137. func verifyOnScreenElementsExcluding(excluding: [XCUIElement]) {
  138. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  139. for orientation in orientantions {
  140. XCUIDevice.shared.orientation = orientation
  141. for element in onScreenElements {
  142. if !excluding.contains(element) {
  143. break
  144. }
  145. XCTAssert(isUIElementWithinUIWindow(element))
  146. if element != messageCardView {
  147. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: element))
  148. }
  149. }
  150. }
  151. }
  152. }