InAppMessagingDisplayModalViewUITests.swift 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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 XCTest
  17. class InAppMessagingDisplayModalViewUITests: InAppMessagingDisplayUITestsBase {
  18. var app: XCUIApplication!
  19. var verificationLabel: XCUIElement!
  20. override func setUp() {
  21. super.setUp()
  22. // Put setup code here. This method is called before the invocation of each test method in the
  23. // 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
  27. // happens for each test method.
  28. XCUIApplication().launch()
  29. app = XCUIApplication()
  30. verificationLabel = app.staticTexts["verification-label-modal"]
  31. // In UI tests it’s important to set the initial state - such as interface orientation -
  32. // required for your tests before they run. The setUp method is a good place to do this.
  33. }
  34. override func tearDown() {
  35. // Put teardown code here. This method is called after the invocation of each test method in the
  36. // class.
  37. super.tearDown()
  38. }
  39. func testNormalModalView() {
  40. app.tabBars.buttons["Modal Messages"].tap()
  41. let messageCardView = app.otherElements["message-card-view"]
  42. let closeButton = app.buttons["close-button"]
  43. let imageView = app.images["modal-image-view"]
  44. let actionButton = app.buttons["message-action-button"]
  45. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  46. for orientation in orientantions {
  47. XCUIDevice.shared.orientation = orientation
  48. app.buttons["Regular"].tap()
  49. waitForElementToAppear(closeButton)
  50. XCTAssert(isElementExistentAndHavingSize(actionButton))
  51. XCTAssert(isElementExistentAndHavingSize(imageView))
  52. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  53. XCTAssert(isElementExistentAndHavingSize(closeButton))
  54. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  55. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
  56. if orientation == UIDeviceOrientation.portrait {
  57. actionButton.tap()
  58. } else {
  59. closeButton.tap()
  60. }
  61. waitForElementToDisappear(messageCardView)
  62. let labelValue = verificationLabel.label
  63. if orientation == UIDeviceOrientation.portrait {
  64. XCTAssertTrue(labelValue.contains("clicked"))
  65. } else {
  66. XCTAssertTrue(labelValue.contains("dismissed"))
  67. }
  68. }
  69. }
  70. func testModalViewWithWideImage() {
  71. app.tabBars.buttons["Modal Messages"].tap()
  72. let messageCardView = app.otherElements["message-card-view"]
  73. let closeButton = app.buttons["close-button"]
  74. let imageView = app.images["modal-image-view"]
  75. let actionButton = app.buttons["message-action-button"]
  76. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  77. for orientation in orientantions {
  78. XCUIDevice.shared.orientation = orientation
  79. app.buttons["Wide Image"].tap()
  80. waitForElementToAppear(closeButton)
  81. XCTAssert(isElementExistentAndHavingSize(actionButton))
  82. XCTAssert(isElementExistentAndHavingSize(imageView))
  83. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  84. XCTAssert(isElementExistentAndHavingSize(closeButton))
  85. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  86. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
  87. app.buttons["close-button"].tap()
  88. waitForElementToDisappear(messageCardView)
  89. let labelValue = verificationLabel.label
  90. XCTAssertTrue(labelValue.contains("dismissed"))
  91. }
  92. }
  93. func testModalViewWithNarrowImage() {
  94. app.tabBars.buttons["Modal Messages"].tap()
  95. let messageCardView = app.otherElements["message-card-view"]
  96. let closeButton = app.buttons["close-button"]
  97. let imageView = app.images["modal-image-view"]
  98. let actionButton = app.buttons["message-action-button"]
  99. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  100. for orientation in orientantions {
  101. XCUIDevice.shared.orientation = orientation
  102. app.buttons["Thin Image"].tap()
  103. waitForElementToAppear(closeButton)
  104. XCTAssert(isElementExistentAndHavingSize(actionButton))
  105. XCTAssert(isElementExistentAndHavingSize(imageView))
  106. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  107. XCTAssert(isElementExistentAndHavingSize(closeButton))
  108. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  109. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
  110. actionButton.tap()
  111. waitForElementToDisappear(messageCardView)
  112. let labelValue = verificationLabel.label
  113. XCTAssertTrue(labelValue.contains("clicked"))
  114. }
  115. }
  116. func testModalViewWithoutImage() {
  117. app.tabBars.buttons["Modal Messages"].tap()
  118. let messageCardView = app.otherElements["message-card-view"]
  119. let closeButton = app.buttons["close-button"]
  120. let actionButton = app.buttons["message-action-button"]
  121. let imageView = app.images["modal-image-view"]
  122. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  123. for orientation in orientantions {
  124. XCUIDevice.shared.orientation = orientation
  125. app.buttons["Without Image"].tap()
  126. waitForElementToAppear(closeButton)
  127. XCTAssert(isElementExistentAndHavingSize(actionButton))
  128. XCTAssert(isElementExistentAndHavingSize(closeButton))
  129. XCTAssertFalse(isElementExistentAndHavingSize(imageView))
  130. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  131. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  132. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
  133. app.buttons["close-button"].tap()
  134. waitForElementToDisappear(messageCardView)
  135. let labelValue = verificationLabel.label
  136. XCTAssertTrue(labelValue.contains("dismissed"))
  137. }
  138. }
  139. func testModalViewWithoutImageOrActionButton() {
  140. app.tabBars.buttons["Modal Messages"].tap()
  141. let messageCardView = app.otherElements["message-card-view"]
  142. let closeButton = app.buttons["close-button"]
  143. let actionButton = app.buttons["message-action-button"]
  144. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  145. for orientation in orientantions {
  146. XCUIDevice.shared.orientation = orientation
  147. app.buttons["Wthout Image or Action Button"].tap()
  148. waitForElementToAppear(closeButton)
  149. XCTAssertFalse(isElementExistentAndHavingSize(actionButton))
  150. XCTAssert(isElementExistentAndHavingSize(closeButton))
  151. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  152. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  153. app.buttons["close-button"].tap()
  154. waitForElementToDisappear(messageCardView)
  155. XCUIDevice.shared.orientation = .portrait
  156. }
  157. }
  158. func testModalViewWithoutActionButton() {
  159. app.tabBars.buttons["Modal Messages"].tap()
  160. let messageCardView = app.otherElements["message-card-view"]
  161. let closeButton = app.buttons["close-button"]
  162. let imageView = app.images["modal-image-view"]
  163. let actionButton = app.buttons["message-action-button"]
  164. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  165. for orientation in orientantions {
  166. XCUIDevice.shared.orientation = orientation
  167. app.buttons["Without Action Button"].tap()
  168. waitForElementToAppear(closeButton)
  169. XCTAssertFalse(isElementExistentAndHavingSize(actionButton))
  170. XCTAssert(isElementExistentAndHavingSize(closeButton))
  171. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  172. XCTAssert(isElementExistentAndHavingSize(imageView))
  173. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  174. app.buttons["close-button"].tap()
  175. waitForElementToDisappear(messageCardView)
  176. }
  177. }
  178. func testModalViewWithLongMessageTitle() {
  179. app.tabBars.buttons["Modal Messages"].tap()
  180. let messageCardView = app.otherElements["message-card-view"]
  181. let closeButton = app.buttons["close-button"]
  182. let imageView = app.images["modal-image-view"]
  183. let bodyTextview = app.textViews["message-body-textview"]
  184. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  185. for orientation in orientantions {
  186. XCUIDevice.shared.orientation = orientation
  187. app.buttons["Large Title Text"].tap()
  188. waitForElementToAppear(closeButton)
  189. let actionButton = app.buttons["message-action-button"]
  190. XCTAssert(isElementExistentAndHavingSize(actionButton))
  191. XCTAssert(isElementExistentAndHavingSize(closeButton))
  192. XCTAssert(isElementExistentAndHavingSize(bodyTextview))
  193. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  194. XCTAssert(!isElementExistentAndHavingSize(imageView))
  195. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  196. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
  197. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: bodyTextview))
  198. app.buttons["close-button"].tap()
  199. waitForElementToDisappear(messageCardView)
  200. }
  201. }
  202. func testModalViewWithLongMessageBody() {
  203. app.tabBars.buttons["Modal Messages"].tap()
  204. let messageCardView = app.otherElements["message-card-view"]
  205. let closeButton = app.buttons["close-button"]
  206. let imageView = app.images["modal-image-view"]
  207. let bodyTextview = app.textViews["message-body-textview"]
  208. let actionButton = app.buttons["message-action-button"]
  209. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  210. for orientation in orientantions {
  211. XCUIDevice.shared.orientation = orientation
  212. app.buttons["Large Title Text"].tap()
  213. waitForElementToAppear(closeButton)
  214. XCTAssert(isElementExistentAndHavingSize(actionButton))
  215. XCTAssert(isElementExistentAndHavingSize(closeButton))
  216. XCTAssert(isElementExistentAndHavingSize(bodyTextview))
  217. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  218. XCTAssert(!isElementExistentAndHavingSize(imageView))
  219. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  220. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
  221. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: bodyTextview))
  222. actionButton.tap()
  223. waitForElementToDisappear(messageCardView)
  224. let labelValue = verificationLabel.label
  225. XCTAssertTrue(labelValue.contains("clicked"))
  226. }
  227. }
  228. func testModalViewWithLongMessageTitleAndMessageBody() {
  229. app.tabBars.buttons["Modal Messages"].tap()
  230. let messageCardView = app.otherElements["message-card-view"]
  231. let closeButton = app.buttons["close-button"]
  232. let imageView = app.images["modal-image-view"]
  233. let bodyTextview = app.textViews["message-body-textview"]
  234. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  235. for orientation in orientantions {
  236. XCUIDevice.shared.orientation = orientation
  237. app.buttons["With Large Title and Body"].tap()
  238. waitForElementToAppear(closeButton)
  239. let actionButton = app.buttons["message-action-button"]
  240. XCTAssert(isElementExistentAndHavingSize(actionButton))
  241. XCTAssert(isElementExistentAndHavingSize(closeButton))
  242. XCTAssert(isElementExistentAndHavingSize(bodyTextview))
  243. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  244. XCTAssert(isElementExistentAndHavingSize(imageView))
  245. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  246. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
  247. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: bodyTextview))
  248. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: imageView))
  249. app.buttons["close-button"].tap()
  250. waitForElementToDisappear(messageCardView)
  251. }
  252. }
  253. func testModalViewWithLongMessageTitleAndMessageBodyWithoutImage() {
  254. let app = XCUIApplication()
  255. app.tabBars.buttons["Modal Messages"].tap()
  256. let messageCardView = app.otherElements["message-card-view"]
  257. let closeButton = app.buttons["close-button"]
  258. let imageView = app.images["modal-image-view"]
  259. let bodyTextview = app.textViews["message-body-textview"]
  260. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  261. for orientation in orientantions {
  262. XCUIDevice.shared.orientation = orientation
  263. app.buttons["With Large Title and Body Without Image"].tap()
  264. waitForElementToAppear(closeButton)
  265. let actionButton = app.buttons["message-action-button"]
  266. XCTAssert(isElementExistentAndHavingSize(actionButton))
  267. XCTAssert(isElementExistentAndHavingSize(closeButton))
  268. XCTAssert(isElementExistentAndHavingSize(bodyTextview))
  269. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  270. XCTAssert(!isElementExistentAndHavingSize(imageView))
  271. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  272. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
  273. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: bodyTextview))
  274. app.buttons["close-button"].tap()
  275. waitForElementToDisappear(messageCardView)
  276. }
  277. }
  278. func testModalViewWithLongMessageTitleWithoutBodyWithoutImageWithoutButton() {
  279. let app = XCUIApplication()
  280. app.tabBars.buttons["Modal Messages"].tap()
  281. let messageCardView = app.otherElements["message-card-view"]
  282. let closeButton = app.buttons["close-button"]
  283. let imageView = app.images["modal-image-view"]
  284. let bodyTextview = app.textViews["message-body-textview"]
  285. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  286. for orientation in orientantions {
  287. XCUIDevice.shared.orientation = orientation
  288. app.buttons["With Large Title, No Image, No Body and No Button"].tap()
  289. waitForElementToAppear(closeButton)
  290. let actionButton = app.buttons["message-action-button"]
  291. XCTAssert(!isElementExistentAndHavingSize(actionButton))
  292. XCTAssert(isElementExistentAndHavingSize(closeButton))
  293. XCTAssert(!isElementExistentAndHavingSize(bodyTextview))
  294. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  295. XCTAssert(!isElementExistentAndHavingSize(imageView))
  296. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  297. app.buttons["close-button"].tap()
  298. waitForElementToDisappear(messageCardView)
  299. }
  300. }
  301. }