InAppMessagingDisplayModalViewUITests.swift 15 KB

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