@samsara-dev/appwright 0.2.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.
Files changed (81) hide show
  1. package/.eslintrc.js +4 -0
  2. package/CHANGELOG.md +538 -0
  3. package/LICENSE +202 -0
  4. package/README.md +183 -0
  5. package/dist/bin/index.d.ts +3 -0
  6. package/dist/bin/index.d.ts.map +1 -0
  7. package/dist/bin/index.js +53 -0
  8. package/dist/config.d.ts +4 -0
  9. package/dist/config.d.ts.map +1 -0
  10. package/dist/config.js +65 -0
  11. package/dist/device/index.d.ts +171 -0
  12. package/dist/device/index.d.ts.map +1 -0
  13. package/dist/device/index.js +415 -0
  14. package/dist/fixture/index.d.ts +38 -0
  15. package/dist/fixture/index.d.ts.map +1 -0
  16. package/dist/fixture/index.js +78 -0
  17. package/dist/fixture/workerInfo.d.ts +27 -0
  18. package/dist/fixture/workerInfo.d.ts.map +1 -0
  19. package/dist/fixture/workerInfo.js +87 -0
  20. package/dist/global-setup.d.ts +5 -0
  21. package/dist/global-setup.d.ts.map +1 -0
  22. package/dist/global-setup.js +30 -0
  23. package/dist/index.d.ts +5 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +25 -0
  26. package/dist/locator/index.d.ts +25 -0
  27. package/dist/locator/index.d.ts.map +1 -0
  28. package/dist/locator/index.js +296 -0
  29. package/dist/logger.d.ts +9 -0
  30. package/dist/logger.d.ts.map +1 -0
  31. package/dist/logger.js +19 -0
  32. package/dist/providers/appium.d.ts +15 -0
  33. package/dist/providers/appium.d.ts.map +1 -0
  34. package/dist/providers/appium.js +274 -0
  35. package/dist/providers/browserstack/index.d.ts +26 -0
  36. package/dist/providers/browserstack/index.d.ts.map +1 -0
  37. package/dist/providers/browserstack/index.js +272 -0
  38. package/dist/providers/browserstack/utils.d.ts +2 -0
  39. package/dist/providers/browserstack/utils.d.ts.map +1 -0
  40. package/dist/providers/browserstack/utils.js +34 -0
  41. package/dist/providers/emulator/index.d.ts +13 -0
  42. package/dist/providers/emulator/index.d.ts.map +1 -0
  43. package/dist/providers/emulator/index.js +86 -0
  44. package/dist/providers/index.d.ts +5 -0
  45. package/dist/providers/index.d.ts.map +1 -0
  46. package/dist/providers/index.js +31 -0
  47. package/dist/providers/lambdatest/index.d.ts +27 -0
  48. package/dist/providers/lambdatest/index.d.ts.map +1 -0
  49. package/dist/providers/lambdatest/index.js +280 -0
  50. package/dist/providers/lambdatest/utils.d.ts +3 -0
  51. package/dist/providers/lambdatest/utils.d.ts.map +1 -0
  52. package/dist/providers/lambdatest/utils.js +36 -0
  53. package/dist/providers/local/index.d.ts +13 -0
  54. package/dist/providers/local/index.d.ts.map +1 -0
  55. package/dist/providers/local/index.js +86 -0
  56. package/dist/reporter.d.ts +13 -0
  57. package/dist/reporter.d.ts.map +1 -0
  58. package/dist/reporter.js +216 -0
  59. package/dist/tests/locator.spec.d.ts +2 -0
  60. package/dist/tests/locator.spec.d.ts.map +1 -0
  61. package/dist/tests/locator.spec.js +89 -0
  62. package/dist/tests/regex.spec.d.ts +2 -0
  63. package/dist/tests/regex.spec.d.ts.map +1 -0
  64. package/dist/tests/regex.spec.js +19 -0
  65. package/dist/tests/vitest.config.d.mts +3 -0
  66. package/dist/tests/vitest.config.d.mts.map +1 -0
  67. package/dist/tests/vitest.config.mjs +6 -0
  68. package/dist/types/errors.d.ts +7 -0
  69. package/dist/types/errors.d.ts.map +1 -0
  70. package/dist/types/errors.js +15 -0
  71. package/dist/types/index.d.ts +234 -0
  72. package/dist/types/index.d.ts.map +1 -0
  73. package/dist/types/index.js +22 -0
  74. package/dist/utils.d.ts +8 -0
  75. package/dist/utils.d.ts.map +1 -0
  76. package/dist/utils.js +66 -0
  77. package/dist/vision/index.d.ts +64 -0
  78. package/dist/vision/index.d.ts.map +1 -0
  79. package/dist/vision/index.js +106 -0
  80. package/package.json +63 -0
  81. package/tsconfig.json +15 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2024 Forge AI Private Limited
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,183 @@
1
+ # Appwright
2
+
3
+ ![NPM Version](https://img.shields.io/npm/v/@samsara-dev/appwright?color=4AC61C)
4
+
5
+ Appwright is a test framework for e2e testing of mobile apps. Appwright builds on top of [Appium](https://appium.io/docs/en/latest/), and can
6
+ run tests on local devices, emulators, and remote device farms — for both iOS and Android.
7
+
8
+ Appwright is one integrated package that combines an automation driver, test runner and test
9
+ reporter. To achieve this, Appwright uses the [Playwright](https://github.com/microsoft/playwright) test runner internally, which is
10
+ purpose-built for the e2e testing workflow.
11
+
12
+ Appwright exposes an ergonomic API to automate user actions. These actions auto-wait and auto-retry
13
+ for UI elements to be ready and interactable, which makes your tests easier to read and maintain.
14
+
15
+ ```ts
16
+ import { test, expect } from "@samsara-dev/appwright";
17
+
18
+ test("User can login", async ({ device }) => {
19
+ await device.getByText("Username").fill("admin");
20
+ await device.getByText("Password").fill("password");
21
+ await device.getByText("Login").tap();
22
+ });
23
+ ```
24
+
25
+ Links to help you get started.
26
+
27
+ - [Example project](https://github.com/empirical-run/appwright/tree/main/example)
28
+ - [Launch blog post](https://www.empirical.run/blog/appwright)
29
+ - [Documentation](#docs)
30
+
31
+ ## Usage
32
+
33
+ ### Minimum requirements
34
+
35
+ - Node 20.19.0 or higher (Appium 3 requirement)
36
+
37
+ ### Install
38
+
39
+ ```sh
40
+ npm i --save-dev @samsara-dev/appwright
41
+ touch appwright.config.ts
42
+ ```
43
+
44
+ ### Configure
45
+
46
+ ```ts
47
+ // In appwright.config.ts
48
+ import { defineConfig, Platform } from "@samsara-dev/appwright";
49
+ export default defineConfig({
50
+ projects: [
51
+ {
52
+ name: "android",
53
+ use: {
54
+ platform: Platform.ANDROID,
55
+ device: {
56
+ provider: "emulator", // or 'local-device' or 'browserstack'
57
+ },
58
+ buildPath: "app-release.apk",
59
+ },
60
+ },
61
+ {
62
+ name: "ios",
63
+ use: {
64
+ platform: Platform.IOS,
65
+ device: {
66
+ provider: "emulator", // or 'local-device' or 'browserstack'
67
+ },
68
+ buildPath: "app-release.app", // Path to your .app file
69
+ },
70
+ },
71
+ ],
72
+ });
73
+ ```
74
+
75
+ ### Configuration Options
76
+
77
+ - `platform`: The platform you want to test on, such as 'android' or 'ios'.
78
+
79
+ - `provider`: The device provider where you want to run your tests.
80
+ You can choose between `browserstack`, `lambdatest`, `emulator`, or `local-device`.
81
+
82
+ - `buildPath`: The path to your build file. For Android, it should be an APK file.
83
+ For iOS, if you are running tests on real device, it should be an `.ipa` file. For running tests on an emulator, it should be a `.app` file.
84
+
85
+ ### Run tests
86
+
87
+ To run tests, you need to specify the project name with `--project` flag.
88
+
89
+ ```sh
90
+ npx appwright test --project android
91
+ npx appwright test --project ios
92
+ ```
93
+
94
+ #### Run tests on BrowserStack
95
+
96
+ Appwright supports BrowserStack out of the box. To run tests on BrowserStack, configure
97
+ the provider in your config.
98
+
99
+ ```ts
100
+ {
101
+ name: "android",
102
+ use: {
103
+ platform: Platform.ANDROID,
104
+ device: {
105
+ provider: "browserstack",
106
+ // Specify device to run the tests on
107
+ // See supported devices: https://www.browserstack.com/list-of-browsers-and-platforms/app_automate
108
+ name: "Google Pixel 8",
109
+ osVersion: "14.0",
110
+ appiumVersion: "3.1.0", // Override if your BrowserStack account does not yet support Appium 3
111
+ },
112
+ buildPath: "app-release.apk",
113
+ },
114
+ },
115
+ ```
116
+
117
+ #### Run tests on LambdaTest
118
+
119
+ Appwright supports LambdaTest out of the box. To run tests on LambdaTest, configure
120
+ the provider in your config.
121
+
122
+ ```ts
123
+ {
124
+ name: "android",
125
+ use: {
126
+ platform: Platform.ANDROID,
127
+ device: {
128
+ provider: "lambdatest",
129
+ // Specify device to run the tests on
130
+ // See supported devices: https://www.lambdatest.com/list-of-real-devices
131
+ name: "Pixel 8",
132
+ osVersion: "14",
133
+ appiumVersion: "3.1.0", // Override if your LambdaTest account does not yet support Appium 3
134
+ },
135
+ buildPath: "app-release.apk",
136
+ },
137
+ },
138
+ ```
139
+
140
+ ## Run the sample project
141
+
142
+ To run the sample project:
143
+
144
+ - Navigate to the `example` directory.
145
+
146
+ ```sh
147
+ cd example
148
+ ```
149
+
150
+ - Install dependencies.
151
+
152
+ ```sh
153
+ npm install
154
+ ```
155
+
156
+ - Run the tests
157
+
158
+ Run the following command to execute tests on an Android emulator:
159
+
160
+ ```sh
161
+ npx appwright test --project android
162
+ ```
163
+
164
+ To run the tests on iOS simulator:
165
+
166
+ - Unzip the `wikipedia.zip` file
167
+
168
+ ```sh
169
+ npm run extract:app
170
+ ```
171
+ - Run the following command:
172
+
173
+ ```sh
174
+ npx appwright test --project ios
175
+ ```
176
+
177
+ ## Docs
178
+
179
+ - [Basics](docs/basics.md)
180
+ - [Configuration](docs/config.md)
181
+ - [Locators](docs/locators.md)
182
+ - [Assertions](docs/assertions.md)
183
+ - [API reference](docs/api-reference.md)
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bin/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const child_process_1 = require("child_process");
5
+ const logger_1 = require("../logger");
6
+ function cmd(command, options) {
7
+ let errorLogs = [];
8
+ return new Promise((resolveFunc, rejectFunc) => {
9
+ let p = (0, child_process_1.spawn)(command[0], command.slice(1), {
10
+ env: { ...process.env, ...options.env },
11
+ });
12
+ p.stdout.on("data", (x) => {
13
+ const log = x.toString();
14
+ if (log.includes("Error")) {
15
+ errorLogs.push(log);
16
+ }
17
+ process.stdout.write(log);
18
+ });
19
+ p.stderr.on("data", (x) => {
20
+ const log = x.toString();
21
+ process.stderr.write(x.toString());
22
+ errorLogs.push(log);
23
+ });
24
+ p.on("exit", (code) => {
25
+ if (code != 0) {
26
+ // assuming last log is the error message before exiting
27
+ rejectFunc(errorLogs.slice(-3).join("\n"));
28
+ }
29
+ else {
30
+ resolveFunc(code);
31
+ }
32
+ });
33
+ });
34
+ }
35
+ async function runPlaywrightCmd(args) {
36
+ const pwRunCmd = `npx playwright ${args}`;
37
+ return cmd(pwRunCmd.split(" "), {});
38
+ }
39
+ (async function main() {
40
+ const defaultConfigFile = `appwright.config.ts`;
41
+ const pwOptions = process.argv.slice(2);
42
+ if (!pwOptions.includes("--config")) {
43
+ pwOptions.push(`--config`);
44
+ pwOptions.push(defaultConfigFile);
45
+ }
46
+ try {
47
+ await runPlaywrightCmd(pwOptions.join(" "));
48
+ }
49
+ catch (error) {
50
+ logger_1.logger.error(`Error while running playwright test: ${error}`);
51
+ process.exit(1);
52
+ }
53
+ })();
@@ -0,0 +1,4 @@
1
+ import { PlaywrightTestConfig } from "@playwright/test";
2
+ import { AppwrightConfig } from "./types";
3
+ export declare function defineConfig(config: PlaywrightTestConfig<AppwrightConfig>): PlaywrightTestConfig<AppwrightConfig, {}>;
4
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,oBAAoB,EAErB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAsC1C,wBAAgB,YAAY,CAAC,MAAM,EAAE,oBAAoB,CAAC,eAAe,CAAC,6CAyBzE"}
package/dist/config.js ADDED
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.defineConfig = defineConfig;
7
+ const test_1 = require("@playwright/test");
8
+ const path_1 = __importDefault(require("path"));
9
+ const logger_1 = require("./logger");
10
+ const resolveGlobalSetup = () => {
11
+ const pathToInstalledAppwright = require.resolve(".");
12
+ const directory = path_1.default.dirname(pathToInstalledAppwright);
13
+ return path_1.default.join(directory, "global-setup.js");
14
+ };
15
+ const resolveVideoReporter = () => {
16
+ const pathToInstalledAppwright = require.resolve(".");
17
+ const directory = path_1.default.dirname(pathToInstalledAppwright);
18
+ return path_1.default.join(directory, "reporter.js");
19
+ };
20
+ const defaultConfig = {
21
+ globalSetup: resolveGlobalSetup(),
22
+ testDir: "./tests",
23
+ // This is turned off so that a persistent device fixture can be
24
+ // used across tests in a file where they run sequentially
25
+ fullyParallel: false,
26
+ forbidOnly: false,
27
+ retries: process.env.CI ? 2 : 0,
28
+ workers: 2,
29
+ reporter: [["list"], ["html", { open: "always" }]],
30
+ use: {
31
+ // TODO: Use this for actions
32
+ actionTimeout: 20_000,
33
+ expectTimeout: 20_000,
34
+ },
35
+ expect: {
36
+ // This is not used right now
37
+ timeout: 20_000,
38
+ },
39
+ timeout: 0,
40
+ };
41
+ function defineConfig(config) {
42
+ const hasGlobalSetup = config.globalSetup !== undefined;
43
+ if (hasGlobalSetup) {
44
+ logger_1.logger.warn("The `globalSetup` parameter in config will be ignored. See https://github.com/empirical-run/appwright/issues/57");
45
+ delete config.globalSetup;
46
+ }
47
+ let reporterConfig;
48
+ if (config.reporter) {
49
+ reporterConfig = config.reporter;
50
+ }
51
+ else {
52
+ reporterConfig = [["list"], ["html", { open: "always" }]];
53
+ }
54
+ return (0, test_1.defineConfig)({
55
+ ...defaultConfig,
56
+ ...config,
57
+ reporter: [[resolveVideoReporter()], ...reporterConfig],
58
+ use: {
59
+ ...defaultConfig.use,
60
+ expectTimeout: config.use?.expectTimeout
61
+ ? config.use.expectTimeout
62
+ : defaultConfig.use?.expectTimeout,
63
+ },
64
+ });
65
+ }
@@ -0,0 +1,171 @@
1
+ import type { Client as WebDriverClient } from "webdriver";
2
+ import { AppwrightLocator, ExtractType, Platform, TimeoutOptions } from "../types";
3
+ import { z } from "zod";
4
+ import { LLMModel } from "@empiricalrun/llm";
5
+ export declare class Device {
6
+ private webDriverClient;
7
+ private bundleId;
8
+ private timeoutOpts;
9
+ private provider;
10
+ constructor(webDriverClient: WebDriverClient, bundleId: string | undefined, timeoutOpts: TimeoutOptions, provider: string);
11
+ locator({ selector, findStrategy, textToMatch, }: {
12
+ selector: string;
13
+ findStrategy: string;
14
+ textToMatch?: string | RegExp;
15
+ }): AppwrightLocator;
16
+ private vision;
17
+ beta: {
18
+ tap: (prompt: string, options?: {
19
+ useCache?: boolean;
20
+ telemetry?: {
21
+ tags?: string[];
22
+ };
23
+ }) => Promise<{
24
+ x: number;
25
+ y: number;
26
+ }>;
27
+ query: <T extends z.ZodType>(prompt: string, options?: {
28
+ responseFormat?: T;
29
+ model?: LLMModel;
30
+ screenshot?: string;
31
+ telemetry?: {
32
+ tags?: string[];
33
+ };
34
+ }) => Promise<ExtractType<T>>;
35
+ };
36
+ /**
37
+ * Closes the automation session. This is called automatically after each test.
38
+ *
39
+ * **Usage:**
40
+ * ```js
41
+ * await device.close();
42
+ * ```
43
+ */
44
+ close(): Promise<void>;
45
+ /**
46
+ * Tap on the screen at the given coordinates, specified as x and y. The top left corner
47
+ * of the screen is { x: 0, y: 0 }.
48
+ *
49
+ * **Usage:**
50
+ * ```js
51
+ * await device.tap({ x: 100, y: 100 });
52
+ * ```
53
+ *
54
+ * @param coordinates to tap on
55
+ * @returns
56
+ */
57
+ tap({ x, y }: {
58
+ x: number;
59
+ y: number;
60
+ }): Promise<void>;
61
+ /**
62
+ * Locate an element on the screen with text content. This method defaults to a
63
+ * substring match, and this be overridden by setting the `exact` option to `true`.
64
+ *
65
+ * **Usage:**
66
+ * ```js
67
+ * // with string
68
+ * const submitButton = device.getByText("Submit");
69
+ *
70
+ * // with RegExp
71
+ * const counter = device.getByText(/^Counter: \d+/);
72
+ * ```
73
+ *
74
+ * @param text string or regular expression to search for
75
+ * @param options
76
+ * @returns
77
+ */
78
+ getByText(text: string | RegExp, { exact }?: {
79
+ exact?: boolean;
80
+ }): AppwrightLocator;
81
+ /**
82
+ * Locate an element on the screen with accessibility identifier. This method defaults to
83
+ * a substring match, and this can be overridden by setting the `exact` option to `true`.
84
+ *
85
+ * **Usage:**
86
+ * ```js
87
+ * const element = await device.getById("signup_button");
88
+ * ```
89
+ *
90
+ * @param text string to search for
91
+ * @param options
92
+ * @returns
93
+ */
94
+ getById(text: string, { exact }?: {
95
+ exact?: boolean;
96
+ }): AppwrightLocator;
97
+ /**
98
+ * Locate an element on the screen with xpath.
99
+ *
100
+ * **Usage:**
101
+ * ```js
102
+ * const element = await device.getByXpath(`//android.widget.Button[@text="Confirm"]`);
103
+ * ```
104
+ *
105
+ * @param xpath xpath to locate the element
106
+ * @returns
107
+ */
108
+ getByXpath(xpath: string): AppwrightLocator;
109
+ /**
110
+ * Helper method to detect the mobile OS running on the device.
111
+ *
112
+ * **Usage:**
113
+ * ```js
114
+ * const platform = device.getPlatform();
115
+ * ```
116
+ *
117
+ * @returns "android" or "ios"
118
+ */
119
+ getPlatform(): Platform;
120
+ terminateApp(bundleId?: string): Promise<void>;
121
+ activateApp(bundleId?: string): Promise<void>;
122
+ /**
123
+ * Retrieves text content from the clipboard of the mobile device. This is useful
124
+ * after a "copy to clipboard" action has been performed. This returns base64 encoded string.
125
+ *
126
+ * **Usage:**
127
+ * ```js
128
+ * const clipboardText = await device.getClipboardText();
129
+ * ```
130
+ *
131
+ * @returns Returns the text content of the clipboard in base64 encoded string.
132
+ */
133
+ getClipboardText(): Promise<string>;
134
+ /**
135
+ * Sets a mock camera view using the specified image. This injects a mock image into the camera view.
136
+ * Currently, this functionality is supported only for BrowserStack.
137
+ *
138
+ * **Usage:**
139
+ * ```js
140
+ * await device.setMockCameraView(`screenshot.png`);
141
+ * ```
142
+ *
143
+ * @param imagePath path to the image file that will be used as the mock camera view.
144
+ * @returns
145
+ */
146
+ setMockCameraView(imagePath: string): Promise<void>;
147
+ pause(): Promise<void>;
148
+ waitForTimeout(timeout: number): Promise<void>;
149
+ /**
150
+ * Get a screenshot of the current screen as a base64 encoded string.
151
+ */
152
+ screenshot(): Promise<string>;
153
+ /**
154
+ * [iOS Only]
155
+ * Scroll the screen from 0.2 to 0.8 of the screen height.
156
+ * This can be used for controlled scroll, for auto scroll checkout `scroll` method from locator.
157
+ *
158
+ * **Usage:**
159
+ * ```js
160
+ * await device.scroll();
161
+ * ```
162
+ *
163
+ */
164
+ scroll(): Promise<void>;
165
+ /**
166
+ * Send keys to already focused input field.
167
+ * To fill input fields using the selectors use `sendKeyStrokes` method from locator
168
+ */
169
+ sendKeyStrokes(value: string): Promise<void>;
170
+ }
171
+ //# sourceMappingURL=index.d.ts.map