@suffolklitlab/alkiln 4.10.3 → 4.10.4
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/.github/CODEOWNERS +1 -0
- package/CHANGELOG.md +5 -0
- package/CONTRIBUTING.md +205 -0
- package/LICENSE +21 -0
- package/README.md +51 -11
- package/lib/scope.js +50 -75
- package/lib/steps.js +9 -16
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* @plocket @BryceStevenWilley
|
package/CHANGELOG.md
CHANGED
|
@@ -40,7 +40,12 @@ Format:
|
|
|
40
40
|
-->
|
|
41
41
|
<!-- ## [Unreleased] -->
|
|
42
42
|
|
|
43
|
+
## [4.10.4] - 2023-02-15
|
|
44
|
+
### Added
|
|
45
|
+
- Contribution docs
|
|
43
46
|
|
|
47
|
+
### Fixed
|
|
48
|
+
- #511, couldn't take screenshots of signature pages https://github.com/SuffolkLITLab/ALKiln/issues/511
|
|
44
49
|
|
|
45
50
|
## [4.10.3] - 2023-01-11
|
|
46
51
|
### Removed
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
For documentation changes, you can just edit and make a pull request. Ignore the instructions below.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
If you are not already in contact with us, you can join the #assembly-line-test channel in the [docassemble Slack](https://docassemble.org/docs/support.html#tocAnchor-1-1) or [make a new issue](https://github.com/SuffolkLITLab/ALKiln/issues/new) and mention @niharikasingh to let us know you're interested.
|
|
8
|
+
|
|
9
|
+
1. Asking to join as a contributor is simplest. You can fork, but you will have to change lines in your `.env` file and may have to set GitHub secrets in your repository. You have to talk to us either way.
|
|
10
|
+
1. Clone the repository locally: `git clone git@github.com:SuffolkLITLab/ALKiln.git`
|
|
11
|
+
1. Run `npm install`
|
|
12
|
+
1. Create [your `.env` file](#env) at the root of the project.
|
|
13
|
+
1. Contact @niharikasingh to get important information for your `.env` file.
|
|
14
|
+
1. Run `npm run setup`
|
|
15
|
+
|
|
16
|
+
Advanced contributors: If you're going to work on our docassemble internal testing interviews, do so as a contributor on this repository. Avoid forking if you can. The reasons are complex. If you feel a need to fork, reach out to us.
|
|
17
|
+
|
|
18
|
+
## PRs
|
|
19
|
+
|
|
20
|
+
Before making a pull request
|
|
21
|
+
|
|
22
|
+
1. Search issues to see if what you are thinking of has been discussed yet.
|
|
23
|
+
1. Make an issue about the change you are thinking of.
|
|
24
|
+
1. Assign yourself to an issue.
|
|
25
|
+
1. Make a new branch.
|
|
26
|
+
1. Make your edits. Feel free to [run tests](#running-internal-tests) as you go.
|
|
27
|
+
1. When you're ready to push
|
|
28
|
+
1. Run `npm run test` to make sure your code passes all our tests.
|
|
29
|
+
1. Make an entry in the `CHANGELOG.md` describing your change.
|
|
30
|
+
1. AVOID changing the version number. We'll do that after merging your changes.
|
|
31
|
+
1. If needed, update the `README.md` (e.g. the cheat sheet section) and/or `CONTRIBUTING.md` docs. Changes to our architecture might require editing `CONTRIBUTING.md`.
|
|
32
|
+
1. Push to GitHub.
|
|
33
|
+
1. Wait for the GitHub tests to pass. You may have to re-run failing tests—server restarts or race conditions may interfere with them. We have reduced them greatly, but some are impossible to avoid.
|
|
34
|
+
1. Make your pull request. Work in progress pull requests are great too. A pull request must be reviewed before it can be merged.
|
|
35
|
+
|
|
36
|
+
## .env
|
|
37
|
+
|
|
38
|
+
You need to make your own `.env` file. It contains sensitive variables, like passwords. We use them for our internal tests. The file should look something like the below:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# For everyone
|
|
42
|
+
|
|
43
|
+
DOCASSEMBLE_DEVELOPER_API_KEY=<ask @niharikasingh>
|
|
44
|
+
SERVER_URL=https://apps-dev.suffolklitlab.org
|
|
45
|
+
REPO_URL=https://github.com/SuffolkLITLab/alkiln
|
|
46
|
+
SERVER_RELOAD_TIMEOUT_SECONDS=
|
|
47
|
+
MAX_SECONDS_FOR_SETUP=
|
|
48
|
+
|
|
49
|
+
# For internal tests
|
|
50
|
+
|
|
51
|
+
# Set DEBUG to 1 to run in non-headless mode and see the test run live
|
|
52
|
+
DEBUG=
|
|
53
|
+
# If you edit interview files (.yml files), you should push to a new
|
|
54
|
+
# branch and update BRANCH_PATH to that branch name
|
|
55
|
+
BRANCH_PATH=v4
|
|
56
|
+
USER1_EMAIL=<ask @niharikasingh>
|
|
57
|
+
USER1_PASSWORD=<ask @niharikasingh>
|
|
58
|
+
SECRET_VAR1=secret-var1-value
|
|
59
|
+
SECRET_VAR2=secret-var2-value
|
|
60
|
+
SECRET_FOR_MISSING_FIELD=secret for missing field
|
|
61
|
+
SECRET_INVALID_THERE_IS_ANOTHER=invalid value for there_is_another
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Running internal tests
|
|
65
|
+
|
|
66
|
+
Only run this the first time you run tests in this repository to make the code available to test on the docassemble server:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
npm run setup
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
If you run `takedown`, you will then have to run `setup` again.
|
|
73
|
+
|
|
74
|
+
Use the syntax below to trigger all tests (cucumber and unit tests):
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npm run test
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Run only cucumber tests:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
npm run cucumber
|
|
84
|
+
|
|
85
|
+
# To test Features or Scenarios specific tags:
|
|
86
|
+
npm run cucumber -- "--tags" "@tagname"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
To run the unit tests in isolation:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
npm run unit
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
If you or someone else changes the interview code in `./docassemble`, you have to clean up the old data on the server before running `setup` again:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
npm run takedown
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## How the tests run
|
|
102
|
+
|
|
103
|
+
Our tests require the user/developer to have a docassemble server on which they host these interviews (online forms) and at least one developer account. With our help, our users set up the tests to run when they commit new code or to run manually. When GitHub runs the tests, it does the following:
|
|
104
|
+
|
|
105
|
+
1. Sets up on the docassemble server. In a given developer account:
|
|
106
|
+
1. Creates a new interview for this particular branch of the repository.
|
|
107
|
+
1. Pulls in the code from that branch into the docassemble server.
|
|
108
|
+
1. Runs the tests
|
|
109
|
+
1. Pretends to be an anonymous account that comes to the form and inputs answers.
|
|
110
|
+
1. Writes up reports and possibly takes screenshots to show to the developer.
|
|
111
|
+
1. Cleans up by deleting the interview it created
|
|
112
|
+
|
|
113
|
+
When the developer commits code to GitHub, their account triggers our code, passing along variables that our code needs, like their GitHub secret of the API key for their docassemble server developer account.
|
|
114
|
+
|
|
115
|
+
## Very general architecture of files and folders
|
|
116
|
+
|
|
117
|
+
An honest look at our current project architecture—some of our files and folders, what they do, and how they interact.
|
|
118
|
+
|
|
119
|
+
### Logic architecture
|
|
120
|
+
|
|
121
|
+
ALKiln uses [cucumber](https://cucumber.io/docs/installation/javascript/)[^1] with [Gherkin](https://cucumber.io/docs/gherkin/reference/) syntax, [puppeteer](https://pptr.dev/), and [chai](https://www.chaijs.com/).
|
|
122
|
+
|
|
123
|
+
#### .feature files
|
|
124
|
+
|
|
125
|
+
The `.feature` files are written in Gherkin, a syntax cucumber uses. The "code" in there relies on the functions set up in `./lib/steps.js`.
|
|
126
|
+
|
|
127
|
+
```js
|
|
128
|
+
// The test_something.feature file step
|
|
129
|
+
Then I sign
|
|
130
|
+
|
|
131
|
+
// relies on the code in steps.js
|
|
132
|
+
Then('I sign', { timeout: -1 }, async () => {
|
|
133
|
+
return wrapPromiseWithTimeout(
|
|
134
|
+
scope.steps.sign( scope ),
|
|
135
|
+
scope.timeout
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
#### steps.js
|
|
141
|
+
|
|
142
|
+
`./lib/steps.js` defines all the Gherkin sentences that our users (the developers) can write. See [cucumber documentation on defining steps](https://cucumber.io/docs/cucumber/step-definitions/?lang=javascript). We sometimes use "cucumber expressions" and, but often use regular expressions as we often want to be more flexible about the user's input.
|
|
143
|
+
|
|
144
|
+
The file handles things like:
|
|
145
|
+
|
|
146
|
+
* Creating state
|
|
147
|
+
* Defining steps for the users/developers
|
|
148
|
+
* Defining steps for internal testing, like testing for appropriate errors and error messages
|
|
149
|
+
* Finishing a Scenario
|
|
150
|
+
* Finishing all tests
|
|
151
|
+
|
|
152
|
+
#### scope.js
|
|
153
|
+
|
|
154
|
+
`./lib/steps.js` makes heavy use of `./lib/scope.js`, where most of the action happens. We have decided to mostly keep it in one file to avoid bouncing back and forth between files.
|
|
155
|
+
|
|
156
|
+
Many `./lib/steps.js` steps make use of the `scope.steps` object. It is there to avoid duplicating code between steps.
|
|
157
|
+
|
|
158
|
+
The file handles things like:
|
|
159
|
+
|
|
160
|
+
* Finding form fields on a page
|
|
161
|
+
* Filling out form fields
|
|
162
|
+
* Generating random data for form fields
|
|
163
|
+
* Waiting for pages to load
|
|
164
|
+
* Checking for server restarts
|
|
165
|
+
* Generating test report content
|
|
166
|
+
|
|
167
|
+
### Logging
|
|
168
|
+
|
|
169
|
+
`./lib/utils/log.js` takes care of logging information of various kinds (normal, debug, error) to the command line in ways we hope are useful. We should probably find a logging library instead, but this is what we have for now. An important feature is that it ensures the messages clearly belong to ALKiln and not to some other process.
|
|
170
|
+
|
|
171
|
+
### session_vars.js
|
|
172
|
+
|
|
173
|
+
The `./lib/utils/session_var.js` file keeps track of what you might otherwise think of as environment variables. We like to think of them as constants, but some of them do need to go through functions, so for consistency we get them all through functions. Also because it was easier to test them when they are functions.
|
|
174
|
+
|
|
175
|
+
### Setup and takedown logic
|
|
176
|
+
|
|
177
|
+
All of the setup and takedown logic is in the `./lib/docassemble` directory. It is named after the docassemble API code that is in there. Also, setup and takedown interact very closely with docassemble and the docassemble server.
|
|
178
|
+
|
|
179
|
+
Other files also use the docassemble API functions, so this folder is in a bit of a messy position.
|
|
180
|
+
|
|
181
|
+
### Bash commands
|
|
182
|
+
|
|
183
|
+
When you `npm run` the scripts in our `./package.json` you can setup, run, or takedown tests. We are working on converting this to a command line tool to avoid some complexity in GitHub actions, increase security, and align more with what this framework has grown into. (TODO: Define this better)
|
|
184
|
+
|
|
185
|
+
### GitHub composite action
|
|
186
|
+
|
|
187
|
+
Our `./action.yml` is a [composite action](https://docs.github.com/en/actions/creating-actions/creating-a-composite-action). The users/developers let it do most of the work for them. It installs npm, installs our repo, then uses our repo to set up the tests, run the tests, generate and save reports, errors, and screenshots, and clean up the tests.
|
|
188
|
+
|
|
189
|
+
### Internal tests
|
|
190
|
+
|
|
191
|
+
We have our own docassemble package in our repo to test our own end-to-end tests. Most of what the package needs is in `./docassemble`. That docassemble package is what the test setup pulls into the docassemble server. Our internal end-to-end cucumber tests are `.feature` files that are stored in `./docassemble/ALKilnTests/data/sources`. The interview (online form) `.yml` files that those `.feature` files use are also deep in the `./docassemble` package. You probably won't be touching the interview files. If you get curious, feel free to ask us.
|
|
192
|
+
|
|
193
|
+
There are other files the docassemble package needs, like `./setup.py`, so if you see them around, don't worry about them.
|
|
194
|
+
|
|
195
|
+
Our unit tests are in `./tests/unit_tests` and their filenames end in `.test.js`. Like the cucumber tests, they use chai for assertions. The fixtures for the tests are also contained in that folder and end in `.fixtures.js`.
|
|
196
|
+
|
|
197
|
+
If you want to know the commands, you can go to the [instructions for running tests](#running-internal-tests).
|
|
198
|
+
|
|
199
|
+
### Files that you don't need to look at
|
|
200
|
+
|
|
201
|
+
`index.js` and `world.js` are short files that cucumber needs. `./lib/utils/langs.js` used to work, but we're not sure it does anymore. No one has used it yet, so we're waiting to experiment until someone expresses a need or we have some extra time.
|
|
202
|
+
|
|
203
|
+
## Footnotes
|
|
204
|
+
|
|
205
|
+
[1] To be clear, our framework is a misuse of cucumberjs. cucumberjs is geared towards behavior driven development. We try to make BDD available to our developers, but it's not always possible and not necessarily our goal.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 plocket
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,26 +1,66 @@
|
|
|
1
1
|
# ALKiln
|
|
2
|
-
Integrated automated end-to-end testing with docassemble, puppeteer, cucumber, and chai.
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
dependent on it.
|
|
3
|
+
ALKiln, or Assembly Line Kiln, is an open source project that helps [docassemble](https://docassemble.org/) developers create automated tests for their interviews (online forms). It works well with the [Document Assembly Line Project](https://suffolklitlab.org/docassemble-AssemblyLine-documentation) but isn't dependent on it.
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
<!--
|
|
6
|
+
https://github.com/18F/open-source-guide/blob/18f-pages/pages/making-readmes-readable.md
|
|
7
|
+
√ What is this repo or project? (You can reuse the repo description you used earlier because this section doesn’t have to be long.)
|
|
8
|
+
√ How does it work?
|
|
9
|
+
√ Who will use this repo or project?
|
|
10
|
+
√ What is the goal of this project?
|
|
11
|
+
-->
|
|
8
12
|
|
|
9
|
-
##
|
|
10
|
-
Read about how to use this framework at https://suffolklitlab.org/docassemble-AssemblyLine-documentation/docs/automated_integrated_testing/.
|
|
13
|
+
## Use ALKiln
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
Read about how to use this framework in [Assembly Line's documentation](https://suffolklitlab.org/docassemble-AssemblyLine-documentation/docs/automated_integrated_testing/).
|
|
16
|
+
|
|
17
|
+
If you have questions or need to report a bug, [start a new issue](https://github.com/SuffolkLITLab/ALKiln/issues/new).
|
|
18
|
+
|
|
19
|
+
The following documentation is for internal developers—those working on ALKiln itself.
|
|
20
|
+
|
|
21
|
+
## Our code
|
|
22
|
+
|
|
23
|
+
Our code pretends to be a human interacting with online forms (interviews) that have been made with the [docassemble](https://docassemble.org) open source platform. It looks at the HTML DOM, manipulates it, and interacts with it.
|
|
24
|
+
|
|
25
|
+
It uses [cucumber](https://cucumber.io/docs/installation/javascript/), [puppeteer](https://pptr.dev/), and [chai](https://www.chaijs.com/).
|
|
26
|
+
|
|
27
|
+
## Our users
|
|
28
|
+
|
|
29
|
+
Our users are developers of online forms (interviews). Usually they're very new to coding and are unfamiliar with GitHub and with a lot of coding concepts. If they know how to code, it tends to be in Python because that's what docassemble uses. They usually don't have the resource or funding to put into learning these skills.
|
|
30
|
+
|
|
31
|
+
For example, a pro bono law firm is trying to write a form that people can use to create a restraining order. They're coding it using docassemble. Their users are already going through a hard time, and the forms make them outline their heart wrenching experiences in detail. The developers need to make sure their users don't get system errors right in the middle of that. They use our framework to run the end-to-end tests.
|
|
32
|
+
|
|
33
|
+
They do good work and we hope to give them a less code-focused way to automate their testing. They avoid having to learn Javascript, GitHub actions, and other such things.
|
|
34
|
+
|
|
35
|
+
To do that, we use [cucumberjs](https://cucumber.io/docs/installation/javascript/), which uses [Gherkin](https://cucumber.io/docs/gherkin/reference/) syntax to give a user/developer a more human-like syntax to instruct alkiln on what answers to give to the user's online form.
|
|
36
|
+
|
|
37
|
+
## Contributing
|
|
38
|
+
|
|
39
|
+
Read about contributing in our [CONTRIBUTING.md document](CONTRIBUTING.md). Here's a quick cheat sheet for some commands once you're up and running:
|
|
40
|
+
|
|
41
|
+
## Cheat sheet
|
|
42
|
+
|
|
43
|
+
*Once you've already read the contributing documentation, you can use these as quick reminders for running our internal tests.*
|
|
44
|
+
To set up for the integration tests, create the project on the server:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
15
47
|
npm run setup
|
|
16
48
|
```
|
|
17
49
|
|
|
18
50
|
Use the syntax below to trigger specific tags:
|
|
19
|
-
|
|
51
|
+
|
|
52
|
+
```bash
|
|
20
53
|
npm run cucumber -- "--tags" "@tagname"
|
|
21
54
|
```
|
|
22
55
|
|
|
23
56
|
To run the unit tests in isolation:
|
|
24
|
-
|
|
57
|
+
|
|
58
|
+
```bash
|
|
25
59
|
npm run unit
|
|
26
60
|
```
|
|
61
|
+
|
|
62
|
+
If you or someone else changes the interview code in `./docassemble`, you have to clean up the old data on the server before running `setup` again:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npm run takedown
|
|
66
|
+
```
|
package/lib/scope.js
CHANGED
|
@@ -52,7 +52,7 @@ let is_secret_var = function(row) {
|
|
|
52
52
|
/* `row` might be a row, a source row, or an original row. */
|
|
53
53
|
let original = get_original_row(row);
|
|
54
54
|
return original.flags !== undefined && original.flags.secret_name !== undefined;
|
|
55
|
-
}
|
|
55
|
+
};
|
|
56
56
|
|
|
57
57
|
let fromBase64 = function(base64_str) {
|
|
58
58
|
/* Takes a base64 encoded string and returns it decoded.
|
|
@@ -636,54 +636,6 @@ module.exports = {
|
|
|
636
636
|
|
|
637
637
|
return false;
|
|
638
638
|
},
|
|
639
|
-
|
|
640
|
-
setVar: async function ( scope, var_name, value ) {
|
|
641
|
-
/* Use variable names and values to interact with buttons that
|
|
642
|
-
* have values, text input elements, textareas, and dropdowns.
|
|
643
|
-
* Returns the element that was found.
|
|
644
|
-
*
|
|
645
|
-
* TODO:
|
|
646
|
-
* - Birthdate fields that will be showing up relatively soon
|
|
647
|
-
* - Time fields?
|
|
648
|
-
*/
|
|
649
|
-
let base64_var_name = toBase64( var_name );
|
|
650
|
-
|
|
651
|
-
// Will catch some radio and checkbox inputs too, which will then be rejected
|
|
652
|
-
// Note: I think `showif`s with `code` don't use `data-saveas`
|
|
653
|
-
let to_manipulate = await Promise.race([
|
|
654
|
-
scope.page.waitForSelector(`button[name="${base64_var_name}"][value="${value}"]`), // button
|
|
655
|
-
scope.page.waitForSelector(`:not(button)[name="${base64_var_name}"]`), // others (not showif)
|
|
656
|
-
scope.page.waitForSelector(`*[data-saveas="${base64_var_name}"] input`), // text input showif
|
|
657
|
-
scope.page.waitForSelector(`*[data-saveas="${base64_var_name}"] textarea`), // textarea showif
|
|
658
|
-
scope.page.waitForSelector(`*[data-saveas="${base64_var_name}"] select`), // select showif/hideif
|
|
659
|
-
]);
|
|
660
|
-
|
|
661
|
-
// Throw error for checkboxes and radios
|
|
662
|
-
let type = await to_manipulate.evaluate( elem => { return elem.getAttribute('type') });
|
|
663
|
-
if ( type === `checkbox` || type === `radio` ) {
|
|
664
|
-
throw new TypeError(`You need the ${type} step, e.g. 'I tap the ${type} variable "some_dict" with the value "choice_value"'`);
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
// Actions based on element
|
|
668
|
-
let tagName = await to_manipulate.evaluate( elem => { return elem.tagName });
|
|
669
|
-
tagName = tagName.toLowerCase();
|
|
670
|
-
|
|
671
|
-
if ( tagName === `button` ) { // Tap buttons
|
|
672
|
-
await scope.tapElement( scope, to_manipulate );
|
|
673
|
-
|
|
674
|
-
} else if ( tagName === `select` ) { // Choose drop-down option
|
|
675
|
-
await to_manipulate.select(value);
|
|
676
|
-
|
|
677
|
-
} else if ( tagName === `input` || tagName === `textarea` ) {
|
|
678
|
-
// Set text field values (includes any other input fields)
|
|
679
|
-
await to_manipulate.evaluate( el => { el.value = '' });
|
|
680
|
-
await to_manipulate.type( value );
|
|
681
|
-
// TODO: Add hideif to this too
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
// Do your own waiting if you need to in the step
|
|
685
|
-
return to_manipulate;
|
|
686
|
-
}, // Ends scope.setVar()
|
|
687
639
|
|
|
688
640
|
continue_button_selector: `fieldset.da-field-buttons button[type="submit"].btn-primary`,
|
|
689
641
|
signature_selector: `fieldset .dasigsave`,
|
|
@@ -1736,7 +1688,7 @@ module.exports = {
|
|
|
1736
1688
|
await scope.afterStep(scope, { waitForShowIf: true });
|
|
1737
1689
|
},
|
|
1738
1690
|
canvas: async function ( scope, { handle, answer }) {
|
|
1739
|
-
await scope.
|
|
1691
|
+
await scope.draw_signature( scope );
|
|
1740
1692
|
await scope.afterStep( scope );
|
|
1741
1693
|
},
|
|
1742
1694
|
input: async function ( scope, { handle, answer }) {
|
|
@@ -1919,7 +1871,7 @@ module.exports = {
|
|
|
1919
1871
|
}, 500)
|
|
1920
1872
|
},
|
|
1921
1873
|
|
|
1922
|
-
|
|
1874
|
+
draw_signature: async function ( scope ) {
|
|
1923
1875
|
/* On a signature page, there should only be a single signature canvas
|
|
1924
1876
|
* and a continue button. Draw in the #dasigcanvas element. `<canvas>`
|
|
1925
1877
|
* takes a while to load. */
|
|
@@ -2327,6 +2279,23 @@ module.exports = {
|
|
|
2327
2279
|
return scope;
|
|
2328
2280
|
}, // Ends scope.throwPageError()
|
|
2329
2281
|
|
|
2282
|
+
take_a_screenshot: async ( scope,{ path }) => {
|
|
2283
|
+
/* Takes a jpeg screenshot. Avoids destroying signatures. */
|
|
2284
|
+
|
|
2285
|
+
let fullPage = true;
|
|
2286
|
+
let signature_elem = await scope.page.$(scope.signature_selector);
|
|
2287
|
+
if ( signature_elem !== null ) {
|
|
2288
|
+
fullPage = false;
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2291
|
+
await scope.page.screenshot({
|
|
2292
|
+
path: path,
|
|
2293
|
+
type: 'jpeg',
|
|
2294
|
+
fullPage: fullPage,
|
|
2295
|
+
});
|
|
2296
|
+
|
|
2297
|
+
}, // Ends scope.take_a_screenshot()
|
|
2298
|
+
|
|
2330
2299
|
|
|
2331
2300
|
//#####################################
|
|
2332
2301
|
//#####################################
|
|
@@ -2349,14 +2318,10 @@ module.exports = {
|
|
|
2349
2318
|
name = `screenshot_on-${ id }-${ date }`;
|
|
2350
2319
|
}
|
|
2351
2320
|
|
|
2352
|
-
await scope.
|
|
2353
|
-
path: `./${ scope.paths.scenario }/${ name }.jpg`,
|
|
2354
|
-
type: 'jpeg',
|
|
2355
|
-
fullPage: true
|
|
2356
|
-
});
|
|
2321
|
+
await scope.take_a_screenshot( scope, { path: `./${ scope.paths.scenario }/${ name }.jpg` });
|
|
2357
2322
|
|
|
2358
2323
|
await scope.afterStep( scope );
|
|
2359
|
-
}, // Ends screenshot()
|
|
2324
|
+
}, // Ends scope.steps.screenshot()
|
|
2360
2325
|
|
|
2361
2326
|
add_json_vars_to_report: async ( scope ) => {
|
|
2362
2327
|
/** Uses https://docassemble.org/docs/functions.html#js_get_interview_variables
|
|
@@ -2371,7 +2336,7 @@ module.exports = {
|
|
|
2371
2336
|
type: `json`,
|
|
2372
2337
|
value: JSON.stringify( data, null, 2 )
|
|
2373
2338
|
});
|
|
2374
|
-
}, // Ends add_json_vars_to_report()
|
|
2339
|
+
}, // Ends scope.steps.add_json_vars_to_report()
|
|
2375
2340
|
|
|
2376
2341
|
link_works: async ( scope, linkText ) => {
|
|
2377
2342
|
let [link] = await scope.page.$x(`//a[contains(text(), "${ linkText }")]`);
|
|
@@ -2390,7 +2355,7 @@ module.exports = {
|
|
|
2390
2355
|
linkPage.close()
|
|
2391
2356
|
|
|
2392
2357
|
await scope.afterStep(scope);
|
|
2393
|
-
}, // Ends link_works()
|
|
2358
|
+
}, // Ends scope.steps.link_works()
|
|
2394
2359
|
|
|
2395
2360
|
set_regular_var: async ( scope, var_name, answer ) => {
|
|
2396
2361
|
/** Set a non-story table variable (with or without a choice associated with it) to a value. Set:
|
|
@@ -2408,7 +2373,7 @@ module.exports = {
|
|
|
2408
2373
|
// Don't continue if the variable doesn't cause navigation itself. Also,
|
|
2409
2374
|
// if this variable cannot be set on this page, trigger an error
|
|
2410
2375
|
await scope.setFields( scope, { var_data, ensure_navigation: false, ensure_all_vars_used: true });
|
|
2411
|
-
}, // Ends set_regular_var()
|
|
2376
|
+
}, // Ends scope.steps.set_regular_var()
|
|
2412
2377
|
|
|
2413
2378
|
set_secret_var: async ( scope, var_name, answer_env_name ) => {
|
|
2414
2379
|
/** Sets a non-story table variable to a "secret" value (i.e. an env var) */
|
|
@@ -2425,7 +2390,7 @@ module.exports = {
|
|
|
2425
2390
|
// Don't continue if the variable doesn't cause navigation itself. Also,
|
|
2426
2391
|
// if this variable cannot be set on this page, trigger an error
|
|
2427
2392
|
await scope.setFields( scope, { var_data, ensure_navigation: false, ensure_all_vars_used: true });
|
|
2428
|
-
},
|
|
2393
|
+
}, // Ends scope.steps.set_secret_var
|
|
2429
2394
|
|
|
2430
2395
|
tap_term: async ( scope, phrase ) => {
|
|
2431
2396
|
/** Tap a link that doesn't navigate. Depends on the language of the text. */
|
|
@@ -2438,13 +2403,13 @@ module.exports = {
|
|
|
2438
2403
|
await scope.tapElement( scope, link );
|
|
2439
2404
|
|
|
2440
2405
|
await scope.afterStep(scope, {waitForShowIf: true});
|
|
2441
|
-
}, // Ends tap_term()
|
|
2406
|
+
}, // Ends scope.steps.tap_term()
|
|
2442
2407
|
|
|
2443
2408
|
sign: async ( scope ) => {
|
|
2444
2409
|
/** Sign on a signature page. */
|
|
2445
|
-
await scope.
|
|
2410
|
+
await scope.draw_signature( scope );
|
|
2446
2411
|
await scope.afterStep(scope);
|
|
2447
|
-
}, // Ends sign()
|
|
2412
|
+
}, // Ends scope.steps.sign()
|
|
2448
2413
|
|
|
2449
2414
|
download: async ( scope, filename ) => {
|
|
2450
2415
|
/* Taps the link that leads to the given filename to trigger downloading.
|
|
@@ -2466,7 +2431,7 @@ module.exports = {
|
|
|
2466
2431
|
// Should this be using `scope.tapElement()`?
|
|
2467
2432
|
await elem.evaluate( elem => { return elem.click(); });
|
|
2468
2433
|
await scope.detectDownloadComplete( scope );
|
|
2469
|
-
}, // Ends download()
|
|
2434
|
+
}, // Ends scope.steps.download()
|
|
2470
2435
|
|
|
2471
2436
|
set_al_name: async ( scope, var_base, name_str ) => {
|
|
2472
2437
|
/** Given a variable name and a space-separated string, fills the
|
|
@@ -2503,15 +2468,20 @@ module.exports = {
|
|
|
2503
2468
|
|
|
2504
2469
|
let desired_pattern = name_patterns[( name_parts.length - 1 )];
|
|
2505
2470
|
|
|
2471
|
+
let raw_data = [];
|
|
2506
2472
|
for ( let parti = 0; parti < name_parts.length; parti++ ) {
|
|
2507
2473
|
let var_name = `${ var_base }.name.${ desired_pattern[ parti ] }`
|
|
2508
2474
|
let value = name_parts[ parti ];
|
|
2509
|
-
|
|
2475
|
+
raw_data.push({ var: var_name, value: value, trigger: scope.trigger_not_needed_flag });
|
|
2510
2476
|
}
|
|
2511
2477
|
|
|
2478
|
+
let var_data = await scope.normalizeTable( scope, { var_data: raw_data, });
|
|
2479
|
+
// Avoid continuing automatically. If this var cannot be set on this page, error
|
|
2480
|
+
await scope.setFields( scope, { var_data, ensure_navigation: false, ensure_all_vars_used: true });
|
|
2481
|
+
|
|
2512
2482
|
// Continue to next page...?
|
|
2513
2483
|
await scope.afterStep(scope, {waitForShowIf: true});
|
|
2514
|
-
}, // Ends set_al_name()
|
|
2484
|
+
}, // Ends scope.steps.set_al_name()
|
|
2515
2485
|
|
|
2516
2486
|
set_al_address: async ( scope, var_base, address_str ) => {
|
|
2517
2487
|
/** Given a variable name and a four-part address formatted as below,
|
|
@@ -2530,16 +2500,21 @@ module.exports = {
|
|
|
2530
2500
|
let address_parts = split.concat( last_parts );
|
|
2531
2501
|
let start = `${ var_base }.address.`;
|
|
2532
2502
|
|
|
2533
|
-
let
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2503
|
+
let no_trigger = scope.trigger_not_needed_flag; // just making the lines shorter
|
|
2504
|
+
let raw_data = [
|
|
2505
|
+
{ var: `${start}address`, value: address_parts[0], trigger: no_trigger },
|
|
2506
|
+
// Remove accidental 'Unit' or 'unit ' text in case dev included it accidentally
|
|
2507
|
+
{ var: `${start}unit`, value: (address_parts[1].toLowerCase()).replace(/unit\s*/, ''), trigger: no_trigger },
|
|
2508
|
+
{ var: `${start}city`, value: address_parts[2], trigger: no_trigger },
|
|
2509
|
+
{ var: `${start}state`, value: address_parts[3], trigger: no_trigger },
|
|
2510
|
+
{ var: `${start}zip`, value: address_parts[4], trigger: no_trigger },
|
|
2511
|
+
];
|
|
2512
|
+
let var_data = await scope.normalizeTable( scope, { var_data: raw_data, });
|
|
2513
|
+
// Avoid continuing automatically. If this var cannot be set on this page, error
|
|
2514
|
+
await scope.setFields( scope, { var_data, ensure_navigation: false, ensure_all_vars_used: true });
|
|
2540
2515
|
|
|
2541
2516
|
await scope.afterStep(scope, {waitForShowIf: true});
|
|
2542
|
-
}, // Ends set_al_address()
|
|
2517
|
+
}, // Ends scope.steps.set_al_address()
|
|
2543
2518
|
|
|
2544
2519
|
sign_in: async function ( scope, { email_secret_name, password_secret_name }) {
|
|
2545
2520
|
/** Allow the developer to log a user into their server using GitHub
|
package/lib/steps.js
CHANGED
|
@@ -846,11 +846,8 @@ When(/I answer randomly for at most ([0-9]+) (?:page(?:s)?|screen(?:s)?)/, { tim
|
|
|
846
846
|
let buttons = await scope.steps.set_random_page_vars( scope );
|
|
847
847
|
|
|
848
848
|
// Take a screenshot of the page before continuing or ending
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
type: `jpeg`,
|
|
852
|
-
fullPage: true
|
|
853
|
-
});
|
|
849
|
+
let path = `${ scope.paths.random_screenshots }/random-${ Date.now() }.jpg`;
|
|
850
|
+
await scope.take_a_screenshot( scope, { path: path });
|
|
854
851
|
|
|
855
852
|
// Prep for the next loop to possibly stop. Signature page buttons
|
|
856
853
|
// don't count as buttons in the way our field detects them
|
|
@@ -1119,27 +1116,23 @@ After(async function(scenario) {
|
|
|
1119
1116
|
if ( !!scope.disable_error_screenshot ) {
|
|
1120
1117
|
scope.addToReport(scope, {
|
|
1121
1118
|
type: `row`,
|
|
1122
|
-
value: `For security, ALKiln will
|
|
1119
|
+
value: `For security, ALKiln will avoid creating a screenshot for this error. It's possible a secret is being used on this screen.`
|
|
1123
1120
|
});
|
|
1124
1121
|
} else {
|
|
1125
1122
|
|
|
1126
1123
|
// Save/download a picture of the screen that's showing during the unexpected status
|
|
1127
1124
|
// Save one copy in the outer-most artifact folder
|
|
1128
1125
|
let scenario_filename = await scope.getSafeScenarioFilename( scope, { prefix: `error_on` });
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
fullPage: true
|
|
1133
|
-
});
|
|
1126
|
+
let path_outer = `${ scope.paths.artifacts }/${ scenario_filename }.jpg`;
|
|
1127
|
+
await scope.take_a_screenshot( scope, { path: path_outer });
|
|
1128
|
+
|
|
1134
1129
|
// Save another copy in the artifact's Scenario folder
|
|
1135
1130
|
let screenshot_name = `error_on`;
|
|
1136
1131
|
let { id } = await scope.examinePageID( scope, 'none to match' );
|
|
1137
1132
|
screenshot_name += `-${ id }`;
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
fullPage: true
|
|
1142
|
-
});
|
|
1133
|
+
let path_scenario = `${ scope.paths.scenario }/${ screenshot_name }.jpg`;
|
|
1134
|
+
await scope.take_a_screenshot( scope, { path: path_scenario });
|
|
1135
|
+
|
|
1143
1136
|
} // ends if scope.disable_error_screenshot
|
|
1144
1137
|
} // ends if scope.page exists
|
|
1145
1138
|
|