diff --git a/StreamChatUITestsAppUITests/Robots/UserRobot.swift b/StreamChatUITestsAppUITests/Robots/UserRobot.swift index 63ae8633a6..e9692b0365 100644 --- a/StreamChatUITestsAppUITests/Robots/UserRobot.swift +++ b/StreamChatUITestsAppUITests/Robots/UserRobot.swift @@ -11,11 +11,6 @@ final class UserRobot: Robot { let composer = MessageListPage.Composer.self let contextMenu = MessageListPage.ContextMenu.self let debugAlert = MessageListPage.Alert.Debug.self - private var server: StreamMockServer - - init(_ server: StreamMockServer) { - self.server = server - } @discardableResult func login() -> Self { @@ -56,13 +51,6 @@ final class UserRobot: Robot { ChannelListPage.cells.allElementsBoundByIndex[channelCellIndex].waitForHitPoint().safeTap() return self } - - @discardableResult - public func waitForJwtToExpire() -> Self { - let sleepTime = UInt32((StreamMockServer.jwtTimeout + 2) * 1_000_000) - usleep(sleepTime) - return self - } @discardableResult public func sleep(_ seconds: Double) -> Self { diff --git a/StreamChatUITestsAppUITests/Tests/Authentication_Tests.swift b/StreamChatUITestsAppUITests/Tests/Authentication_Tests.swift index c028a1319a..4dc820577a 100644 --- a/StreamChatUITestsAppUITests/Tests/Authentication_Tests.swift +++ b/StreamChatUITestsAppUITests/Tests/Authentication_Tests.swift @@ -123,7 +123,7 @@ final class Authentication_Tests: StreamTestCase { .assertConnectionStatus(.connected) } WHEN("token expires") { - userRobot.waitForJwtToExpire() + backendRobot.waitForJwtToExpire() } THEN("app requests a token refresh") { userRobot.assertConnectionStatus(.connected) @@ -142,7 +142,7 @@ final class Authentication_Tests: StreamTestCase { deviceRobot.moveApplication(to: .background) } AND("token expires") { - userRobot.waitForJwtToExpire() + backendRobot.waitForJwtToExpire() } WHEN("user comes back to foreground") { deviceRobot.moveApplication(to: .foreground) @@ -164,7 +164,7 @@ final class Authentication_Tests: StreamTestCase { userRobot.setConnectivity(to: .off) } WHEN("token expires") { - userRobot.waitForJwtToExpire() + backendRobot.waitForJwtToExpire() } WHEN("user comes back online") { userRobot.setConnectivity(to: .on) diff --git a/StreamChatUITestsAppUITests/Tests/Base TestCase/StreamTestCase.swift b/StreamChatUITestsAppUITests/Tests/Base TestCase/StreamTestCase.swift index 98d9bead26..ee65b5c83c 100644 --- a/StreamChatUITestsAppUITests/Tests/Base TestCase/StreamTestCase.swift +++ b/StreamChatUITestsAppUITests/Tests/Base TestCase/StreamTestCase.swift @@ -8,7 +8,7 @@ let app = XCUIApplication() class StreamTestCase: XCTestCase { let deviceRobot = DeviceRobot(app) - var userRobot: UserRobot! + let userRobot = UserRobot() var backendRobot: BackendRobot! var participantRobot: ParticipantRobot! var mockServer: StreamMockServer! @@ -19,10 +19,6 @@ class StreamTestCase: XCTestCase { continueAfterFailure = false try super.setUpWithError() - mockServer = StreamMockServer(driverPort: "4566", testName: testName) - backendRobot = BackendRobot(mockServer) - participantRobot = ParticipantRobot(mockServer) - userRobot = UserRobot(mockServer) alertHandler() backendHandler() app.launch() @@ -31,7 +27,9 @@ class StreamTestCase: XCTestCase { override func tearDownWithError() throws { attachElementTree() app.terminate() - mockServer.stop() + if useMockServer { + mockServer.stop() + } try super.tearDownWithError() app.launchArguments.removeAll() @@ -41,13 +39,15 @@ class StreamTestCase: XCTestCase { extension StreamTestCase { private func backendHandler() { - app.setEnvironmentVariables([ - .websocketHost: "ws://localhost", - .httpHost: "http://localhost", - .port: StreamMockServer.port! - ]) - if useMockServer { + mockServer = StreamMockServer(driverPort: "4566", testName: testName) + backendRobot = BackendRobot(mockServer) + participantRobot = ParticipantRobot(mockServer) + app.setEnvironmentVariables([ + .websocketHost: "ws://localhost", + .httpHost: "http://localhost", + .port: StreamMockServer.port! + ]) app.setLaunchArguments(.useMockServer) } else if let switchApiKey { app.setEnvironmentVariables([.customApiKey: switchApiKey]) diff --git a/StreamChatUITestsAppUITests/Tests/Performance/MessageListScrollTime.swift b/StreamChatUITestsAppUITests/Tests/Performance/MessageListScrollTime.swift index 482f234679..0148fb9d95 100644 --- a/StreamChatUITestsAppUITests/Tests/Performance/MessageListScrollTime.swift +++ b/StreamChatUITestsAppUITests/Tests/Performance/MessageListScrollTime.swift @@ -6,11 +6,25 @@ import XCTest @available(iOS 15.0, *) class MessageListScrollTime: StreamTestCase { + override func setUpWithError() throws { + useMockServer = false + switchApiKey = "zcgvnykxsfm8" + try super.setUpWithError() + } + func testMessageListScrollTime() { - WHEN("user opens the message list") { - backendRobot.generateChannels(channelsCount: 1, messagesCount: 100, attachments: true) - participantRobot.addReaction(type: .like) - userRobot.login().openChannel() + WHEN("user logs in") { + userRobot.login() + } + AND("user opens a channel with many messages") { + let minMessageCount = 20 + for channelIndex in 0..= minMessageCount { + break + } + userRobot.tapOnBackButton() + } } THEN("user scrolls the message list") { let measureOptions = XCTMeasureOptions() diff --git a/TestTools/StreamChatTestMockServer/Robots/BackendRobot.swift b/TestTools/StreamChatTestMockServer/Robots/BackendRobot.swift index ae5a3f4138..03841e07d9 100644 --- a/TestTools/StreamChatTestMockServer/Robots/BackendRobot.swift +++ b/TestTools/StreamChatTestMockServer/Robots/BackendRobot.swift @@ -56,6 +56,13 @@ public class BackendRobot { _ = mockServer.postRequest(endpoint: "delay_messages?delay=\(seconds)") return self } + + @discardableResult + public func waitForJwtToExpire() -> Self { + let sleepTime = UInt32((StreamMockServer.jwtTimeout + 2) * 1_000_000) + usleep(sleepTime) + return self + } public func revokeToken(duration: Int = 5) { waitForMockServerToStart()