InAppMessagingDisplayBannerViewUITests.swift 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 InAppMessagingDisplayBannerViewUITests: InAppMessagingDisplayUITestsBase {
  19. var app: XCUIApplication!
  20. var verificationLabel: XCUIElement!
  21. override func setUp() {
  22. super.setUp()
  23. // Put setup code here. This method is called before the invocation of each test method in the
  24. // class.
  25. // In UI tests it is usually best to stop immediately when a failure occurs.
  26. continueAfterFailure = false
  27. // UI tests must launch the application that they test. Doing this in setup will make sure it
  28. // happens for each test method.
  29. XCUIApplication().launch()
  30. // In UI tests it’s important to set the initial state - such as interface orientation -
  31. // required for your tests before they run. The setUp method is a good place to do this.
  32. app = XCUIApplication()
  33. verificationLabel = app.staticTexts["verification-label-banner"]
  34. }
  35. override func tearDown() {
  36. // Put teardown code here. This method is called after the invocation of each test method in the
  37. // class.
  38. super.tearDown()
  39. }
  40. func testNormalBannerView() {
  41. app.tabBars.buttons["Banner Messages"].tap()
  42. let titleElement = app.staticTexts["banner-message-title-view"]
  43. let imageView = app.images["banner-image-view"]
  44. let bodyElement = app.staticTexts["banner-body-label"]
  45. let bannerUIView = app.otherElements["banner-mode-uiview"]
  46. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  47. for orientation in orientantions {
  48. XCUIDevice.shared.orientation = orientation
  49. app.buttons["Show Regular Banner View"].tap()
  50. waitForElementToAppear(bannerUIView)
  51. XCTAssert(isElementExistentAndHavingSize(imageView))
  52. XCTAssert(isElementExistentAndHavingSize(titleElement))
  53. XCTAssert(isElementExistentAndHavingSize(bodyElement))
  54. // This also verifies that up-swiping gesture would dismiss
  55. // the banner view
  56. bannerUIView.swipeUp()
  57. waitForElementToDisappear(bannerUIView)
  58. let labelValue = verificationLabel.label
  59. XCTAssertTrue(labelValue.contains("dismissed"))
  60. }
  61. }
  62. func testBannerViewWithoutImage() {
  63. app.tabBars.buttons["Banner Messages"].tap()
  64. let titleElement = app.staticTexts["banner-message-title-view"]
  65. let imageViewElement = app.images["banner-image-view"]
  66. let bodyElement = app.staticTexts["banner-body-label"]
  67. let bannerUIView = app.otherElements["banner-mode-uiview"]
  68. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  69. for orientation in orientantions {
  70. XCUIDevice.shared.orientation = orientation
  71. app.buttons["Without Image"].tap()
  72. waitForElementToAppear(bannerUIView)
  73. XCTAssert(isElementExistentAndHavingSize(titleElement))
  74. XCTAssert(isElementExistentAndHavingSize(bodyElement))
  75. XCTAssert(!isElementExistentAndHavingSize(imageViewElement))
  76. bannerUIView.tap()
  77. waitForElementToDisappear(bannerUIView)
  78. let labelValue = verificationLabel.label
  79. XCTAssertTrue(labelValue.contains("clicked"))
  80. }
  81. }
  82. func testBannerViewWithLongTitle() {
  83. app.tabBars.buttons["Banner Messages"].tap()
  84. let titleElement = app.staticTexts["banner-message-title-view"]
  85. let imageView = app.images["banner-image-view"]
  86. let bodyElement = app.staticTexts["banner-body-label"]
  87. let bannerUIView = app.otherElements["banner-mode-uiview"]
  88. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  89. for orientation in orientantions {
  90. XCUIDevice.shared.orientation = orientation
  91. app.buttons["With Long Title"].tap()
  92. waitForElementToAppear(bannerUIView)
  93. XCTAssert(isElementExistentAndHavingSize(imageView))
  94. XCTAssert(isElementExistentAndHavingSize(titleElement))
  95. XCTAssert(isElementExistentAndHavingSize(bodyElement))
  96. bannerUIView.swipeUp()
  97. waitForElementToDisappear(bannerUIView)
  98. }
  99. }
  100. func testBannerViewWithWideImage() {
  101. app.tabBars.buttons["Banner Messages"].tap()
  102. let titleElement = app.staticTexts["banner-message-title-view"]
  103. let imageView = app.images["banner-image-view"]
  104. let bodyElement = app.staticTexts["banner-body-label"]
  105. let bannerUIView = app.otherElements["banner-mode-uiview"]
  106. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  107. for orientation in orientantions {
  108. XCUIDevice.shared.orientation = orientation
  109. app.buttons["With Wide Image"].tap()
  110. waitForElementToAppear(bannerUIView)
  111. XCTAssert(isElementExistentAndHavingSize(imageView))
  112. XCTAssert(isElementExistentAndHavingSize(titleElement))
  113. XCTAssert(isElementExistentAndHavingSize(bodyElement))
  114. bannerUIView.swipeUp()
  115. waitForElementToDisappear(bannerUIView)
  116. }
  117. }
  118. func testBannerViewWithThinImage() {
  119. app.tabBars.buttons["Banner Messages"].tap()
  120. let titleElement = app.staticTexts["banner-message-title-view"]
  121. let imageView = app.images["banner-image-view"]
  122. let bodyElement = app.staticTexts["banner-body-label"]
  123. let bannerUIView = app.otherElements["banner-mode-uiview"]
  124. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  125. for orientation in orientantions {
  126. XCUIDevice.shared.orientation = orientation
  127. app.buttons["With Thin Image"].tap()
  128. waitForElementToAppear(bannerUIView)
  129. XCTAssert(isElementExistentAndHavingSize(imageView))
  130. XCTAssert(isElementExistentAndHavingSize(titleElement))
  131. XCTAssert(isElementExistentAndHavingSize(bodyElement))
  132. bannerUIView.swipeUp()
  133. waitForElementToDisappear(bannerUIView)
  134. }
  135. }
  136. func testBannerViewWithLargeBody() {
  137. app.tabBars.buttons["Banner Messages"].tap()
  138. let titleElement = app.staticTexts["banner-message-title-view"]
  139. let imageView = app.images["banner-image-view"]
  140. let bodyElement = app.staticTexts["banner-body-label"]
  141. let bannerUIView = app.otherElements["banner-mode-uiview"]
  142. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  143. for orientation in orientantions {
  144. XCUIDevice.shared.orientation = orientation
  145. app.buttons["With Large Body Text"].tap()
  146. waitForElementToAppear(bannerUIView)
  147. XCTAssert(isElementExistentAndHavingSize(imageView))
  148. XCTAssert(isElementExistentAndHavingSize(titleElement))
  149. XCTAssert(isElementExistentAndHavingSize(bodyElement))
  150. bannerUIView.swipeUp()
  151. waitForElementToDisappear(bannerUIView)
  152. }
  153. }
  154. }