InAppMessagingDisplayBannerViewUITests.swift 7.0 KB

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