| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- /*
- * Copyright 2018 Google
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- import XCTest
- class InAppMessagingDisplayModalViewUITests: InAppMessagingDisplayUITestsBase {
- var app: XCUIApplication!
- var verificationLabel: XCUIElement!
- override func setUp() {
- super.setUp()
- // Put setup code here. This method is called before the invocation of each test method in the class.
- // In UI tests it is usually best to stop immediately when a failure occurs.
- continueAfterFailure = false
- // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
- XCUIApplication().launch()
- app = XCUIApplication()
- verificationLabel = app.staticTexts["verification-label-modal"]
- // 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.
- }
- override func tearDown() {
- // Put teardown code here. This method is called after the invocation of each test method in the class.
- super.tearDown()
- }
- func testNormalModalView() {
- app.tabBars.buttons["Modal Messages"].tap()
- let messageCardView = app.otherElements["message-card-view"]
- let closeButton = app.buttons["close-button"]
- let imageView = app.images["modal-image-view"]
- let actionButton = app.buttons["message-action-button"]
- let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
- for orientation in orientantions {
- XCUIDevice.shared.orientation = orientation
- app.buttons["Regular"].tap()
- waitForElementToAppear(closeButton)
- XCTAssert(isElementExistentAndHavingSize(actionButton))
- XCTAssert(isElementExistentAndHavingSize(imageView))
- XCTAssert(isElementExistentAndHavingSize(messageCardView))
- XCTAssert(isElementExistentAndHavingSize(closeButton))
- XCTAssert(isUIElementWithinUIWindow(messageCardView))
- XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
- if orientation == UIDeviceOrientation.portrait {
- actionButton.tap()
- } else {
- closeButton.tap()
- }
- waitForElementToDisappear(messageCardView)
- let labelValue = verificationLabel.label
- if orientation == UIDeviceOrientation.portrait {
- XCTAssertTrue(labelValue.contains("clicked"))
- } else {
- XCTAssertTrue(labelValue.contains("dismissed"))
- }
- }
- }
- func testModalViewWithWideImage() {
- app.tabBars.buttons["Modal Messages"].tap()
- let messageCardView = app.otherElements["message-card-view"]
- let closeButton = app.buttons["close-button"]
- let imageView = app.images["modal-image-view"]
- let actionButton = app.buttons["message-action-button"]
- let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
- for orientation in orientantions {
- XCUIDevice.shared.orientation = orientation
- app.buttons["Wide Image"].tap()
- waitForElementToAppear(closeButton)
- XCTAssert(isElementExistentAndHavingSize(actionButton))
- XCTAssert(isElementExistentAndHavingSize(imageView))
- XCTAssert(isElementExistentAndHavingSize(messageCardView))
- XCTAssert(isElementExistentAndHavingSize(closeButton))
- XCTAssert(isUIElementWithinUIWindow(messageCardView))
- XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
- app.buttons["close-button"].tap()
- waitForElementToDisappear(messageCardView)
- let labelValue = verificationLabel.label
- XCTAssertTrue(labelValue.contains("dismissed"))
- }
- }
- func testModalViewWithNarrowImage() {
- app.tabBars.buttons["Modal Messages"].tap()
- let messageCardView = app.otherElements["message-card-view"]
- let closeButton = app.buttons["close-button"]
- let imageView = app.images["modal-image-view"]
- let actionButton = app.buttons["message-action-button"]
- let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
- for orientation in orientantions {
- XCUIDevice.shared.orientation = orientation
- app.buttons["Thin Image"].tap()
- waitForElementToAppear(closeButton)
- XCTAssert(isElementExistentAndHavingSize(actionButton))
- XCTAssert(isElementExistentAndHavingSize(imageView))
- XCTAssert(isElementExistentAndHavingSize(messageCardView))
- XCTAssert(isElementExistentAndHavingSize(closeButton))
- XCTAssert(isUIElementWithinUIWindow(messageCardView))
- XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
- actionButton.tap()
- waitForElementToDisappear(messageCardView)
- let labelValue = verificationLabel.label
- XCTAssertTrue(labelValue.contains("clicked"))
- }
- }
- func testModalViewWithoutImage() {
- app.tabBars.buttons["Modal Messages"].tap()
- let messageCardView = app.otherElements["message-card-view"]
- let closeButton = app.buttons["close-button"]
- let actionButton = app.buttons["message-action-button"]
- let imageView = app.images["modal-image-view"]
- let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
- for orientation in orientantions {
- XCUIDevice.shared.orientation = orientation
- app.buttons["Without Image"].tap()
- waitForElementToAppear(closeButton)
- XCTAssert(isElementExistentAndHavingSize(actionButton))
- XCTAssert(isElementExistentAndHavingSize(closeButton))
- XCTAssertFalse(isElementExistentAndHavingSize(imageView))
- XCTAssert(isElementExistentAndHavingSize(messageCardView))
- XCTAssert(isUIElementWithinUIWindow(messageCardView))
- XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
- app.buttons["close-button"].tap()
- waitForElementToDisappear(messageCardView)
- let labelValue = verificationLabel.label
- XCTAssertTrue(labelValue.contains("dismissed"))
- }
- }
- func testModalViewWithoutImageOrActionButton() {
- app.tabBars.buttons["Modal Messages"].tap()
- let messageCardView = app.otherElements["message-card-view"]
- let closeButton = app.buttons["close-button"]
- let actionButton = app.buttons["message-action-button"]
- let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
- for orientation in orientantions {
- XCUIDevice.shared.orientation = orientation
- app.buttons["Wthout Image or Action Button"].tap()
- waitForElementToAppear(closeButton)
- XCTAssertFalse(isElementExistentAndHavingSize(actionButton))
- XCTAssert(isElementExistentAndHavingSize(closeButton))
- XCTAssert(isElementExistentAndHavingSize(messageCardView))
- XCTAssert(isUIElementWithinUIWindow(messageCardView))
- app.buttons["close-button"].tap()
- waitForElementToDisappear(messageCardView)
- XCUIDevice.shared.orientation = .portrait
- }
- }
- func testModalViewWithoutActionButton() {
- app.tabBars.buttons["Modal Messages"].tap()
- let messageCardView = app.otherElements["message-card-view"]
- let closeButton = app.buttons["close-button"]
- let imageView = app.images["modal-image-view"]
- let actionButton = app.buttons["message-action-button"]
- let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
- for orientation in orientantions {
- XCUIDevice.shared.orientation = orientation
- app.buttons["Without Action Button"].tap()
- waitForElementToAppear(closeButton)
- XCTAssertFalse(isElementExistentAndHavingSize(actionButton))
- XCTAssert(isElementExistentAndHavingSize(closeButton))
- XCTAssert(isElementExistentAndHavingSize(messageCardView))
- XCTAssert(isElementExistentAndHavingSize(imageView))
- XCTAssert(isUIElementWithinUIWindow(messageCardView))
- app.buttons["close-button"].tap()
- waitForElementToDisappear(messageCardView)
- }
- }
- func testModalViewWithLongMessageTitle() {
- app.tabBars.buttons["Modal Messages"].tap()
- let messageCardView = app.otherElements["message-card-view"]
- let closeButton = app.buttons["close-button"]
- let imageView = app.images["modal-image-view"]
- let bodyTextview = app.textViews["message-body-textview"]
- let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
- for orientation in orientantions {
- XCUIDevice.shared.orientation = orientation
- app.buttons["Large Title Text"].tap()
- waitForElementToAppear(closeButton)
- let actionButton = app.buttons["message-action-button"]
- XCTAssert(isElementExistentAndHavingSize(actionButton))
- XCTAssert(isElementExistentAndHavingSize(closeButton))
- XCTAssert(isElementExistentAndHavingSize(bodyTextview))
- XCTAssert(isElementExistentAndHavingSize(messageCardView))
- XCTAssert(!isElementExistentAndHavingSize(imageView))
- XCTAssert(isUIElementWithinUIWindow(messageCardView))
- XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
- XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: bodyTextview))
- app.buttons["close-button"].tap()
- waitForElementToDisappear(messageCardView)
- }
- }
- func testModalViewWithLongMessageBody() {
- app.tabBars.buttons["Modal Messages"].tap()
- let messageCardView = app.otherElements["message-card-view"]
- let closeButton = app.buttons["close-button"]
- let imageView = app.images["modal-image-view"]
- let bodyTextview = app.textViews["message-body-textview"]
- let actionButton = app.buttons["message-action-button"]
- let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
- for orientation in orientantions {
- XCUIDevice.shared.orientation = orientation
- app.buttons["Large Title Text"].tap()
- waitForElementToAppear(closeButton)
- XCTAssert(isElementExistentAndHavingSize(actionButton))
- XCTAssert(isElementExistentAndHavingSize(closeButton))
- XCTAssert(isElementExistentAndHavingSize(bodyTextview))
- XCTAssert(isElementExistentAndHavingSize(messageCardView))
- XCTAssert(!isElementExistentAndHavingSize(imageView))
- XCTAssert(isUIElementWithinUIWindow(messageCardView))
- XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
- XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: bodyTextview))
- actionButton.tap()
- waitForElementToDisappear(messageCardView)
- let labelValue = verificationLabel.label
- XCTAssertTrue(labelValue.contains("clicked"))
- }
- }
- func testModalViewWithLongMessageTitleAndMessageBody() {
- app.tabBars.buttons["Modal Messages"].tap()
- let messageCardView = app.otherElements["message-card-view"]
- let closeButton = app.buttons["close-button"]
- let imageView = app.images["modal-image-view"]
- let bodyTextview = app.textViews["message-body-textview"]
- let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
- for orientation in orientantions {
- XCUIDevice.shared.orientation = orientation
- app.buttons["With Large Title and Body"].tap()
- waitForElementToAppear(closeButton)
- let actionButton = app.buttons["message-action-button"]
- XCTAssert(isElementExistentAndHavingSize(actionButton))
- XCTAssert(isElementExistentAndHavingSize(closeButton))
- XCTAssert(isElementExistentAndHavingSize(bodyTextview))
- XCTAssert(isElementExistentAndHavingSize(messageCardView))
- XCTAssert(isElementExistentAndHavingSize(imageView))
- XCTAssert(isUIElementWithinUIWindow(messageCardView))
- XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
- XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: bodyTextview))
- XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: imageView))
- app.buttons["close-button"].tap()
- waitForElementToDisappear(messageCardView)
- }
- }
- func testModalViewWithLongMessageTitleAndMessageBodyWithoutImage() {
- let app = XCUIApplication()
- app.tabBars.buttons["Modal Messages"].tap()
- let messageCardView = app.otherElements["message-card-view"]
- let closeButton = app.buttons["close-button"]
- let imageView = app.images["modal-image-view"]
- let bodyTextview = app.textViews["message-body-textview"]
- let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
- for orientation in orientantions {
- XCUIDevice.shared.orientation = orientation
- app.buttons["With Large Title and Body Without Image"].tap()
- waitForElementToAppear(closeButton)
- let actionButton = app.buttons["message-action-button"]
- XCTAssert(isElementExistentAndHavingSize(actionButton))
- XCTAssert(isElementExistentAndHavingSize(closeButton))
- XCTAssert(isElementExistentAndHavingSize(bodyTextview))
- XCTAssert(isElementExistentAndHavingSize(messageCardView))
- XCTAssert(!isElementExistentAndHavingSize(imageView))
- XCTAssert(isUIElementWithinUIWindow(messageCardView))
- XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: actionButton))
- XCTAssert(childFrameWithinParentBound(parent: messageCardView, child: bodyTextview))
- app.buttons["close-button"].tap()
- waitForElementToDisappear(messageCardView)
- }
- }
- func testModalViewWithLongMessageTitleWithoutBodyWithoutImageWithoutButton() {
- let app = XCUIApplication()
- app.tabBars.buttons["Modal Messages"].tap()
- let messageCardView = app.otherElements["message-card-view"]
- let closeButton = app.buttons["close-button"]
- let imageView = app.images["modal-image-view"]
- let bodyTextview = app.textViews["message-body-textview"]
- let orientantions = [UIDeviceOrientation.portrait, UIDeviceOrientation.landscapeLeft]
- for orientation in orientantions {
- XCUIDevice.shared.orientation = orientation
- app.buttons["With Large Title, No Image, No Body and No Button"].tap()
- waitForElementToAppear(closeButton)
- let actionButton = app.buttons["message-action-button"]
- XCTAssert(!isElementExistentAndHavingSize(actionButton))
- XCTAssert(isElementExistentAndHavingSize(closeButton))
- XCTAssert(!isElementExistentAndHavingSize(bodyTextview))
- XCTAssert(isElementExistentAndHavingSize(messageCardView))
- XCTAssert(!isElementExistentAndHavingSize(imageView))
- XCTAssert(isUIElementWithinUIWindow(messageCardView))
- app.buttons["close-button"].tap()
- waitForElementToDisappear(messageCardView)
- }
- }
- }
|