InAppMessaging_Example_iOS_SwiftUITests.swift 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. /*
  2. * Copyright 2017 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 InAppMessaging_Example_iOS_SwiftUITests: XCTestCase {
  18. override func setUp() {
  19. super.setUp()
  20. continueAfterFailure = false
  21. let app = XCUIApplication()
  22. setupSnapshot(app)
  23. app.launch()
  24. }
  25. override func tearDown() {
  26. // Put teardown code here. This method is called after the invocation of each test method in the class.
  27. XCUIDevice.shared.orientation = .portrait
  28. super.tearDown()
  29. }
  30. func waitForElementToAppear(_ element: XCUIElement, _ timeoutInSeconds: TimeInterval = 5) {
  31. let existsPredicate = NSPredicate(format: "exists == true")
  32. expectation(for: existsPredicate, evaluatedWith: element, handler: nil)
  33. waitForExpectations(timeout: timeoutInSeconds, handler: nil)
  34. }
  35. func waitForElementToDisappear(_ element: XCUIElement, _ timeoutInSeconds: TimeInterval = 5) {
  36. let existsPredicate = NSPredicate(format: "exists == false")
  37. expectation(for: existsPredicate, evaluatedWith: element, handler: nil)
  38. waitForExpectations(timeout: timeoutInSeconds, handler: nil)
  39. }
  40. func childFrameWithinParentBound(parent: XCUIElement, child: XCUIElement) -> Bool {
  41. return parent.frame.contains(child.frame)
  42. }
  43. func isUIElementWithinUIWindow(_ uiElement: XCUIElement) -> Bool {
  44. let app = XCUIApplication()
  45. let window = app.windows.element(boundBy: 0)
  46. return window.frame.contains(uiElement.frame)
  47. }
  48. func isElementExistentAndHavingSize(_ uiElement: XCUIElement) -> Bool {
  49. // on iOS 9.3 for a XCUIElement whose height or width <=0, uiElement.exists still returns true
  50. // on iOS 10.3, for such an element uiElement.exists returns false
  51. // this function is to handle the existence (in our semanatic visible) testing for both cases
  52. return uiElement.exists && uiElement.frame.size.height > 0 && uiElement.frame.size.width > 0
  53. }
  54. func testNormalModalView() {
  55. let app = XCUIApplication()
  56. app.tabBars.buttons["Modal Messages"].tap()
  57. let messageCardView = app.otherElements["message-card-view"]
  58. let closeButton = app.buttons["close-button"]
  59. let imageView = app.images["modal-image-view"]
  60. let actionButton = app.buttons["message-action-button"]
  61. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  62. for orientation in orientantions {
  63. XCUIDevice.shared.orientation = orientation
  64. app.buttons["Regular"].tap()
  65. waitForElementToAppear(closeButton)
  66. snapshot("in-app-regular-modal-view-\(orientation.rawValue)")
  67. XCTAssert(isElementExistentAndHavingSize(actionButton))
  68. XCTAssert(isElementExistentAndHavingSize(imageView))
  69. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  70. XCTAssert(isElementExistentAndHavingSize(closeButton))
  71. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  72. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
  73. app.buttons["close-button"].tap()
  74. waitForElementToDisappear(messageCardView)
  75. }
  76. }
  77. func testModalViewWithWideImage() {
  78. let app = XCUIApplication()
  79. app.tabBars.buttons["Modal Messages"].tap()
  80. let messageCardView = app.otherElements["message-card-view"]
  81. let closeButton = app.buttons["close-button"]
  82. let imageView = app.images["modal-image-view"]
  83. let actionButton = app.buttons["message-action-button"]
  84. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  85. for orientation in orientantions {
  86. XCUIDevice.shared.orientation = orientation
  87. app.buttons["Thin Image"].tap()
  88. waitForElementToAppear(closeButton)
  89. snapshot("in-app-regular-modal-view-with-wider-image-\(orientation.rawValue)")
  90. XCTAssert(isElementExistentAndHavingSize(actionButton))
  91. XCTAssert(isElementExistentAndHavingSize(imageView))
  92. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  93. XCTAssert(isElementExistentAndHavingSize(closeButton))
  94. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  95. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
  96. app.buttons["close-button"].tap()
  97. waitForElementToDisappear(messageCardView)
  98. }
  99. }
  100. func testModalViewWithNarrowImage() {
  101. let app = XCUIApplication()
  102. app.tabBars.buttons["Modal Messages"].tap()
  103. let messageCardView = app.otherElements["message-card-view"]
  104. let closeButton = app.buttons["close-button"]
  105. let imageView = app.images["modal-image-view"]
  106. let actionButton = app.buttons["message-action-button"]
  107. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  108. for orientation in orientantions {
  109. XCUIDevice.shared.orientation = orientation
  110. app.buttons["Wide Image"].tap()
  111. waitForElementToAppear(closeButton)
  112. snapshot("in-app-regular-modal-view-with-narrow-image-\(orientation.rawValue)")
  113. XCTAssert(isElementExistentAndHavingSize(actionButton))
  114. XCTAssert(isElementExistentAndHavingSize(imageView))
  115. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  116. XCTAssert(isElementExistentAndHavingSize(closeButton))
  117. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  118. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
  119. app.buttons["close-button"].tap()
  120. waitForElementToDisappear(messageCardView)
  121. }
  122. }
  123. func testNormalBannerView() {
  124. let app = XCUIApplication()
  125. app.tabBars.buttons["Banner Messages"].tap()
  126. let titleElement = app.staticTexts["banner-message-title-view"]
  127. let imageView = app.images["banner-image-view"]
  128. let bodyElement = app.staticTexts["banner-body-label"]
  129. let bannerUIView = app.otherElements["banner-mode-uiview"]
  130. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  131. for orientation in orientantions {
  132. XCUIDevice.shared.orientation = orientation
  133. app.buttons["Show Regular Banner View"].tap()
  134. waitForElementToAppear(bannerUIView)
  135. snapshot("in-app-regular-banner-view-\(orientation.rawValue)")
  136. XCTAssert(isElementExistentAndHavingSize(imageView))
  137. XCTAssert(isElementExistentAndHavingSize(titleElement))
  138. XCTAssert(isElementExistentAndHavingSize(bodyElement))
  139. bannerUIView.swipeUp()
  140. waitForElementToDisappear(bannerUIView)
  141. }
  142. }
  143. func testBannerViewAutoDimiss() {
  144. let app = XCUIApplication()
  145. app.tabBars.buttons["Banner Messages"].tap()
  146. let titleElement = app.staticTexts["banner-message-title-view"]
  147. let imageView = app.images["banner-image-view"]
  148. let bodyElement = app.staticTexts["banner-body-label"]
  149. let bannerUIView = app.otherElements["banner-mode-uiview"]
  150. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  151. for orientation in orientantions {
  152. XCUIDevice.shared.orientation = orientation
  153. app.buttons["Banner View With Short Auto Dismiss"].tap()
  154. waitForElementToAppear(bannerUIView)
  155. XCTAssert(isElementExistentAndHavingSize(imageView))
  156. XCTAssert(isElementExistentAndHavingSize(titleElement))
  157. XCTAssert(isElementExistentAndHavingSize(bodyElement))
  158. // without user action, the banner is dismissed quickly in this test setup
  159. waitForElementToDisappear(bannerUIView, 15)
  160. }
  161. }
  162. func testBannerViewWithoutImage() {
  163. let app = XCUIApplication()
  164. app.tabBars.buttons["Banner Messages"].tap()
  165. let titleElement = app.staticTexts["banner-message-title-view"]
  166. let bodyElement = app.staticTexts["banner-body-label"]
  167. let bannerUIView = app.otherElements["banner-mode-uiview"]
  168. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  169. for orientation in orientantions {
  170. XCUIDevice.shared.orientation = orientation
  171. app.buttons["Without Image"].tap()
  172. waitForElementToAppear(bannerUIView)
  173. snapshot("in-app-banner-view-without-image-\(orientation.rawValue)")
  174. XCTAssert(isElementExistentAndHavingSize(titleElement))
  175. XCTAssert(isElementExistentAndHavingSize(bodyElement))
  176. bannerUIView.swipeUp()
  177. waitForElementToDisappear(bannerUIView)
  178. }
  179. }
  180. func testBannerViewWithLongTitle() {
  181. let app = XCUIApplication()
  182. app.tabBars.buttons["Banner Messages"].tap()
  183. let titleElement = app.staticTexts["banner-message-title-view"]
  184. let imageView = app.images["banner-image-view"]
  185. let bodyElement = app.staticTexts["banner-body-label"]
  186. let bannerUIView = app.otherElements["banner-mode-uiview"]
  187. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  188. for orientation in orientantions {
  189. XCUIDevice.shared.orientation = orientation
  190. app.buttons["With Long Title"].tap()
  191. waitForElementToAppear(bannerUIView)
  192. snapshot("in-app-banner-view-with-long-title-\(orientation.rawValue)")
  193. XCTAssert(isElementExistentAndHavingSize(imageView))
  194. XCTAssert(isElementExistentAndHavingSize(titleElement))
  195. XCTAssert(isElementExistentAndHavingSize(bodyElement))
  196. bannerUIView.swipeUp()
  197. waitForElementToDisappear(bannerUIView)
  198. }
  199. }
  200. func testBannerViewWithWideImage() {
  201. let app = XCUIApplication()
  202. app.tabBars.buttons["Banner Messages"].tap()
  203. let titleElement = app.staticTexts["banner-message-title-view"]
  204. let imageView = app.images["banner-image-view"]
  205. let bodyElement = app.staticTexts["banner-body-label"]
  206. let bannerUIView = app.otherElements["banner-mode-uiview"]
  207. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  208. for orientation in orientantions {
  209. XCUIDevice.shared.orientation = orientation
  210. app.buttons["With Wide Image"].tap()
  211. waitForElementToAppear(bannerUIView)
  212. snapshot("in-app-banner-view-with-wide-image-\(orientation.rawValue)")
  213. XCTAssert(isElementExistentAndHavingSize(imageView))
  214. XCTAssert(isElementExistentAndHavingSize(titleElement))
  215. XCTAssert(isElementExistentAndHavingSize(bodyElement))
  216. bannerUIView.swipeUp()
  217. waitForElementToDisappear(bannerUIView)
  218. }
  219. }
  220. func testBannerViewWithThinImage() {
  221. let app = XCUIApplication()
  222. app.tabBars.buttons["Banner Messages"].tap()
  223. let titleElement = app.staticTexts["banner-message-title-view"]
  224. let imageView = app.images["banner-image-view"]
  225. let bodyElement = app.staticTexts["banner-body-label"]
  226. let bannerUIView = app.otherElements["banner-mode-uiview"]
  227. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  228. for orientation in orientantions {
  229. XCUIDevice.shared.orientation = orientation
  230. app.buttons["With Thin Image"].tap()
  231. waitForElementToAppear(bannerUIView)
  232. snapshot("in-app-banner-view-with-thing-image-\(orientation.rawValue)")
  233. XCTAssert(isElementExistentAndHavingSize(imageView))
  234. XCTAssert(isElementExistentAndHavingSize(titleElement))
  235. XCTAssert(isElementExistentAndHavingSize(bodyElement))
  236. bannerUIView.swipeUp()
  237. waitForElementToDisappear(bannerUIView)
  238. }
  239. }
  240. func testBannerViewWithLargeBody() {
  241. let app = XCUIApplication()
  242. app.tabBars.buttons["Banner Messages"].tap()
  243. let titleElement = app.staticTexts["banner-message-title-view"]
  244. let imageView = app.images["banner-image-view"]
  245. let bodyElement = app.staticTexts["banner-body-label"]
  246. let bannerUIView = app.otherElements["banner-mode-uiview"]
  247. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  248. for orientation in orientantions {
  249. XCUIDevice.shared.orientation = orientation
  250. app.buttons["With Large Body Text"].tap()
  251. waitForElementToAppear(bannerUIView)
  252. snapshot("in-app-banner-view-with-long-body-\(orientation.rawValue)")
  253. XCTAssert(isElementExistentAndHavingSize(imageView))
  254. XCTAssert(isElementExistentAndHavingSize(titleElement))
  255. XCTAssert(isElementExistentAndHavingSize(bodyElement))
  256. bannerUIView.swipeUp()
  257. waitForElementToDisappear(bannerUIView)
  258. }
  259. }
  260. func testImageOnlyView() {
  261. let app = XCUIApplication()
  262. app.tabBars.buttons["Image Only Messages"].tap()
  263. let imageView = app.images["image-view-in-image-only-view"]
  264. let closeButton = app.buttons["close-button"]
  265. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  266. for orientation in orientantions {
  267. XCUIDevice.shared.orientation = orientation
  268. app.buttons["Show Regular Image Only View"].tap()
  269. waitForElementToAppear(closeButton)
  270. snapshot("in-app-regular-image-only-view-\(orientation.rawValue)")
  271. XCTAssert(isElementExistentAndHavingSize(imageView))
  272. XCTAssert(isUIElementWithinUIWindow(imageView))
  273. app.buttons["close-button"].tap()
  274. waitForElementToDisappear(imageView)
  275. }
  276. }
  277. func testImageOnlyViewWithLargeImageDimension() {
  278. let app = XCUIApplication()
  279. app.tabBars.buttons["Image Only Messages"].tap()
  280. let imageView = app.images["image-view-in-image-only-view"]
  281. let closeButton = app.buttons["close-button"]
  282. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  283. for orientation in orientantions {
  284. XCUIDevice.shared.orientation = orientation
  285. app.buttons["High Dimension Image"].tap()
  286. // wait time longer due to large image
  287. waitForElementToAppear(closeButton, 10)
  288. snapshot("in-app-large-image-only-view-high-dimension-\(orientation.rawValue)")
  289. XCTAssert(isElementExistentAndHavingSize(imageView))
  290. XCTAssert(isUIElementWithinUIWindow(imageView))
  291. app.buttons["close-button"].tap()
  292. waitForElementToDisappear(imageView)
  293. }
  294. }
  295. func testImageOnlyViewWithLowImageDimension() {
  296. let app = XCUIApplication()
  297. app.tabBars.buttons["Image Only Messages"].tap()
  298. let imageView = app.images["image-view-in-image-only-view"]
  299. let closeButton = app.buttons["close-button"]
  300. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  301. for orientation in orientantions {
  302. XCUIDevice.shared.orientation = orientation
  303. app.buttons["Low Dimension Image"].tap()
  304. // wait time longer due to large image
  305. waitForElementToAppear(closeButton, 10)
  306. snapshot("in-app-large-image-only-view-low-dimension-\(orientation.rawValue)")
  307. XCTAssert(isElementExistentAndHavingSize(imageView))
  308. XCTAssert(isUIElementWithinUIWindow(imageView))
  309. app.buttons["close-button"].tap()
  310. waitForElementToDisappear(imageView)
  311. }
  312. }
  313. func testModalViewWithoutImage() {
  314. let app = XCUIApplication()
  315. app.tabBars.buttons["Modal Messages"].tap()
  316. let messageCardView = app.otherElements["message-card-view"]
  317. let closeButton = app.buttons["close-button"]
  318. let actionButton = app.buttons["message-action-button"]
  319. let imageView = app.images["modal-image-view"]
  320. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  321. for orientation in orientantions {
  322. XCUIDevice.shared.orientation = orientation
  323. app.buttons["Without Image"].tap()
  324. waitForElementToAppear(closeButton)
  325. snapshot("in-app-no-image-modal-view-\(orientation.rawValue)")
  326. XCTAssert(isElementExistentAndHavingSize(actionButton))
  327. XCTAssert(isElementExistentAndHavingSize(closeButton))
  328. XCTAssertFalse(isElementExistentAndHavingSize(imageView))
  329. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  330. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  331. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
  332. app.buttons["close-button"].tap()
  333. waitForElementToDisappear(messageCardView)
  334. }
  335. }
  336. func testModalViewWithoutImageOrActionButton() {
  337. let app = XCUIApplication()
  338. app.tabBars.buttons["Modal Messages"].tap()
  339. let messageCardView = app.otherElements["message-card-view"]
  340. let closeButton = app.buttons["close-button"]
  341. let actionButton = app.buttons["message-action-button"]
  342. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  343. for orientation in orientantions {
  344. XCUIDevice.shared.orientation = orientation
  345. app.buttons["Wthout Image or Action Button"].tap()
  346. waitForElementToAppear(closeButton)
  347. snapshot("in-app-no-image-no-button-modal-view-\(orientation.rawValue)")
  348. XCTAssertFalse(isElementExistentAndHavingSize(actionButton))
  349. XCTAssert(isElementExistentAndHavingSize(closeButton))
  350. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  351. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  352. app.buttons["close-button"].tap()
  353. waitForElementToDisappear(messageCardView)
  354. XCUIDevice.shared.orientation = .portrait
  355. }
  356. }
  357. func testModalViewWithoutActionButton() {
  358. let app = XCUIApplication()
  359. app.tabBars.buttons["Modal Messages"].tap()
  360. let messageCardView = app.otherElements["message-card-view"]
  361. let closeButton = app.buttons["close-button"]
  362. let imageView = app.images["modal-image-view"]
  363. let actionButton = app.buttons["message-action-button"]
  364. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  365. for orientation in orientantions {
  366. XCUIDevice.shared.orientation = orientation
  367. app.buttons["Without Action Button"].tap()
  368. waitForElementToAppear(closeButton)
  369. snapshot("in-app-no-action-button-moal-view-\(orientation.rawValue)")
  370. XCTAssertFalse(isElementExistentAndHavingSize(actionButton))
  371. XCTAssert(isElementExistentAndHavingSize(closeButton))
  372. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  373. XCTAssert(isElementExistentAndHavingSize(imageView))
  374. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  375. app.buttons["close-button"].tap()
  376. waitForElementToDisappear(messageCardView)
  377. }
  378. }
  379. func testModalViewWithLongMessageTitle() {
  380. let app = XCUIApplication()
  381. app.tabBars.buttons["Modal Messages"].tap()
  382. let messageCardView = app.otherElements["message-card-view"]
  383. let closeButton = app.buttons["close-button"]
  384. let imageView = app.images["modal-image-view"]
  385. let bodyTextview = app.textViews["message-body-textview"]
  386. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  387. for orientation in orientantions {
  388. XCUIDevice.shared.orientation = orientation
  389. app.buttons["Large Title Text"].tap()
  390. waitForElementToAppear(closeButton)
  391. snapshot("in-app-long-title-modal-view-\(orientation.rawValue)")
  392. let actionButton = app.buttons["message-action-button"]
  393. XCTAssert(isElementExistentAndHavingSize(actionButton))
  394. XCTAssert(isElementExistentAndHavingSize(closeButton))
  395. XCTAssert(isElementExistentAndHavingSize(bodyTextview))
  396. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  397. XCTAssert(isElementExistentAndHavingSize(imageView))
  398. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  399. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
  400. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: bodyTextview))
  401. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: imageView))
  402. app.buttons["close-button"].tap()
  403. waitForElementToDisappear(messageCardView)
  404. }
  405. }
  406. func testModalViewWithLongMessageBody() {
  407. let app = XCUIApplication()
  408. app.tabBars.buttons["Modal Messages"].tap()
  409. let messageCardView = app.otherElements["message-card-view"]
  410. let closeButton = app.buttons["close-button"]
  411. let imageView = app.images["modal-image-view"]
  412. let bodyTextview = app.textViews["message-body-textview"]
  413. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  414. for orientation in orientantions {
  415. XCUIDevice.shared.orientation = orientation
  416. app.buttons["Large Title Text"].tap()
  417. waitForElementToAppear(closeButton)
  418. snapshot("in-app-long-body-modal-view-\(orientation.rawValue)")
  419. let actionButton = app.buttons["message-action-button"]
  420. XCTAssert(isElementExistentAndHavingSize(actionButton))
  421. XCTAssert(isElementExistentAndHavingSize(closeButton))
  422. XCTAssert(isElementExistentAndHavingSize(bodyTextview))
  423. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  424. XCTAssert(isElementExistentAndHavingSize(imageView))
  425. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  426. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
  427. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: bodyTextview))
  428. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: imageView))
  429. app.buttons["close-button"].tap()
  430. waitForElementToDisappear(messageCardView)
  431. }
  432. }
  433. func testModalViewWithLongMessageTitleAndMessageBody() {
  434. let app = XCUIApplication()
  435. app.tabBars.buttons["Modal Messages"].tap()
  436. let messageCardView = app.otherElements["message-card-view"]
  437. let closeButton = app.buttons["close-button"]
  438. let imageView = app.images["modal-image-view"]
  439. let bodyTextview = app.textViews["message-body-textview"]
  440. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  441. for orientation in orientantions {
  442. XCUIDevice.shared.orientation = orientation
  443. app.buttons["With Large Title and Body"].tap()
  444. waitForElementToAppear(closeButton)
  445. snapshot("in-app-long-title-and-body-modal-view-\(orientation.rawValue)")
  446. let actionButton = app.buttons["message-action-button"]
  447. XCTAssert(isElementExistentAndHavingSize(actionButton))
  448. XCTAssert(isElementExistentAndHavingSize(closeButton))
  449. XCTAssert(isElementExistentAndHavingSize(bodyTextview))
  450. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  451. XCTAssert(isElementExistentAndHavingSize(imageView))
  452. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  453. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
  454. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: bodyTextview))
  455. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: imageView))
  456. app.buttons["close-button"].tap()
  457. waitForElementToDisappear(messageCardView)
  458. }
  459. }
  460. func testModalViewWithLongMessageTitleAndMessageBodyWithoutImage() {
  461. let app = XCUIApplication()
  462. app.tabBars.buttons["Modal Messages"].tap()
  463. let messageCardView = app.otherElements["message-card-view"]
  464. let closeButton = app.buttons["close-button"]
  465. let imageView = app.images["modal-image-view"]
  466. let bodyTextview = app.textViews["message-body-textview"]
  467. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  468. for orientation in orientantions {
  469. XCUIDevice.shared.orientation = orientation
  470. app.buttons["With Large Title and Body Without Image"].tap()
  471. waitForElementToAppear(closeButton)
  472. snapshot("in-app-long-title-and-body-no-image-modal-view-\(orientation.rawValue)")
  473. let actionButton = app.buttons["message-action-button"]
  474. XCTAssert(isElementExistentAndHavingSize(actionButton))
  475. XCTAssert(isElementExistentAndHavingSize(closeButton))
  476. XCTAssert(isElementExistentAndHavingSize(bodyTextview))
  477. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  478. XCTAssert(!isElementExistentAndHavingSize(imageView))
  479. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  480. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
  481. XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: bodyTextview))
  482. app.buttons["close-button"].tap()
  483. waitForElementToDisappear(messageCardView)
  484. }
  485. }
  486. func testModalViewWithLongMessageTitleWithoutBodyWithoutImageWithoutButton() {
  487. let app = XCUIApplication()
  488. app.tabBars.buttons["Modal Messages"].tap()
  489. let messageCardView = app.otherElements["message-card-view"]
  490. let closeButton = app.buttons["close-button"]
  491. let imageView = app.images["modal-image-view"]
  492. let bodyTextview = app.textViews["message-body-textview"]
  493. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  494. for orientation in orientantions {
  495. XCUIDevice.shared.orientation = orientation
  496. app.buttons["With Large Title, No Image, No Body and No Button"].tap()
  497. waitForElementToAppear(closeButton)
  498. snapshot("in-app-long-title-no-image-body-button-modal-view-\(orientation.rawValue)")
  499. let actionButton = app.buttons["message-action-button"]
  500. XCTAssert(!isElementExistentAndHavingSize(actionButton))
  501. XCTAssert(isElementExistentAndHavingSize(closeButton))
  502. XCTAssert(!isElementExistentAndHavingSize(bodyTextview))
  503. XCTAssert(isElementExistentAndHavingSize(messageCardView))
  504. XCTAssert(!isElementExistentAndHavingSize(imageView))
  505. XCTAssert(isUIElementWithinUIWindow(messageCardView))
  506. app.buttons["close-button"].tap()
  507. waitForElementToDisappear(messageCardView)
  508. }
  509. }
  510. }