pEpForiOSUITests/NewAccountSetupUITest.swift
author Xavier Algarra <xavier@pep-project.org>
Tue, 06 Jun 2017 07:49:23 +0200
changeset 2248 75013a586bfd
parent 2231 bb691a140710
child 2262 8763c2e97084
permissions -rw-r--r--
IOS-137 add multiple accounts option with the new login
dirk@213
     1
//
dirk@213
     2
//  NewAccountSetupUITest.swift
dirk@213
     3
//  pEpForiOS
dirk@213
     4
//
dirk@213
     5
//  Created by Dirk Zimmermann on 20/05/16.
dirk@213
     6
//  Copyright © 2016 p≡p Security S.A. All rights reserved.
dirk@213
     7
//
dirk@213
     8
dirk@213
     9
import XCTest
dirk@816
    10
dirk@213
    11
class NewAccountSetupUITest: XCTestCase {
dirk@213
    12
    override func setUp() {
dirk@213
    13
        super.setUp()
dirk@213
    14
dirk@213
    15
        // In UI tests it is usually best to stop immediately when a failure occurs.
dirk@213
    16
        continueAfterFailure = false
dirk@213
    17
        // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
dirk@213
    18
        XCUIApplication().launch()
dirk@213
    19
dirk@213
    20
        // 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.
dirk@213
    21
    }
dirk@213
    22
dirk@214
    23
    /*
dirk@214
    24
     Use if you want to wait forever. May be useful for debugging.
dirk@214
    25
     */
dirk@214
    26
    func waitForever() {
dirk@1938
    27
        let _ = expectation(description: "Never happens")
dirk@784
    28
        waitForExpectations(timeout: 3000, handler: nil)
dirk@214
    29
    }
dirk@214
    30
dirk@228
    31
    /**
dirk@228
    32
     Clears the given text element.
dirk@228
    33
     */
dirk@784
    34
    func clearTextField(_ textField: XCUIElement) {
dirk@228
    35
        let string = textField.value as? String
dirk@228
    36
        XCTAssertNotNil(string)
dirk@228
    37
dirk@1293
    38
        while true {
dirk@1293
    39
            guard let text = textField.value as? String else {
dirk@1293
    40
                break
dirk@1293
    41
            }
dirk@1293
    42
            if text.characters.count == 0 {
dirk@1293
    43
                break
dirk@1293
    44
            }
dirk@227
    45
            textField.typeText("\u{8}")
dirk@227
    46
        }
dirk@227
    47
    }
dirk@227
    48
dirk@2231
    49
    func manualNewAccountSetup(_ account: Account) {
dirk@216
    50
        let tablesQuery = XCUIApplication().tables
dirk@216
    51
dirk@364
    52
        var tf = tablesQuery.cells.textFields["nameOfTheUser"]
dirk@364
    53
        tf.typeText(account.nameOfTheUser)
dirk@364
    54
dirk@364
    55
        tf = tablesQuery.cells.textFields["email"]
dirk@364
    56
        tf.tap()
dirk@216
    57
        tf.typeText(account.email)
dirk@216
    58
dirk@216
    59
        tf = tablesQuery.cells.secureTextFields["password"]
dirk@216
    60
        tf.tap()
dirk@216
    61
        tf.typeText(account.password)
dirk@216
    62
dirk@216
    63
        XCUIApplication().navigationBars.buttons["Next"].tap()
dirk@216
    64
dirk@216
    65
        tf = tablesQuery.textFields["imapServer"]
dirk@951
    66
        tf.typeText(account.imapServerName)
dirk@216
    67
        tf = tablesQuery.textFields["imapPort"]
dirk@216
    68
        tf.tap()
dirk@227
    69
        clearTextField(tf)
dirk@227
    70
        tf.typeText(String(account.imapPort))
dirk@229
    71
dirk@229
    72
        tablesQuery.buttons["imapTransportSecurity"].tap()
dirk@229
    73
        let sheet = XCUIApplication().sheets["Transport protocol"]
dirk@814
    74
        sheet.buttons[account.imapTransportSecurityString].tap()
dirk@229
    75
dirk@216
    76
        // TODO: Support alert for choosing transport
dirk@216
    77
        XCUIApplication().navigationBars.buttons["Next"].tap()
dirk@216
    78
dirk@216
    79
        tf = tablesQuery.textFields["smtpServer"]
dirk@951
    80
        tf.typeText(account.smtpServerName)
dirk@216
    81
        tf = tablesQuery.textFields["smtpPort"]
dirk@216
    82
        tf.tap()
dirk@227
    83
        clearTextField(tf)
dirk@227
    84
        tf.typeText(String(account.smtpPort))
dirk@229
    85
dirk@229
    86
        tablesQuery.buttons["smtpTransportSecurity"].tap()
dirk@814
    87
        sheet.buttons[account.smtpTransportSecurityString].tap()
dirk@229
    88
dirk@227
    89
        let nextButton = XCUIApplication().navigationBars.buttons["Next"]
dirk@227
    90
        nextButton.tap()
dirk@228
    91
    }
dirk@227
    92
dirk@2231
    93
    func newAccountSetup(account: Account) {
dirk@2231
    94
        let tablesQuery = XCUIApplication().tables
dirk@2231
    95
        var tfEmail = tablesQuery.cells.textFields["email"]
dirk@2231
    96
dirk@2231
    97
        tfEmail.tap()
dirk@2231
    98
        tfEmail.typeText(account.email)
dirk@2231
    99
dirk@2231
   100
        tfEmail = tablesQuery.cells.secureTextFields["password"]
dirk@2231
   101
        tfEmail.tap()
dirk@2231
   102
        tfEmail.typeText(account.password)
dirk@2231
   103
dirk@2231
   104
        XCUIApplication().tables.cells.buttons["Sign In"].tap()
dirk@2231
   105
    }
dirk@2231
   106
dirk@2231
   107
    func testNewAccountSetup() {
dirk@2231
   108
        let account = UITestData.workingAccount1
dirk@2231
   109
        newAccountSetup(account: account)
dirk@2231
   110
        waitForever()
dirk@2231
   111
    }
dirk@2231
   112
dirk@1563
   113
    func testInsertNewWorkingAccount() {
dirk@1563
   114
        let account = UITestData.workingAccount1
dirk@2231
   115
        manualNewAccountSetup(account)
dirk@1563
   116
        waitForever()
dirk@1563
   117
    }
dirk@1563
   118
dirk@228
   119
    func testNewAccountThatShouldFail() {
dirk@1435
   120
        var account = UITestData.workingAccount1
dirk@228
   121
        account.password = "CLEArlyWRong"
dirk@2231
   122
        manualNewAccountSetup(account)
dirk@228
   123
        // TODO: Verify error message
dirk@228
   124
        waitForever()
dirk@228
   125
    }
dirk@228
   126
dirk@227
   127
    func testInsertNewYahooAccount() {
dirk@227
   128
        let account = UITestData.workingYahooAccount
dirk@2231
   129
        manualNewAccountSetup(account)
dirk@217
   130
        waitForever()
dirk@216
   131
    }
dirk@1435
   132
dirk@1436
   133
    func testAddSingleWorkingAccounts() {
dirk@1436
   134
        let app = XCUIApplication()
dirk@1436
   135
dirk@1436
   136
        app.navigationBars["Inbox"].buttons["Accounts"].tap()
dirk@1436
   137
        app.navigationBars["Accounts"].buttons["Add"].tap()
dirk@1436
   138
dirk@1436
   139
        let account = UITestData.workingAccount3
dirk@2231
   140
        manualNewAccountSetup(account)
dirk@1436
   141
dirk@1436
   142
        waitForever()
dirk@1436
   143
    }
dirk@1436
   144
dirk@1436
   145
    func testAddTwoWorkingAccounts() {
dirk@1436
   146
        let app = XCUIApplication()
dirk@1436
   147
dirk@1436
   148
        var account = UITestData.workingAccount1
dirk@2231
   149
        manualNewAccountSetup(account)
dirk@1436
   150
dirk@1436
   151
        app.navigationBars["Inbox"].buttons["Accounts"].tap()
dirk@1436
   152
        app.navigationBars["Accounts"].buttons["Add"].tap()
dirk@1436
   153
dirk@1436
   154
        account = UITestData.workingAccount2
dirk@2231
   155
        manualNewAccountSetup(account)
dirk@1436
   156
dirk@1436
   157
        waitForever()
dirk@1436
   158
    }
dirk@1436
   159
    
dirk@1435
   160
    func testAddThreeWorkingAccounts() {
dirk@1435
   161
        let app = XCUIApplication()
dirk@1435
   162
dirk@1435
   163
        var account = UITestData.workingAccount1
dirk@2231
   164
        manualNewAccountSetup(account)
dirk@1435
   165
dirk@1435
   166
        app.navigationBars["Inbox"].buttons["Accounts"].tap()
dirk@1435
   167
        app.navigationBars["Accounts"].buttons["Add"].tap()
dirk@1435
   168
dirk@1435
   169
        account = UITestData.workingAccount2
dirk@2231
   170
        manualNewAccountSetup(account)
dirk@1435
   171
dirk@1435
   172
        app.navigationBars["Inbox"].buttons["Accounts"].tap()
dirk@1435
   173
        app.navigationBars["Accounts"].buttons["Add"].tap()
dirk@1435
   174
dirk@1435
   175
        account = UITestData.workingAccount3
dirk@2231
   176
        manualNewAccountSetup(account)
dirk@1436
   177
        
dirk@1435
   178
        waitForever()
dirk@1435
   179
    }
hernani@783
   180
}