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
55 changes: 44 additions & 11 deletions packages/wdio-browserstack-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export const config = {
key: process.env.BROWSERSTACK_ACCESS_KEY,
services: [
['browserstack', {
testObservability: true,
testObservabilityOptions: {
testReporting: true,
testReportingOptions: {
projectName: "Your project name goes here",
buildName: "The static build job name goes here e.g. Nightly regression"
},
Expand All @@ -44,25 +44,45 @@ export const config = {

In order to authorize to the BrowserStack service your config needs to contain a [`user`](https://webdriver.io/docs/options#user) and [`key`](https://webdriver.io/docs/options#key) option.

### testObservability
### testReporting (formerly testObservability)

Test Observability is an advanced test reporting tool that gives insights to improve your automation tests and helps you debug faster. Its enabled by default by setting the testObservability​ flag as true for all users of browserstack-service. You can disable this by setting the testObservability​ flag to false.
Test Reporting and Analytics is an advanced test reporting tool that gives insights to improve your automation tests and helps you debug faster. It's enabled by default by setting the testReporting flag as true for all users of browserstack-service. You can disable this by setting the testReporting flag to false.

Once your tests finish running, you can visit [Test Observability](https://observability.browserstack.com/?utm_source=webdriverio&utm_medium=partnered&utm_campaign=documentation) to debug your builds with additional insights like Unique Error Analysis, Automatic Flaky Test Detection, and more.
Once your tests finish running, you can visit [Test Reporting and Analytics](https://automation.browserstack.com/?utm_source=webdriverio&utm_medium=partnered&utm_campaign=documentation) to debug your builds with additional insights like Unique Error Analysis, Automatic Flaky Test Detection, and more.

You can use Test Observability even if you don’t run your tests on the BrowserStack infrastructure. Even if you run your tests on a CI, a local machine, or even on other cloud service providers, Test Observability can still generate intelligent test reports and advanced analytics on your tests.

If you want to use Test Observability without running your tests on BrowserStack infrastructure, you can set your config as follows:
You can use Test Reporting and Analytics even if you don't run your tests on the BrowserStack infrastructure. Even if you run your tests on a CI, a local machine, or even on other cloud service providers, Test Reporting and Analytics can still generate intelligent test reports and advanced analytics on your tests.

If you want to use Test Reporting and Analytics without running your tests on BrowserStack infrastructure, you can set your config as follows:

```js
// wdio.conf.js
export const config = {
// ...
services: [
['browserstack', {
testObservability: true,
testObservabilityOptions: {
testReporting: true,
testReportingOptions: {
user: process.env.BROWSERSTACK_USERNAME,
key: process.env.BROWSERSTACK_ACCESS_KEY,
projectName: "Your project name goes here",
buildName: "The static build job name goes here e.g. Nightly regression"
}
}]
],
// ...
};
```

For backward compatibility, the legacy `testObservability` and `testObservabilityOptions` flags are still supported:

```js
// wdio.conf.js (legacy configuration)
export const config = {
// ...
services: [
['browserstack', {
testObservability: true, // deprecated, use testReporting instead
testObservabilityOptions: { // deprecated, use testReportingOptions instead
user: process.env.BROWSERSTACK_USERNAME,
key: process.env.BROWSERSTACK_ACCESS_KEY,
projectName: "Your project name goes here",
Expand All @@ -74,7 +94,20 @@ export const config = {
};
```

You can explore all the features of Test Observability in [this sandbox](https://observability-demo.browserstack.com/?utm_source=webdriverio&utm_medium=partnered&utm_campaign=documentation) or read more about it [here](https://www.browserstack.com/docs/test-observability/overview/what-is-test-observability?utm_source=webdriverio&utm_medium=partnered&utm_campaign=documentation).
#### Environment Variables

The following environment variables are supported:

**New (recommended):**
- `BROWSERSTACK_TEST_REPORTING` - Enable/disable test reporting
- `BROWSERSTACK_TEST_REPORTING_DEBUG` - Enable debug mode for test reporting
- `TEST_REPORTING_BUILD_TAG` - Comma-separated build tags

**Legacy (still supported):**

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check with product once do we need to have this added?

- `BROWSERSTACK_OBSERVABILITY` - Enable/disable test observability (deprecated)
- `TEST_OBSERVABILITY_BUILD_TAG` - Comma-separated build tags (deprecated)

You can explore all the features of Test Reporting and Analytics in [this sandbox](https://automation-demo.browserstack.com/?utm_source=webdriverio&utm_medium=partnered&utm_campaign=documentation) or read more about it [here](https://www.browserstack.com/docs/test-reporting/overview/what-is-test-reporting?utm_source=webdriverio&utm_medium=partnered&utm_campaign=documentation).

### browserstackLocal
Set this to true to enable routing connections from BrowserStack cloud through your computer.
Expand Down
6 changes: 3 additions & 3 deletions packages/wdio-browserstack-service/src/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ export default class BStackCleanup {
if (!process.env[BROWSERSTACK_TESTHUB_JWT]) {
return
}
BStackLogger.debug('Executing observability cleanup')
BStackLogger.debug('Executing Test Reporting and Analytics cleanup')
try {
const killSignal = funnelData?.event_properties?.finishedMetadata?.signal
const result = await stopBuildUpstream(killSignal)
if (process.env[BROWSERSTACK_OBSERVABILITY] && process.env[BROWSERSTACK_TESTHUB_UUID]) {
BStackLogger.info(`\nVisit https://observability.browserstack.com/builds/${process.env[BROWSERSTACK_TESTHUB_UUID]} to view build report, insights, and many more debugging information all at one place!\n`)
BStackLogger.info(`\nVisit https://automation.browserstack.com/builds/${process.env[BROWSERSTACK_TESTHUB_UUID]} to view build report, insights, and many more debugging information all at one place!\n`)
}
const status = (result && result.status) || 'failed'
const message = (result && result.message)
this.updateO11yStopData(funnelData, status, status === 'failed' ? message : undefined)
} catch (e: unknown) {
BStackLogger.error('Error in stopping Observability build: ' + e)
BStackLogger.error('Error in stopping Test Reporting and Analytics build: ' + e)
this.updateO11yStopData(funnelData, 'failed', e)
}
}
Expand Down
23 changes: 22 additions & 1 deletion packages/wdio-browserstack-service/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const DEFAULT_OPTIONS: Partial<BrowserstackConfig> = {
setSessionName: true,
setSessionStatus: true,
testObservability: true,
testReporting: true,
accessibility: false
}

Expand Down Expand Up @@ -120,9 +121,29 @@ export const BSTACK_A11Y_POLLING_TIMEOUT = 'BSTACK_A11Y_POLLING_TIMEOUT'
// Whether session is a accessibility session
export const BROWSERSTACK_ACCESSIBILITY = 'BROWSERSTACK_ACCESSIBILITY'

// Whether session is a observability session
// Whether session is a test reporting session (new name)
export const BROWSERSTACK_TEST_REPORTING = 'BROWSERSTACK_TEST_REPORTING'

// Debug flag for test reporting
export const BROWSERSTACK_TEST_REPORTING_DEBUG = 'BROWSERSTACK_TEST_REPORTING_DEBUG'

// Build tag environment variable for test reporting
export const TEST_REPORTING_BUILD_TAG = 'TEST_REPORTING_BUILD_TAG'

// Build name environment variable for test reporting
export const TEST_REPORTING_BUILD_NAME = 'TEST_REPORTING_BUILD_NAME'

// Project name environment variable for test reporting
export const TEST_REPORTING_PROJECT_NAME = 'TEST_REPORTING_PROJECT_NAME'

// Whether session is a observability session (legacy name)
export const BROWSERSTACK_OBSERVABILITY = 'BROWSERSTACK_OBSERVABILITY'

// Legacy environment variables for backward compatibility
export const TEST_OBSERVABILITY_BUILD_TAG = 'TEST_OBSERVABILITY_BUILD_TAG'
export const TEST_OBSERVABILITY_BUILD_NAME = 'TEST_OBSERVABILITY_BUILD_NAME'
export const TEST_OBSERVABILITY_PROJECT_NAME = 'TEST_OBSERVABILITY_PROJECT_NAME'

// Maximum size of VCS info which is allowed
export const MAX_GIT_META_DATA_SIZE_IN_BYTES = 64 * 1024

Expand Down
2 changes: 1 addition & 1 deletion packages/wdio-browserstack-service/src/insights-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ class _InsightsHandler {
this.listener.logCreated([stdLog])
}
} catch (error) {
BStackLogger.debug(`Exception in uploading log data to Observability with error : ${error}`)
BStackLogger.debug(`Exception in uploading log data to Test Reporting and Analytics with error : ${error}`)
}
}

Expand Down
10 changes: 8 additions & 2 deletions packages/wdio-browserstack-service/src/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ import {
isValidCapsForHealing,
getBooleanValueFromString,
validateCapsWithNonBstackA11y,
mergeChromeOptions
mergeChromeOptions,
normalizeTestReportingConfig,
normalizeTestReportingEnvVariables
} from './util.js'
import { getProductMap } from './testHub/utils.js'
import CrashReporter from './crash-reporter.js'
Expand Down Expand Up @@ -84,6 +86,10 @@ export default class BrowserstackLauncherService implements Services.ServiceInst
// added to maintain backward compatibility with webdriverIO v5
this._config || (this._config = _options)

//normalizing testReporting config and env variables
normalizeTestReportingConfig(this._options)

normalizeTestReportingEnvVariables()
this.browserStackConfig = BrowserStackConfig.getInstance(_options, _config)
if (Array.isArray(capabilities)) {
capabilities
Expand Down Expand Up @@ -404,7 +410,7 @@ export default class BrowserstackLauncherService implements Services.ServiceInst
BStackLogger.debug('Sending stop launch event')
await stopBuildUpstream()
if (process.env[BROWSERSTACK_OBSERVABILITY] && process.env[BROWSERSTACK_TESTHUB_UUID]) {
console.log(`\nVisit https://observability.browserstack.com/builds/${process.env[BROWSERSTACK_TESTHUB_UUID]} to view build report, insights, and many more debugging information all at one place!\n`)
console.log(`\nVisit https://automation.browserstack.com/builds/${process.env[BROWSERSTACK_TESTHUB_UUID]} to view build report, insights, and many more debugging information all at one place!\n`)
}
this.browserStackConfig.testObservability.buildStopped = true

Expand Down
2 changes: 1 addition & 1 deletion packages/wdio-browserstack-service/src/request-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class RequestQueueHandler {

add (event: UploadType) {
if (!process.env[TESTOPS_BUILD_COMPLETED_ENV]) {
throw new Error('Observability build start not completed yet.')
throw new Error('Test Reporting and Analytics build start not completed yet.')
}

this.queue.push(event)
Expand Down
8 changes: 7 additions & 1 deletion packages/wdio-browserstack-service/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
isBrowserstackSession,
patchConsoleLogs,
shouldAddServiceVersion,
isTrue
isTrue,
normalizeTestReportingConfig,
normalizeTestReportingEnvVariables
} from './util.js'
import type { BrowserstackConfig, BrowserstackOptions, MultiRemoteAction, SessionResponse, TurboScaleSessionResponse } from './types.js'
import type { Pickle, Feature, ITestCaseHookParameter, CucumberHook } from './cucumber-types.js'
Expand Down Expand Up @@ -60,6 +62,10 @@ export default class BrowserstackService implements Services.ServiceInstance {
this._options = { ...DEFAULT_OPTIONS, ...options }
// added to maintain backward compatibility with webdriverIO v5
this._config || (this._config = this._options)

normalizeTestReportingConfig(this._options)

normalizeTestReportingEnvVariables()
this._observability = this._options.testObservability
this._accessibility = this._options.accessibility
this._percy = isTrue(process.env.BROWSERSTACK_PERCY)
Expand Down
29 changes: 26 additions & 3 deletions packages/wdio-browserstack-service/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ export interface TestObservabilityOptions {
ignoreHooksStatus?: boolean
}

// Add new interface that's identical but with new name
export interface TestReportingOptions {
buildName?: string,
projectName?: string,
buildTag?: string[],
user?: string,
key?: string
}

export interface BrowserstackOptions extends Options.Testrunner {
selfHeal?: boolean;
}
Expand All @@ -61,17 +70,31 @@ export interface BrowserstackConfig {
*/
buildIdentifier?: string;
/**
* Set this to true to enable BrowserStack Test Observability which will collect test related data
* Set this to true to enable BrowserStack Test Reporting and Analytics which will collect test related data
* (name, hierarchy, status, error stack trace, file name and hierarchy), test commands, etc.
* and show all the data in a meaningful manner in BrowserStack Test Observability dashboards for faster test debugging and better insights.
* and show all the data in a meaningful manner in BrowserStack Test Reporting and Analytics dashboards for faster test debugging and better insights.
* @default true
* @deprecated Use testReporting instead
*/
testObservability?: boolean;
/**
* Set the Test Observability related config options under this key.
* Set this to true to enable BrowserStack Test Reporting and Analytics which will collect test related data
* (name, hierarchy, status, error stack trace, file name and hierarchy), test commands, etc.
* and show all the data in a meaningful manner in BrowserStack Test Reporting and Analytics dashboards for faster test debugging and better insights.
* @default true
*/
testReporting?: boolean;
/**
* Set the Test Reporting and Analytics related config options under this key.
* For e.g. buildName, projectName, BrowserStack access credentials, etc.
* @deprecated Use testReportingOptions instead
*/
testObservabilityOptions?: TestObservabilityOptions;
/**
* Set the Test Reporting and Analytics related config options under this key.
* For e.g. buildName, projectName, BrowserStack access credentials, etc.
*/
testReportingOptions?: TestReportingOptions;
/**
* Set this to true to enable BrowserStack Percy which will take screenshots
* and snapshots for your tests run on Browserstack
Expand Down
32 changes: 30 additions & 2 deletions packages/wdio-browserstack-service/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ import {
TESTOPS_BUILD_COMPLETED_ENV,
BROWSERSTACK_TESTHUB_JWT,
BROWSERSTACK_OBSERVABILITY,
BROWSERSTACK_TEST_REPORTING,
BROWSERSTACK_ACCESSIBILITY,
MAX_GIT_META_DATA_SIZE_IN_BYTES,
GIT_META_DATA_TRUNCATED,
APP_ALLY_ENDPOINT,
APP_ALLY_ISSUES_SUMMARY_ENDPOINT,
APP_ALLY_ISSUES_ENDPOINT
APP_ALLY_ISSUES_ENDPOINT,
TEST_REPORTING_PROJECT_NAME
} from './constants.js'
import CrashReporter from './crash-reporter.js'
import { BStackLogger } from './bstackLogger.js'
Expand Down Expand Up @@ -1204,11 +1206,37 @@ export async function batchAndPostEvents (eventUrl: string, kind: string, data:
}).json()
BStackLogger.debug(`[${kind}] Success response: ${JSON.stringify(response)}`)
} catch (error) {
BStackLogger.debug(`[${kind}] EXCEPTION IN ${kind} REQUEST TO TEST OBSERVABILITY : ${error}`)
BStackLogger.debug(`[${kind}] EXCEPTION IN ${kind} REQUEST TO TEST Reporting and Analytics : ${error}`)
throw new Error('Exception in request ' + error)
}
}

export function normalizeTestReportingConfig(_options: BrowserstackConfig & Options.Testrunner){
if (!isUndefined(_options.testReporting)){
_options.testObservability = _options.testReporting
}

if (!isUndefined(_options.testReportingOptions)){
_options.testObservabilityOptions = _options.testReportingOptions
}
}

export function normalizeTestReportingEnvVariables(){
if (!isUndefined(process.env[BROWSERSTACK_TEST_REPORTING])){
process.env[BROWSERSTACK_OBSERVABILITY] = process.env[BROWSERSTACK_TEST_REPORTING]
}
if (!isUndefined(process.env[TEST_REPORTING_PROJECT_NAME])){
process.env.TEST_OBSERVABILITY_PROJECT_NAME = process.env[TEST_REPORTING_PROJECT_NAME]
}
if (!isUndefined(process.env.TEST_REPORTING_BUILD_NAME)) {
process.env.TEST_OBSERVABILITY_BUILD_NAME = process.env.TEST_REPORTING_BUILD_NAME
}
if (!isUndefined(process.env.TEST_REPORTING_BUILD_TAG)) {
process.env.TEST_OBSERVABILITY_BUILD_TAG = process.env.TEST_REPORTING_BUILD_TAG
}

}

export function getObservabilityUser(options: BrowserstackConfig & Options.Testrunner, config: Options.Testrunner) {
if (process.env.BROWSERSTACK_USERNAME) {
return process.env.BROWSERSTACK_USERNAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('RequestQueueHandler', () => {
describe('add', () => {
it('throw error if BS_TESTOPS_BUILD_COMPLETED not present', () => {
delete process.env[TESTOPS_BUILD_COMPLETED_ENV]
expect(() => requestQueueHandler.add({ event_type: 'there' })).toThrowError(/Observability build start not completed yet/)
expect(() => requestQueueHandler.add({ event_type: 'there' })).toThrowError(/Test Reporting and Analytics build start not completed yet/)
})

it('if event_type in BATCH_EVENT_TYPES', () => {
Expand Down
Loading