InAppMessagingDisplayImageOnlyViewUITests.swift 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 InAppMessagingImageOnlyViewUITests: 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-image-only"]
  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 testImageOnlyView() {
  37. app.tabBars.buttons["Image Only Messages"].tap()
  38. let imageView = app.images["image-view-in-image-only-view"]
  39. let closeButton = app.buttons["close-button"]
  40. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  41. for orientation in orientantions {
  42. XCUIDevice.shared.orientation = orientation
  43. app.buttons["Show Regular Image Only View"].tap()
  44. waitForElementToAppear(closeButton)
  45. XCTAssert(isElementExistentAndHavingSize(imageView))
  46. XCTAssert(isUIElementWithinUIWindow(imageView))
  47. imageView.tap()
  48. waitForElementToDisappear(imageView)
  49. let labelValue = verificationLabel.label
  50. XCTAssertTrue(labelValue.contains("clicked"))
  51. }
  52. }
  53. func testImageOnlyViewWithLargeImageDimension() {
  54. app.tabBars.buttons["Image Only Messages"].tap()
  55. let imageView = app.images["image-view-in-image-only-view"]
  56. let closeButton = app.buttons["close-button"]
  57. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  58. for orientation in orientantions {
  59. XCUIDevice.shared.orientation = orientation
  60. app.buttons["High Dimension Image"].tap()
  61. // wait time longer due to large image
  62. waitForElementToAppear(closeButton, 30)
  63. XCTAssert(isElementExistentAndHavingSize(imageView))
  64. XCTAssert(isUIElementWithinUIWindow(imageView))
  65. app.buttons["close-button"].tap()
  66. waitForElementToDisappear(imageView)
  67. let labelValue = verificationLabel.label
  68. XCTAssertTrue(labelValue.contains("dismissed"))
  69. }
  70. }
  71. func testImageOnlyViewWithLowImageDimension() {
  72. app.tabBars.buttons["Image Only Messages"].tap()
  73. let imageView = app.images["image-view-in-image-only-view"]
  74. let closeButton = app.buttons["close-button"]
  75. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  76. for orientation in orientantions {
  77. XCUIDevice.shared.orientation = orientation
  78. app.buttons["Low Dimension Image"].tap()
  79. // wait time longer due to large image
  80. waitForElementToAppear(closeButton, 30)
  81. XCTAssert(isElementExistentAndHavingSize(imageView))
  82. XCTAssert(isUIElementWithinUIWindow(imageView))
  83. app.buttons["close-button"].tap()
  84. waitForElementToDisappear(imageView)
  85. }
  86. }
  87. func testImageOnlyViewWithWideImage() {
  88. app.tabBars.buttons["Image Only Messages"].tap()
  89. let imageView = app.images["image-view-in-image-only-view"]
  90. let closeButton = app.buttons["close-button"]
  91. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  92. for orientation in orientantions {
  93. XCUIDevice.shared.orientation = orientation
  94. app.buttons["Wide Image"].tap()
  95. // wait time longer due to large image
  96. waitForElementToAppear(closeButton, 30)
  97. XCTAssert(isElementExistentAndHavingSize(imageView))
  98. XCTAssert(isUIElementWithinUIWindow(imageView))
  99. app.buttons["close-button"].tap()
  100. waitForElementToDisappear(imageView)
  101. }
  102. }
  103. func testImageOnlyViewWithNarrowImage() {
  104. app.tabBars.buttons["Image Only Messages"].tap()
  105. let imageView = app.images["image-view-in-image-only-view"]
  106. let closeButton = app.buttons["close-button"]
  107. let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
  108. for orientation in orientantions {
  109. XCUIDevice.shared.orientation = orientation
  110. app.buttons["Narrow Image"].tap()
  111. // wait time longer due to large image
  112. waitForElementToAppear(closeButton, 30)
  113. XCTAssert(isElementExistentAndHavingSize(imageView))
  114. XCTAssert(isUIElementWithinUIWindow(imageView))
  115. app.buttons["close-button"].tap()
  116. waitForElementToDisappear(imageView)
  117. }
  118. }
  119. }