LoginUITests.swift 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // NextcloudUITests.swift
  3. // NextcloudUITests
  4. //
  5. // Created by Milen Pivchev on 5/19/23.
  6. // Copyright © 2023 Marino Faggiana. All rights reserved.
  7. //
  8. import XCTest
  9. final class LoginUITests: BaseUIXCTestCase {
  10. private let baseUrl = EnvVars.testServerUrl
  11. private let user = EnvVars.testUser
  12. private let userId = EnvVars.testUser
  13. private let password = EnvVars.testAppPassword
  14. private lazy var account = "\(userId) \(baseUrl)"
  15. let app = XCUIApplication()
  16. override func setUp() {
  17. app.launchArguments += ["UI_TESTING"]
  18. }
  19. func test_logIn_withProperParams_shouldLogInAndGoToHomeScreen() throws {
  20. app.launch()
  21. let loginButton = app.buttons["Log in"]
  22. XCTAssert(loginButton.waitForExistence(timeout: timeoutSeconds))
  23. loginButton.tap()
  24. let serverAddressHttpsTextField = app.textFields["Server address https:// …"]
  25. serverAddressHttpsTextField.tap()
  26. serverAddressHttpsTextField.typeText(baseUrl)
  27. let button = app.windows.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .button).element(boundBy: 0)
  28. button.tap()
  29. let webViewsQuery = app.webViews.webViews.webViews
  30. let loginButton2 = webViewsQuery/*@START_MENU_TOKEN@*/.buttons["Log in"]/*[[".otherElements.matching(identifier: \"Nextcloud\")",".otherElements[\"main\"].buttons[\"Log in\"]",".buttons[\"Log in\"]"],[[[-1,2],[-1,1],[-1,0,1]],[[-1,2],[-1,1]]],[0]]@END_MENU_TOKEN@*/
  31. XCTAssert(loginButton2.waitForExistence(timeout: timeoutSeconds))
  32. waitForEnabledAndHittable(object: loginButton2)
  33. loginButton2.tap()
  34. let element = webViewsQuery/*@START_MENU_TOKEN@*/.otherElements["main"]/*[[".otherElements[\"Login – Nextcloud\"].otherElements[\"main\"]",".otherElements[\"main\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.children(matching: .other).element(boundBy: 1)
  35. let usernameTextField = element.children(matching: .other).element(boundBy: 2).children(matching: .textField).element
  36. XCTAssert(usernameTextField.waitForExistence(timeout: timeoutSeconds))
  37. usernameTextField.tap()
  38. usernameTextField.typeText(user)
  39. let passwordTextField = element.children(matching: .other).element(boundBy: 4).children(matching: .secureTextField).element
  40. passwordTextField.tap()
  41. passwordTextField.typeText(user)
  42. let loginButton3 = webViewsQuery/*@START_MENU_TOKEN@*/.buttons["Log in"]/*[[".otherElements[\"Login – Nextcloud\"]",".otherElements[\"main\"].buttons[\"Log in\"]",".buttons[\"Log in\"]"],[[[-1,2],[-1,1],[-1,0,1]],[[-1,2],[-1,1]]],[0]]@END_MENU_TOKEN@*/
  43. XCTAssert(loginButton3.waitForExistence(timeout: timeoutSeconds))
  44. loginButton3.tap()
  45. let grantAccessButton = webViewsQuery/*@START_MENU_TOKEN@*/.buttons["Grant access"]/*[[".otherElements.matching(identifier: \"Nextcloud\")",".otherElements[\"main\"].buttons[\"Grant access\"]",".buttons[\"Grant access\"]"],[[[-1,2],[-1,1],[-1,0,1]],[[-1,2],[-1,1]]],[0]]@END_MENU_TOKEN@*/
  46. XCTAssert(grantAccessButton.waitForExistence(timeout: timeoutSeconds))
  47. waitForEnabledAndHittable(object: grantAccessButton)
  48. grantAccessButton.tap()
  49. // Check if we are in the home screen
  50. XCTAssert(app.navigationBars["Nextcloud"].waitForExistence(timeout: timeoutSeconds))
  51. XCTAssert(app.tabBars["Tab Bar"].waitForExistence(timeout: timeoutSeconds))
  52. }
  53. }