Skip to content

Commit

Permalink
test: Update quark commands use latest protoncore
Browse files Browse the repository at this point in the history
Jira-Id: TPE-512
  • Loading branch information
gricsi authored and jaroslavas committed Feb 5, 2024
1 parent ebab9a9 commit f05f2f5
Show file tree
Hide file tree
Showing 23 changed files with 140 additions and 299 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ stages:
- i18n
- github
- lint
- deploy
- build
- test
- deploy
- test_ui
- cleanup

Expand Down
27 changes: 0 additions & 27 deletions .gitlab/jobs/lib-onboarding.yml

This file was deleted.

4 changes: 3 additions & 1 deletion .gitlab/jobs/templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: never
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_PIPELINE_SOURCE == "schedule" && $CUSTOM_TEST_PLAN # for custom pipeline like subscription should not run all ui tests just specific selected test plan related
when: never
- if: '$CI_PIPELINE_SOURCE == "schedule" && $CUSTOM_TEST_PLAN == null'
when: always
- if: $CI_COMMIT_BRANCH == "develop"
when: manual
Expand Down
2 changes: 2 additions & 0 deletions apps/ios/ProtonVPNUITests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>1028</string>
<key>DYNAMIC_DOMAIN</key>
<string>${DYNAMIC_DOMAIN}</string>
</dict>
</plist>
173 changes: 45 additions & 128 deletions apps/ios/ProtonVPNUITests/ProtonVPNUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,95 +21,56 @@
//

import fusion
import XCTest
import PMLogger
import ProtonCoreDoh
import ProtonCoreEnvironment
import ProtonCoreLog
import ProtonCoreQuarkCommands
import ProtonCoreTestingToolkitUITestsLogin
import ProtonCoreTestingToolkitUnitTestsCore
import ProtonCoreTestingToolkitUITestsCore
import XCTest

class ProtonVPNUITests: CoreTestCase {
class ProtonVPNUITests: ProtonCoreBaseTestCase {

let mainRobot = MainRobot()

let app = XCUIApplication()
var launchEnvironment: String?
lazy var logFileUrl = LogFileManagerImplementation().getFileUrl(named: "ProtonVPN.log")

private static var isAutoFillPasswordsEnabled = true

/// Runs only once per test run.
override class func setUp() {
super.setUp()
disableAutoFillPasswords()
}

/// Runs before each test case.

override func setUp() {
launchArguments = [
"UITests",
"-BlockOneTimeAnnouncement", "YES",
"-BlockUpdatePrompt", "YES",
"-AppleLanguages", "(en)",
"enforceUnauthSessionStrictVerificationOnBackend"
]

beforeSetUp(bundleIdentifier: "ch.protonmail.vpn.ProtonVPNUITests", launchArguments: launchArguments)
super.setUp()

continueAfterFailure = false

app.launchArguments += ["UITests"]
app.launchArguments += ["-BlockOneTimeAnnouncement", "YES"]
app.launchArguments += ["-BlockUpdatePrompt", "YES"]
app.launchArguments += ["-AppleLanguages", "(en)"]
// Put setup code here. This method is called before the invocation of each test method in the class.
app.launchArguments += ["enforceUnauthSessionStrictVerificationOnBackend"]
app.launchArguments += [LogFileManagerImplementation.logDirLaunchArgument,
logFileUrl.absoluteString]

setupSnapshot(app)

// Inject launchEnvironment
if let env = launchEnvironment {
app.launchEnvironment[env] = "1"
}
PMLog.info("UI TEST runs on: " + doh.getAccountHost())

app.launch()

logoutIfNeeded()

}

override open func tearDownWithError() throws {

try super.tearDownWithError()

if FileManager.default.fileExists(atPath: logFileUrl.absoluteString) {
let pmLogAttachment = XCTAttachment(contentsOfFile: logFileUrl)
pmLogAttachment.lifetime = .deleteOnSuccess
add(pmLogAttachment)
}

guard #available(iOS 15, *) else { return }

let group = DispatchGroup()
group.enter()

let osLogContent = OSLogContent()
osLogContent.loadContent { [weak self] logContent in
let osLogAttachment = XCTAttachment(string: logContent)
osLogAttachment.lifetime = .deleteOnSuccess
self?.add(osLogAttachment)

group.leave()
}

group.wait()
}

func logoutIfNeeded() {
let tabBarsQuery = app.tabBars
_ = tabBarsQuery.element.waitForExistence(timeout: 1) // tests would reach this point when the tabbar is not yet available
guard !tabBarsQuery.allElementsBoundByIndex.isEmpty else {
return
}

tabBarsQuery.buttons["Settings"].tap()
let logoutButton = app.buttons["Sign out"]
app.swipeUp() // For iphone SE small screen
logoutButton.tap()
}

private static func disableAutoFillPasswords() {
guard #available(iOS 16.0, *), isAutoFillPasswordsEnabled else {
return
Expand Down Expand Up @@ -146,84 +107,39 @@ class ProtonVPNUITests: CoreTestCase {
}

func setupAtlasEnvironment() {
if staticText(dynamicDomain).exists() {
openLoginScreen()
} else {
textField("customEnvironmentTextField").waitUntilExists(time:1).tap().clearText().typeText(dynamicDomain)
button("Change and kill the app").tap()
closeAndOpenTheApp()
}
}

func setupProdEnvironment() {
if staticText("https://vpn-api.proton.me").waitUntilExists(time:1).exists() {
openLoginScreen()
} else {
button("Reset to production and kill the app").tap()
closeAndOpenTheApp()
}
}

private func closeAndOpenTheApp() {
button("OK").tap()
device().foregroundApp(.launch)
button("Use and continue").tap()
}

private func openLoginScreen() {
button("Use and continue").tap()
}

let dynamicDomain: String = {
if let domain = ProcessInfo.processInfo.environment["DYNAMIC_DOMAIN"], !domain.isEmpty {
return "https://" + domain + "/api"
let url = doh.getCurrentlyUsedHostUrl()
if staticText(url).exists() {
openLoginScreen()
} else {
return ObfuscatedConstants.blackDefaultHost + ObfuscatedConstants.blackDefaultPath
textField("customEnvironmentTextField").waitUntilExists(time:1).tap().clearText().typeText(url)
button("Change and kill the app").tap()
closeAndOpenTheApp()
}
}()

lazy var dynamicHost: String? = {
let url = URL(string: dynamicDomain) ??
URL(string: ObfuscatedConstants.blackDefaultHost)!
}

if #available(iOS 16, *) {
if let host = url.host() {
return host
}
func setupProdEnvironment() {
if staticText("https://vpn-api.proton.me").waitUntilExists(time:1).exists() {
openLoginScreen()
} else {
if let host = url.host {
return host
}
}
return nil
}()

func unbanBeforeSignup(doh: DoHInterface) {
let expectQuarkCommandToFinish = expectation(description: "Quark command should finish")
QuarkCommands.unban(currentlyUsedHostUrl: doh.getCurrentlyUsedHostUrl()) { _ in
expectQuarkCommandToFinish.fulfill()
button("Reset to production and kill the app").tap()
closeAndOpenTheApp()
}
wait(for: [expectQuarkCommandToFinish], timeout: 5.0)
}

func createAccountForTest(doh: DoHInterface, accountToBeCreated: AccountAvailableForCreation, at function: String = #function) -> Bool {
let expectQuarkCommandToFinish = expectation(description: "Quark command should finish")
var quarkCommandResult: Result<CreatedAccountDetails, CreateAccountError>?
QuarkCommands.create(account: accountToBeCreated, currentlyUsedHostUrl: doh.getCurrentlyUsedHostUrl()) { result in
quarkCommandResult = result
expectQuarkCommandToFinish.fulfill()
}
private func closeAndOpenTheApp() {
button("OK").tap()
device().foregroundApp(.launch)
button("Use and continue").tap()
}

wait(for: [expectQuarkCommandToFinish], timeout: 5.0)
if case .failure(let error) = quarkCommandResult {
XCTFail("Internal account creation failed in test \(function) because of \(error.userFacingMessageInQuarkCommands)")
return false
}
return true
private func openLoginScreen() {
button("Use and continue").tap()
}

var doh: DoHInterface {
if let customDomain = ProcessInfo.processInfo.environment["DYNAMIC_DOMAIN"], !customDomain.isEmpty {
lazy var quarkCommands = Quark().baseUrl(doh)

var doh: DoH {
if let customDomain = dynamicDomain.map({ "\($0)" }) {
return CustomServerConfigDoH(
signupDomain: customDomain,
captchaHost: "https://api.\(customDomain)",
Expand All @@ -245,4 +161,5 @@ class ProtonVPNUITests: CoreTestCase {
)
}
}

}
14 changes: 10 additions & 4 deletions apps/ios/ProtonVPNUITests/Robots/Login/Login/LoginRobot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import fusion
import ProtonCoreQuarkCommands

fileprivate let titleId = "LoginViewController.titleLabel"
fileprivate let subtitleId = "LoginViewController.subtitleLabel"
Expand All @@ -31,10 +32,15 @@ class LoginRobot: CoreElements {

@discardableResult
func enterCredentials(_ name: Credentials) -> LoginRobot {
return typeUsername(username: name.username)
.typePassword(password: name.password)
}

return typeUsername(username: name.username)
.typePassword(password: name.password)
}

func enterCredentials(_ user: User) -> LoginRobot {
return typeUsername(username: user.name)
.typePassword(password: user.password)
}

@discardableResult
func enterIncorrectCredentials(_ username: String, _ password: String) -> LoginRobot {
return typeUsername(username: username)
Expand Down
2 changes: 1 addition & 1 deletion apps/ios/ProtonVPNUITests/Robots/MainRobot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class MainRobot: CoreElements {

@discardableResult
func goToSettingsTab() -> SettingsRobot {
button(tabSettings).tap()
button(tabSettings).waitUntilExists(time: 30).tap()
return SettingsRobot()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import ProtonCoreTestingToolkitUITestsLogin
class ConnectionTests: ProtonVPNUITests {

private let loginRobot = LoginRobot()
private let mainRobot = MainRobot()
private let connectionStatusRobot = ConnectionStatusRobot()
private let countryListRobot = CountryListRobot()
private let serverListRobot = ServerListRobot()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@
import fusion
import ProtonCoreTestingToolkitUITestsLogin
import ProtonCoreQuarkCommands
import ProtonCoreEnvironment

final class InternalAndExternalSignUpTests: ProtonVPNUITests {

private let mainRobot = MainRobot()
private let loginRobot = LoginRobot()

override func setUp() {
super.setUp()
setupAtlasEnvironment()
Expand All @@ -35,8 +31,6 @@ final class InternalAndExternalSignUpTests: ProtonVPNUITests {
}

func testSignUpWithInternalAccountWorks() {
unbanBeforeSignup(doh: doh)

let randomUsername = StringUtils().randomAlphanumericString(length: 8)
let randomEmail = "\(StringUtils().randomAlphanumericString(length: 8))@proton.uitests"
let randomPassword = StringUtils().randomAlphanumericString(length: 8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
import XCTest
import fusion
import ProtonCoreTestingToolkitUITestsLogin
import ProtonCoreTestingToolkitUITestsCore

class LoginExtAccountTests: ProtonVPNUITests {

let mainRobot = MainRobot()
let loginRobot = ProtonCoreTestingToolkitUITestsLogin.LoginRobot()

override func setUp() {
launchEnvironment = "ExtAccountNotSupportedStub"
launchEnvironment = ["ExtAccountNotSupportedStub": "true"]
super.setUp()
setupAtlasEnvironment()
mainRobot
.showLogin()
.verify.loginScreenIsShown()
}

// Sign-in with external account on old iOS version
func testLoginExtAcountNotSupportedOnOldAppVersion() {
loginRobot
Expand Down
Loading

0 comments on commit f05f2f5

Please sign in to comment.