Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/browserstack-service/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,12 @@ export default class BrowserstackService implements Services.ServiceInstance {
}

this._reloadHappened = true
if (BrowserstackCLI.getInstance().isRunning()) {
const instance = AutomationFramework.getTrackedInstance() as AutomationFrameworkInstance
if (instance) {
AutomationFramework.setState(instance, AutomationFrameworkConstants.KEY_FRAMEWORK_SESSION_ID, newSessionId)
}
}

const { setSessionName, setSessionStatus } = this._options
const ignoreHooksStatus = this._options.testObservabilityOptions?.ignoreHooksStatus === true
Expand Down
35 changes: 35 additions & 0 deletions packages/browserstack-service/tests/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import * as utils from '../src/util.js'
import InsightsHandler from '../src/insights-handler.js'
import { BrowserstackCLI } from '../src/cli/index.js'
import * as bstackLogger from '../src/bstackLogger.js'
import AutomationFramework from '../src/cli/frameworks/automationFramework.js'
import { AutomationFrameworkConstants } from '../src/cli/frameworks/constants/automationFrameworkConstants.js'

const jasmineSuiteTitle = 'Jasmine__TopLevel__Suite'
const sessionBaseUrl = 'https://api.browserstack.com/automate/sessions'
Expand Down Expand Up @@ -206,6 +208,39 @@ describe('onReload()', () => {
})
expect(service['_suiteTitle']).toEqual('my suite title')
})

it('should update framework session id on tracked instance when CLI is running', async () => {
const getInstanceSpy = vi.spyOn(BrowserstackCLI, 'getInstance').mockReturnValue({ isRunning: () => true } as any)
const trackedInstance = {} as any
const getTrackedInstanceSpy = vi.spyOn(AutomationFramework, 'getTrackedInstance').mockReturnValue(trackedInstance)
const setStateSpy = vi.spyOn(AutomationFramework, 'setState').mockImplementation(() => {})
const updateSpy = vi.spyOn(service, '_update').mockResolvedValue(undefined as any)
const printSpy = vi.spyOn(service, '_printSessionURL').mockResolvedValue(undefined as any)
service['_browser'] = browser

await service.onReload('1', '2')
expect(setStateSpy).toHaveBeenCalledWith(trackedInstance, AutomationFrameworkConstants.KEY_FRAMEWORK_SESSION_ID, '2')

getInstanceSpy.mockRestore()
getTrackedInstanceSpy.mockRestore()
setStateSpy.mockRestore()
updateSpy.mockRestore()
printSpy.mockRestore()
})

it('should not update framework session id when CLI is not running', async () => {
const setStateSpy = vi.spyOn(AutomationFramework, 'setState').mockImplementation(() => {})
const updateSpy = vi.spyOn(service, '_update').mockResolvedValue(undefined as any)
const printSpy = vi.spyOn(service, '_printSessionURL').mockResolvedValue(undefined as any)
service['_browser'] = browser

await service.onReload('1', '2')
expect(setStateSpy).not.toHaveBeenCalled()

setStateSpy.mockRestore()
updateSpy.mockRestore()
printSpy.mockRestore()
})
})

describe('beforeSession', () => {
Expand Down
Loading