@tvlabs/wdio-service 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 TV Labs Ltd
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,115 @@
1
+ <p align="center">
2
+ <a href="https://tvlabs.ai">
3
+ <img alt="TV Labs Logo" width="200" src="https://tvlabs.ai/images/tvlabs.svg">
4
+ </a>
5
+ </p>
6
+
7
+ <p align="center">
8
+ <b>@tvlabs/wdio-service</b> is a <a href="https://webdriver.io/">WebdriverIO</a> service for seamless integration with the <a href="https://tvlabs.ai">TV Labs</a> platform.
9
+ </p>
10
+
11
+ ## Introduction
12
+
13
+ The `@tvlabs/wdio-service` package uses a websocket to connect to the TV Labs platform before an Appium session begins, logging events relating to TV Labs session creation as they occur. This offloads the responsibility of creating the TV Labs session from the `POST /session` Webdriver endpoint, leading to more reliable session requests and creation.
14
+
15
+ The service first makes a session request, and then subscribes to events for that request. Once the session has been filled and is ready for the Webdriver script to begin, the service receives a ready event with the TV Labs session ID. This session ID is injected into the capabilities as `tvlabs:session_id` on the Webdriver session create request.
16
+
17
+ ## Installation
18
+
19
+ In your WebdriverIO project, run one of the following commands to install:
20
+
21
+ ### NPM
22
+
23
+ ```
24
+ npm i --save @tvlabs/wdio-service
25
+ ```
26
+
27
+ ### Yarn
28
+
29
+ ```
30
+ yarn add @tvlabs/wdio-service
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ### WebdriverIO Test Runner
36
+
37
+ To use this as a WebdriverIO test runner service, include the service in your WebdriverIO configuration file (e.g. `wdio.conf.ts`) with your TV Labs API key set in the options.
38
+
39
+ ```javascript
40
+ import TVLabsService from '@tvlabs/wdio-service';
41
+
42
+ export const config = {
43
+ // ...
44
+ services: [
45
+ [TVLabsService, apiKey: process.env.TVLABS_API_KEY]
46
+ ],
47
+ // ...
48
+ }
49
+ ```
50
+
51
+ ### WebdriverIO Remote
52
+
53
+ To use this with WebdriverIO remote but without the test runner, call the beforeSession hook before instantiating the remote.
54
+
55
+ ```javascript
56
+ import { remote } from 'webdriverio';
57
+ import TVLabsService from '@tvlabs/wdio-service';
58
+
59
+ const capabilities = { ... };
60
+
61
+ const wdOpts = {
62
+ capabilities,
63
+ hostname: 'appium.tvlabs.ai',
64
+ port: 4723,
65
+ headers: {
66
+ Authorization: `Bearer ${process.env.TVLABS_API_TOKEN}`,
67
+ },
68
+ };
69
+
70
+ const serviceOpts = {
71
+ apiKey: process.env.TVLABS_API_TOKEN,
72
+ }
73
+
74
+ async function run() {
75
+ const service = new TVLabsService(serviceOpts, capabilities, {})
76
+
77
+ // The TV Labs service does not use specs or a cid, pass default values.
78
+ const cid = ""
79
+ const specs = []
80
+
81
+ await service.beforeSession(wdOpts, capabilities, specs, cid)
82
+
83
+ const driver = await remote(wdOpts);
84
+
85
+ try {
86
+ // ...
87
+ } finally {
88
+ await driver.deleteSession();
89
+ }
90
+ }
91
+
92
+ run();
93
+ ```
94
+
95
+ ## Options
96
+
97
+ ### `apiKey`
98
+
99
+ - **Type:** `string`
100
+ - **Required:** Yes
101
+ - **Description:** TV Labs API key used for authentication to the platform
102
+
103
+ ### `retries`
104
+
105
+ - **Type:** `number`
106
+ - **Required:** No
107
+ - **Default:** `3`
108
+ - **Description:** Maximum number of attempts to create a session before failing
109
+
110
+ ### `reconnectRetries`
111
+
112
+ - **Type:** `number`
113
+ - **Required:** No
114
+ - **Default:** `5`
115
+ - **Description:** Maximum number of attempts to re-connect if the connection to TV Labs is lost.
@@ -0,0 +1,25 @@
1
+ import type { TVLabsCapabilities } from './types.js';
2
+ export declare class TVLabsChannel {
3
+ private endpoint;
4
+ private maxReconnectRetries;
5
+ private key;
6
+ private socket;
7
+ private lobbyTopic;
8
+ private requestTopic?;
9
+ private readonly events;
10
+ constructor(endpoint: string, maxReconnectRetries: number, key: string);
11
+ disconnect(): Promise<void>;
12
+ connect(): Promise<void>;
13
+ newSession(capabilities: TVLabsCapabilities, maxRetries: number, retry?: number): Promise<string>;
14
+ private handleRetry;
15
+ private observeRequest;
16
+ private unobserveRequest;
17
+ private requestSession;
18
+ private join;
19
+ private push;
20
+ private params;
21
+ private reconnectAfterMs;
22
+ private logSocketError;
23
+ private tvlabsSessionLink;
24
+ }
25
+ //# sourceMappingURL=channel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,kBAAkB,EAInB,MAAM,YAAY,CAAC;AAKpB,qBAAa,aAAa;IAetB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,mBAAmB;IAC3B,OAAO,CAAC,GAAG;IAhBb,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAU;IAC5B,OAAO,CAAC,YAAY,CAAC,CAAU;IAE/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAOZ;gBAGD,QAAQ,EAAE,MAAM,EAChB,mBAAmB,EAAE,MAAM,EAC3B,GAAG,EAAE,MAAM;IAaf,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ3B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBxB,UAAU,CACd,YAAY,EAAE,kBAAkB,EAChC,UAAU,EAAE,MAAM,EAClB,KAAK,SAAI,GACR,OAAO,CAAC,MAAM,CAAC;YAWJ,WAAW;YAkBX,cAAc;IAkD5B,OAAO,CAAC,gBAAgB;YAUV,cAAc;YAuBd,IAAI;YAgBJ,IAAI;IAoBlB,OAAO,CAAC,MAAM;IAMd,OAAO,CAAC,gBAAgB;IAgBxB,OAAO,CAAC,cAAc;IAWtB,OAAO,CAAC,iBAAiB;CAG1B"}
@@ -0,0 +1,178 @@
1
+ import { Socket } from 'phoenix';
2
+ import WebSocket from 'ws';
3
+ import logger from '@wdio/logger';
4
+ import { SevereServiceError } from 'webdriverio';
5
+ const log = logger('wdio-tvlabs-service');
6
+ export class TVLabsChannel {
7
+ endpoint;
8
+ maxReconnectRetries;
9
+ key;
10
+ socket;
11
+ lobbyTopic;
12
+ requestTopic;
13
+ events = {
14
+ SESSION_READY: 'session:ready',
15
+ SESSION_FAILED: 'session:failed',
16
+ REQUEST_CANCELED: 'request:canceled',
17
+ REQUEST_FAILED: 'request:failed',
18
+ REQUEST_FILLED: 'request:filled',
19
+ REQUEST_MATCHING: 'request:matching',
20
+ };
21
+ constructor(endpoint, maxReconnectRetries, key) {
22
+ this.endpoint = endpoint;
23
+ this.maxReconnectRetries = maxReconnectRetries;
24
+ this.key = key;
25
+ this.socket = new Socket(this.endpoint, {
26
+ transport: WebSocket,
27
+ params: this.params(),
28
+ reconnectAfterMs: this.reconnectAfterMs.bind(this),
29
+ });
30
+ this.socket.onError(this.logSocketError);
31
+ this.lobbyTopic = this.socket.channel('requests:lobby');
32
+ }
33
+ async disconnect() {
34
+ return new Promise((res, _rej) => {
35
+ this.lobbyTopic.leave();
36
+ this.requestTopic?.leave();
37
+ this.socket.disconnect(() => res());
38
+ });
39
+ }
40
+ async connect() {
41
+ try {
42
+ log.debug('Connecting to TV Labs...');
43
+ this.socket.connect();
44
+ await this.join(this.lobbyTopic);
45
+ log.debug('Connected to TV Labs!');
46
+ }
47
+ catch (error) {
48
+ log.error('Error connecting to TV Labs:', error);
49
+ throw new SevereServiceError('Could not connect to TV Labs, please check your connection.');
50
+ }
51
+ }
52
+ async newSession(capabilities, maxRetries, retry = 0) {
53
+ try {
54
+ const requestId = await this.requestSession(capabilities);
55
+ const sessionId = await this.observeRequest(requestId);
56
+ return sessionId;
57
+ }
58
+ catch {
59
+ return this.handleRetry(capabilities, maxRetries, retry);
60
+ }
61
+ }
62
+ async handleRetry(capabilities, maxRetries, retry) {
63
+ if (retry < maxRetries) {
64
+ log.warn(`Could not create a session, retrying (${retry + 1}/${maxRetries})`);
65
+ return this.newSession(capabilities, maxRetries, retry + 1);
66
+ }
67
+ else {
68
+ throw new SevereServiceError(`Could not create a session after ${maxRetries} attempts.`);
69
+ }
70
+ }
71
+ async observeRequest(requestId) {
72
+ const cleanup = () => this.unobserveRequest();
73
+ return new Promise((res, rej) => {
74
+ this.requestTopic = this.socket.channel(`requests:${requestId}`);
75
+ const eventHandlers = {
76
+ [this.events.REQUEST_MATCHING]: ({ request_id }) => {
77
+ log.info(`Session request ${request_id} matching...`);
78
+ },
79
+ [this.events.REQUEST_FILLED]: ({ session_id, request_id }) => {
80
+ log.info(`Session request ${request_id} filled: ${this.tvlabsSessionLink(session_id)}`);
81
+ log.info('Waiting for device to be ready...');
82
+ },
83
+ [this.events.SESSION_FAILED]: ({ session_id, reason }) => {
84
+ log.error(`Session ${session_id} failed, reason: ${reason}`);
85
+ rej(reason);
86
+ },
87
+ [this.events.REQUEST_CANCELED]: ({ request_id, reason }) => {
88
+ log.info(`Session request ${request_id} canceled, reason: ${reason}`);
89
+ rej(reason);
90
+ },
91
+ [this.events.REQUEST_FAILED]: ({ request_id, reason }) => {
92
+ log.info(`Session request ${request_id} failed, reason: ${reason}`);
93
+ rej(reason);
94
+ },
95
+ [this.events.SESSION_READY]: ({ session_id }) => {
96
+ log.info(`Session ${session_id} ready!`);
97
+ res(session_id);
98
+ },
99
+ };
100
+ Object.entries(eventHandlers).forEach(([event, handler]) => {
101
+ this.requestTopic?.on(event, handler);
102
+ });
103
+ this.join(this.requestTopic).catch((err) => {
104
+ rej(err);
105
+ });
106
+ }).finally(cleanup);
107
+ }
108
+ unobserveRequest() {
109
+ Object.values(this.events).forEach((event) => {
110
+ this.requestTopic?.off(event);
111
+ });
112
+ this.requestTopic?.leave();
113
+ this.requestTopic = undefined;
114
+ }
115
+ async requestSession(capabilities) {
116
+ log.info('Requesting TV Labs session');
117
+ try {
118
+ const response = await this.push(this.lobbyTopic, 'requests:create', { capabilities });
119
+ log.info(`Received session request ID: ${response.request_id}. Waiting for a match...`);
120
+ return response.request_id;
121
+ }
122
+ catch (error) {
123
+ log.error('Error requesting session:', error);
124
+ throw error;
125
+ }
126
+ }
127
+ async join(topic) {
128
+ return new Promise((res, rej) => {
129
+ topic
130
+ .join()
131
+ .receive('ok', (_resp) => {
132
+ res();
133
+ })
134
+ .receive('error', ({ response }) => {
135
+ rej('Failed to join topic: ' + response);
136
+ })
137
+ .receive('timeout', () => {
138
+ rej('timeout');
139
+ });
140
+ });
141
+ }
142
+ async push(topic, event, payload) {
143
+ return new Promise((res, rej) => {
144
+ topic
145
+ .push(event, payload)
146
+ .receive('ok', (msg) => {
147
+ res(msg);
148
+ })
149
+ .receive('error', (reason) => {
150
+ rej(reason);
151
+ })
152
+ .receive('timeout', () => {
153
+ rej('timeout');
154
+ });
155
+ });
156
+ }
157
+ params() {
158
+ return {
159
+ api_key: this.key,
160
+ };
161
+ }
162
+ reconnectAfterMs(tries) {
163
+ if (tries > this.maxReconnectRetries) {
164
+ throw new SevereServiceError('Could not connect to TV Labs, please check your connection.');
165
+ }
166
+ const wait = [0, 1000, 3000, 5000][tries] || 10000;
167
+ log.info(`[${tries}/${this.maxReconnectRetries}] Waiting ${wait}ms before re-attempting to connect...`);
168
+ return wait;
169
+ }
170
+ logSocketError(event, _transport, _establishedConnections) {
171
+ const error = event.error;
172
+ const code = error && error.code;
173
+ log.error('Socket error:', code || error || event);
174
+ }
175
+ tvlabsSessionLink(sessionId) {
176
+ return `https://tvlabs.ai/app/sessions/${sessionId}`;
177
+ }
178
+ }
@@ -0,0 +1,4 @@
1
+ import TVLabsService from './service.js';
2
+ export default TVLabsService;
3
+ export * from './types.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,cAAc,CAAC;AAEzC,eAAe,aAAa,CAAC;AAC7B,cAAc,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import TVLabsService from './service.js';
2
+ export default TVLabsService;
3
+ export * from './types.js';
@@ -0,0 +1,15 @@
1
+ import type { Services, Capabilities, Options } from '@wdio/types';
2
+ import type { TVLabsCapabilities, TVLabsServiceOptions } from './types.js';
3
+ export default class TVLabsService implements Services.ServiceInstance {
4
+ private _options;
5
+ private _capabilities;
6
+ private _config;
7
+ constructor(_options: TVLabsServiceOptions, _capabilities: Capabilities.ResolvedTestrunnerCapabilities, _config: Options.WebdriverIO);
8
+ onPrepare(_config: Options.Testrunner, param: Capabilities.TestrunnerCapabilities): void;
9
+ beforeSession(_config: Omit<Options.Testrunner, 'capabilities'>, capabilities: TVLabsCapabilities, _specs: string[], _cid: string): Promise<void>;
10
+ private endpoint;
11
+ private retries;
12
+ private apiKey;
13
+ private reconnectRetries;
14
+ }
15
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAE3E,MAAM,CAAC,OAAO,OAAO,aAAc,YAAW,QAAQ,CAAC,eAAe;IAElE,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,OAAO;gBAFP,QAAQ,EAAE,oBAAoB,EAC9B,aAAa,EAAE,YAAY,CAAC,8BAA8B,EAC1D,OAAO,EAAE,OAAO,CAAC,WAAW;IAGtC,SAAS,CACP,OAAO,EAAE,OAAO,CAAC,UAAU,EAC3B,KAAK,EAAE,YAAY,CAAC,sBAAsB;IAStC,aAAa,CACjB,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,cAAc,CAAC,EACjD,YAAY,EAAE,kBAAkB,EAChC,MAAM,EAAE,MAAM,EAAE,EAChB,IAAI,EAAE,MAAM;IAkBd,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,MAAM;IAId,OAAO,CAAC,gBAAgB;CAGzB"}
@@ -0,0 +1,35 @@
1
+ import { SevereServiceError } from 'webdriverio';
2
+ import { TVLabsChannel } from './channel.js';
3
+ export default class TVLabsService {
4
+ _options;
5
+ _capabilities;
6
+ _config;
7
+ constructor(_options, _capabilities, _config) {
8
+ this._options = _options;
9
+ this._capabilities = _capabilities;
10
+ this._config = _config;
11
+ }
12
+ onPrepare(_config, param) {
13
+ if (!Array.isArray(param)) {
14
+ throw new SevereServiceError('Multi-remote capabilities are not implemented. Contact TV Labs support if you are interested in this feature.');
15
+ }
16
+ }
17
+ async beforeSession(_config, capabilities, _specs, _cid) {
18
+ const channel = new TVLabsChannel(this.endpoint(), this.reconnectRetries(), this.apiKey());
19
+ await channel.connect();
20
+ capabilities['tvlabs:session_id'] = await channel.newSession(capabilities, this.retries());
21
+ await channel.disconnect();
22
+ }
23
+ endpoint() {
24
+ return this._options.endpoint || 'wss://tvlabs.ai/appium';
25
+ }
26
+ retries() {
27
+ return this._options.retries || 3;
28
+ }
29
+ apiKey() {
30
+ return this._options.apiKey;
31
+ }
32
+ reconnectRetries() {
33
+ return this._options.reconnectRetries || 5;
34
+ }
35
+ }
@@ -0,0 +1,35 @@
1
+ import type { Capabilities } from '@wdio/types';
2
+ export type TVLabsServiceOptions = {
3
+ apiKey: string;
4
+ endpoint?: string;
5
+ retries?: number;
6
+ reconnectRetries?: number;
7
+ };
8
+ export type TVLabsCapabilities = Capabilities.RequestedStandaloneCapabilities & {
9
+ 'tvlabs:session_id'?: string;
10
+ 'tvlabs:build'?: string;
11
+ 'tvlabs:constraints'?: {
12
+ platform_key?: string;
13
+ device_type?: string;
14
+ make?: string;
15
+ model?: string;
16
+ year?: string;
17
+ minimum_chromedriver_major_version?: number;
18
+ supports_chromedriver?: boolean;
19
+ };
20
+ 'tvlabs:match_timeout'?: number;
21
+ 'tvlabs:device_timeout'?: number;
22
+ };
23
+ export type TVLabsSessionRequestEventHandler = (response: TVLabsSessionRequestUpdate) => void;
24
+ export type TVLabsSessionRequestUpdate = {
25
+ request_id: string;
26
+ session_id: string;
27
+ reason: string;
28
+ };
29
+ export type TVLabsSessionRequestResponse = {
30
+ request_id: string;
31
+ };
32
+ export type TVLabsSessionChannelParams = {
33
+ api_key: string;
34
+ };
35
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAC5B,YAAY,CAAC,+BAA+B,GAAG;IAC7C,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE;QACrB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,kCAAkC,CAAC,EAAE,MAAM,CAAC;QAC5C,qBAAqB,CAAC,EAAE,OAAO,CAAC;KACjC,CAAC;IACF,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC,CAAC;AAEJ,MAAM,MAAM,gCAAgC,GAAG,CAC7C,QAAQ,EAAE,0BAA0B,KACjC,IAAI,CAAC;AAEV,MAAM,MAAM,0BAA0B,GAAG;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@tvlabs/wdio-service",
3
+ "version": "0.1.0",
4
+ "description": "WebdriverIO service that provides a better integration into TV Labs",
5
+ "author": "Regan Karlewicz <regan@tvlabs.ai>",
6
+ "license": "Apache-2.0",
7
+ "engines": {
8
+ "node": ">=18.20.0"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/tv-labs/wdio-tvlabs-service.git"
13
+ },
14
+ "keywords": [
15
+ "wdio-plugin",
16
+ "wdio-service",
17
+ "tvlabs",
18
+ "tv-labs",
19
+ "appium"
20
+ ],
21
+ "bugs": {
22
+ "url": "https://github.com/tv-labs/wdio-tvlabs-service/issues"
23
+ },
24
+ "scripts": {
25
+ "build": "tsc -p src",
26
+ "start": "ts-node src/index.ts",
27
+ "dev": "ts-node --transpile-only src/index.ts",
28
+ "clean": "rm -rf dist",
29
+ "format": "prettier --write .",
30
+ "format:check": "prettier --check .",
31
+ "lint": "eslint",
32
+ "test": "vitest --config vitest.config.ts --coverage"
33
+ },
34
+ "type": "module",
35
+ "types": "./dist/index.d.ts",
36
+ "exports": {
37
+ ".": {
38
+ "types": "./dist/index.d.ts",
39
+ "import": "./dist/index.js"
40
+ }
41
+ },
42
+ "typeScriptVersion": "5.8.2",
43
+ "devDependencies": {
44
+ "@eslint/js": "^9.22.0",
45
+ "@types/node": "^22.13.10",
46
+ "@types/phoenix": "^1.6.6",
47
+ "@types/ws": "^8.18.0",
48
+ "@typescript-eslint/eslint-plugin": "^8.27.0",
49
+ "@typescript-eslint/parser": "^8.27.0",
50
+ "@vitest/coverage-v8": "^3.0.9",
51
+ "@wdio/globals": "^9.12.1",
52
+ "@wdio/logger": "^9.4.4",
53
+ "@wdio/types": "^9.10.1",
54
+ "eslint": "^9.22.0",
55
+ "globals": "^16.0.0",
56
+ "jiti": "^2.4.2",
57
+ "prettier": "^3.5.3",
58
+ "typescript": "^5.8.2",
59
+ "typescript-eslint": "^8.27.0",
60
+ "vitest": "^3.0.9",
61
+ "webdriverio": "^9.12.1"
62
+ },
63
+ "dependencies": {
64
+ "phoenix": "^1.7.20",
65
+ "ws": "^8.18.1"
66
+ }
67
+ }