Skip to content

Commit 9159f68

Browse files
committed
feat: add locator.inputValue
1 parent 60f41de commit 9159f68

9 files changed

+295
-53
lines changed

README.md

+49-12
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ test("auto Playwright example", async ({ page }) => {
4343
4444
## Usage
4545
46-
At minimum, the `auto` function requires a _plain text prompt_ and an _argument_ that contains your ` page`` and `test`` objects.
46+
At minimum, the `auto` function requires a _plain text prompt_ and an _argument_ that contains your `page` and `test` objects.
4747
4848
```ts
4949
auto("<your prompt>", { page, test });
@@ -59,7 +59,7 @@ There are additional options you can pass as a third argument:
5959
6060
```ts
6161
const options = {
62-
// If true, debugging information is returned from the auto() call.
62+
// If true, debugging information is printed in the console.
6363
debug: boolean,
6464
// The OpenAI model (https://platform.openai.com/docs/models/overview)
6565
model: "gpt-4-1106-preview",
@@ -70,11 +70,11 @@ auto("<your prompt>", { page, test }, options);
7070
7171
## Supported Actions & Return Values
7272
73-
Depending on the `type` of action (specified above or inferred by the `auto` function), there are different behaviors and return types.
73+
Depending on the `type` of action (inferred by the `auto` function), there are different behaviors and return types.
7474
7575
### Action
7676
77-
**Action**: An action (e.g. "click") is some simulated user interaction with the page, e.g. a click on a link. Actions will return `undefined`` if they were successful and will throw an error if they failed, e.g.
77+
An action (e.g. "click") is some simulated user interaction with the page, e.g. a click on a link. Actions will return `undefined`` if they were successful and will throw an error if they failed, e.g.
7878
7979
```ts
8080
try {
@@ -86,7 +86,7 @@ try {
8686
8787
### Query
8888
89-
**Query**: A query will return requested data from the page as a string, e.g.
89+
A query will return requested data from the page as a string, e.g.
9090
9191
```ts
9292
const linkText = await auto("Get the text of the first link", { page, test });
@@ -96,7 +96,7 @@ console.log("The link text is", linkText);
9696
9797
### Assert
9898
99-
**Assert**: An assertion is a question that will return `true` or `false`, e.g.
99+
An assertion is a question that will return `true` or `false`, e.g.
100100
101101
```ts
102102
const thereAreThreeLinks = await auto("Are there 3 links on the page?", {
@@ -107,12 +107,49 @@ const thereAreThreeLinks = await auto("Are there 3 links on the page?", {
107107
console.log(`"There are 3 links" is a ${thereAreThreeLinks} statement`);
108108
```
109109
110+
111+
## Why use Auto Playwright?
112+
113+
Certainly! Here's a rephrased version of the provided content, presented in a markdown table:
114+
115+
| Aspect | Conventional Approach | Testing with Auto Playwright |
116+
| ------ | --------------------- | ---------------------------- |
117+
| **Coupling with Markup** | Strongly linked to the application's markup. | Eliminates the use of selectors; actions are determined by the AI assistant at runtime. |
118+
| **Speed of Implementation** | Slower implementation due to the need for precise code translation for each action. | Rapid test creation using simple, plain text instructions for actions and assertions. |
119+
| **Handling Complex Scenarios** | Automating complex scenarios is challenging and prone to frequent failures. | Facilitates testing of complex scenarios by focusing on the intended test outcomes. |
120+
| **Test Writing Timing** | Can only write tests after the complete development of the functionality. | Enables a Test-Driven Development (TDD) approach, allowing test writing concurrent with or before functionality development. |
121+
110122
## Supported Playwright Actions
111123
112-
* `page.goto`
113-
* `locator.getAttribute`
114-
* `locator.innerHTML`
115-
* `locator.innerText`
116-
* `locator.fill`
124+
- `locator.fill`
125+
- `locator.getAttribute`
126+
- `locator.innerHTML`
127+
- `locator.innerText`
128+
- `locator.inputValue`
129+
- `page.goto`
130+
131+
Adding new actions is easy: just update the `functions` in [`src/completeTask.ts`](src/completeTask.ts).
132+
133+
## Pricing
134+
135+
This library is free. However, there are costs associated with using OpenAI. You can find more information about pricing here: https://openai.com/pricing/.
136+
137+
<details>
138+
<summary>Example</summary>
139+
140+
Using https://ray.run/ as an example, the cost of running a test step is approximately $0.01 using GPT-4 Turbo (and $0.001 using GPT-3.5 Turbo).
141+
142+
The low cost is in part because `auto-playwright` uses HTML sanitization to reduce the payload size, e.g. What follows is the payload that would be submitted for https://ray.run/.
143+
144+
Naturally, the price will vary dramatically depending on the payload.
145+
146+
```html
147+
<div class="cYdhWw dKnOgO geGbZz bGoBgk jkEels"><div class="kSmiQp fPSBzf bnYmbW dXscgu xJzwH jTWvec gzBMzy"><h1 class="fwYeZS fwlORb pdjVK bccLBY fsAQjR fyszFl WNJim fzozfU">Learn Playwright</h1><h2 class="cakMWc ptfck bBmAxp hSiiri xJzwS gnfYng jTWvec fzozfU">Resources for learning end-to-end testing using Playwright automation framework</h2><div class="bLTbYS gvHvKe cHEBuD ddgODW jsxhGC kdTEUJ ilCTXp iQHbtH yuxBn ilIXfy gPeiPq ivcdqp isDTsq jyZWmS ivdkBK cERSkX hdAwi ezvbLT jNrAaV jsxhGJ fzozCb"></div></div><div class="cYdhWw dpjphg cqUdSC fasMpP"><a class="gacSWM dCgFix conipm knkqUc bddCnd dTKJOB leOtqz hEzNkW fNBBKe jTWvec fIMbrO fzozfU group" href="/blog"><div class="plfYl bccLBY hSiiri fNBpvX">Blog</div><div class="jqqjPD fWDXZB pKTba bBmAxp hSiiri evbPEu"><p>Learn in depth subjects about end-to-end testing.</p></div></a><a class="gacSWM dCgFix conipm knkqUc bddCnd dTKJOB leOtqz hEzNkW fNBBKe jTWvec fIMbrO fzozfU group" href="/ask"><div class="plfYl bccLBY hSiiri fNBpvX">Ask AI</div><div class="jqqjPD fWDXZB pKTba bBmAxp hSiiri evbPEu"><p>Ask ChatGPT Playwright questions.</p></div></a><a class="gacSWM dCgFix conipm knkqUc bddCnd dTKJOB leOtqz hEzNkW fNBBKe jTWvec fIMbrO fzozfU group" href="/tools"><div class="plfYl bccLBY hSiiri fNBpvX">Dev Tools</div><div class="jqqjPD fWDXZB pKTba bBmAxp hSiiri evbPEu"><p>All-in-one toolbox for QA engineers.</p></div></a><a class="gacSWM dCgFix conipm knkqUc bddCnd dTKJOB leOtqz hEzNkW fNBBKe jTWvec fIMbrO fzozfU group" href="/jobs"><div class="plfYl bccLBY hSiiri fNBpvX">QA Jobs</div><div class="jqqjPD fWDXZB pKTba bBmAxp hSiiri evbPEu"><p>Handpicked QA and Automation opportunities.</p></div></a><a class="gacSWM dCgFix conipm knkqUc bddCnd dTKJOB leOtqz hEzNkW fNBBKe jTWvec fIMbrO fzozfU group" href="/questions"><div class="plfYl bccLBY hSiiri fNBpvX">Questions</div><div class="jqqjPD fWDXZB pKTba bBmAxp hSiiri evbPEu"><p>Ask AI answered questions about Playwright.</p></div></a><a class="gacSWM dCgFix conipm knkqUc bddCnd dTKJOB leOtqz hEzNkW fNBBKe jTWvec fIMbrO fzozfU group" href="/discord-forum"><div class="plfYl bccLBY hSiiri fNBpvX">Discord Forum</div><div class="jqqjPD fWDXZB pKTba bBmAxp hSiiri evbPEu"><p>Archive of Discord Forum posts about Playwright.</p></div></a><a class="gacSWM dCgFix conipm knkqUc bddCnd dTKJOB leOtqz hEzNkW fNBBKe jTWvec fIMbrO fzozfU group" href="/videos"><div class="plfYl bccLBY hSiiri fNBpvX">Videos</div><div class="jqqjPD fWDXZB pKTba bBmAxp hSiiri evbPEu"><p>Tutorials, conference talks, and release videos.</p></div></a><a class="gacSWM dCgFix conipm knkqUc bddCnd dTKJOB leOtqz hEzNkW fNBBKe jTWvec fIMbrO fzozfU group" href="/browser-extension"><div class="plfYl bccLBY hSiiri fNBpvX">Browser Extension</div><div class="jqqjPD fWDXZB pKTba bBmAxp hSiiri evbPEu"><p>GUI for generating Playwright locators.</p></div></a><a class="gacSWM dCgFix conipm knkqUc bddCnd dTKJOB leOtqz hEzNkW fNBBKe jTWvec fIMbrO fzozfU group" href="/wiki"><div class="plfYl bccLBY hSiiri fNBpvX">QA Wiki</div><div class="jqqjPD fWDXZB pKTba bBmAxp hSiiri evbPEu"><p>Definitions of common end-to-end testing terms.</p></div></a></div><div class="kSmiQp fPSBzf pKTba eTDpsp legDhJ hSiiri hdaZLM jTWvec gzBMzy bGySga fzoybr"><p class="dXhlDK leOtqz glpWRZ fNCcFz">Use <kbd class="bWhrAL XAzZz cakMWc bUyOMB bmOrOm fyszFl dTmriP">⌘</kbd> + <kbd>k</kbd> + "Tools" to quickly access all tools.</p></div></div>
148+
```
149+
</details>
150+
151+
## Implementation
152+
153+
### HTML Sanitization
117154
118-
Adding new actions is easy: just update the `functions` in [`src/completeTask.ts`](src/completeTask.ts).
155+
The `auto` function uses [sanitize-html](https://www.npmjs.com/package/sanitize-html) to sanitize the HTML of the page before sending it to OpenAI. This is done to reduce cost and improve the quality of the generated text.

package-lock.json

+185-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)