เรียกใช้การทดสอบนักเขียนบทละครโดยใช้ AI
auto-playwright : npm install auto-playwright -D.env ของคุณ: export OPENAI_API_KEY= ' sk-..."auto : import { test , expect } from "@playwright/test" ;
import { auto } from "auto-playwright" ;
test ( "auto Playwright example" , async ( { page } ) => {
await page . goto ( "/" ) ;
// `auto` can query data
// In this case, the result is plain-text contents of the header
const headerText = await auto ( "get the header text" , { page , test } ) ;
// `auto` can perform actions
// In this case, auto will find and fill in the search text input
await auto ( `Type " ${ headerText } " in the search box` , { page , test } ) ;
// `auto` can assert the state of the website
// In this case, the result is a boolean outcome
const searchInputHasHeaderText = await auto ( `Is the contents of the search box equal to " ${ headerText } "?` , { page , test } ) ;
expect ( searchInputHasHeaderText ) . toBe ( true ) ;
} ) ;รวมประเภท stepoptions ที่มีค่าที่จำเป็นสำหรับการเชื่อมต่อกับ Azure OpenAI
import { test , expect } from "@playwright/test" ;
import { auto } from "auto-playwright" ;
import { StepOptions } from "../src/types" ;
const apiKey = "apikey" ;
const resource = "azure-resource-name" ;
const model = "model-deployment-name" ;
const options : StepOptions = {
model : model ,
openaiApiKey : apiKey ,
openaiBaseUrl : `https:// ${ resource } .openai.azure.com/openai/deployments/ ${ model } ` ,
openaiDefaultQuery : { 'api-version' : "2023-07-01-preview" } ,
openaiDefaultHeaders : { 'api-key' : apiKey }
} ;
test ( "auto Playwright example" , async ( { page } ) => {
await page . goto ( "/" ) ;
// `auto` can query data
// In this case, the result is plain-text contents of the header
const headerText = await auto ( "get the header text" , { page , test } , options ) ;
// `auto` can perform actions
// In this case, auto will find and fill in the search text input
await auto ( `Type " ${ headerText } " in the search box` , { page , test } , options ) ;
// `auto` can assert the state of the website
// In this case, the result is a boolean outcome
const searchInputHasHeaderText = await auto ( `Is the contents of the search box equal to " ${ headerText } "?` , { page , test } , options ) ;
expect ( searchInputHasHeaderText ) . toBe ( true ) ;
} ) ; อย่างน้อยที่สุดฟังก์ชั่น auto ต้องใช้ ข้อความข้อความธรรมดา และ อาร์กิวเมนต์ ที่มี page และ test (ไม่บังคับ) วัตถุ
auto ( "<your prompt>" , { page , test } ) ; ทำงานโดยไม่มีพารามิเตอร์ test :
import { chromium } from "playwright" ;
import { auto } from "auto-playwright" ;
( async ( ) => {
const browser = await chromium . launch ( { headless : true } ) ;
const context = await browser . newContext ( ) ;
const page = await context . newPage ( ) ;
// Navigate to a website
await page . goto ( "https://www.example.com" ) ;
// `auto` can query data
// In this case, the result is plain-text contents of the header
const res = await auto ( "get the header text" , { page } ) ;
// use res.query to get a query result.
console . log ( res ) ;
await page . close ( ) ;
} ) ( ) ; คุณอาจผ่านแอตทริบิวต์ debug เป็นพารามิเตอร์ที่สามไปยังฟังก์ชัน auto สิ่งนี้จะพิมพ์พรอมต์และคำสั่งที่ดำเนินการโดย OpenAI
await auto ( "get the header text" , { page , test } , { debug : true } ) ; นอกจากนี้คุณยังสามารถตั้งค่าสภาพแวดล้อม AUTO_PLAYWRIGHT_DEBUG=true ซึ่งจะเปิดใช้งานการดีบักสำหรับการโทร auto ทั้งหมด
export AUTO_PLAYWRIGHT_DEBUG=trueทุกเบราว์เซอร์ที่นักเขียนบทละครรองรับ
มีตัวเลือกเพิ่มเติมที่คุณสามารถผ่านเป็นอาร์กิวเมนต์ที่สาม:
const options = {
// If true, debugging information is printed in the console.
debug : boolean ,
// The OpenAI model (https://platform.openai.com/docs/models/overview)
model : "gpt-4-1106-preview" ,
// The OpenAI API key
openaiApiKey : 'sk-...' ,
} ;
auto ( "<your prompt>" , { page , test } , options ) ; ขึ้นอยู่กับ type ของการกระทำ (อนุมานโดยฟังก์ชั่น auto ) มีพฤติกรรมและประเภทการคืนที่แตกต่างกัน
การกระทำ (เช่น "คลิก") เป็นการโต้ตอบกับผู้ใช้จำลองกับหน้าเว็บเช่นคลิกที่ลิงค์ การกระทำจะส่งคืน `undefined`` ถ้าพวกเขาประสบความสำเร็จและจะโยนข้อผิดพลาดหากพวกเขาล้มเหลวเช่น
try {
await auto ( "click the link" , { page , test } ) ;
} catch ( e ) {
console . error ( "failed to click the link" ) ;
}แบบสอบถามจะส่งคืนข้อมูลที่ร้องขอจากหน้าเป็นสตริงเช่น
const linkText = await auto ( "Get the text of the first link" , { page , test } ) ;
console . log ( "The link text is" , linkText ) ; การยืนยันเป็นคำถามที่จะส่งคืน true หรือ false เช่น
const thereAreThreeLinks = await auto ( "Are there 3 links on the page?" , {
page ,
test ,
} ) ;
console . log ( `"There are 3 links" is a ${ thereAreThreeLinks } statement` ) ; | ด้าน | วิธีการทั่วไป | การทดสอบกับนักเขียนบทละครอัตโนมัติ |
|---|---|---|
| การมีเพศสัมพันธ์กับมาร์กอัป | เชื่อมโยงอย่างมากกับมาร์กอัปของแอปพลิเคชัน | กำจัดการใช้ตัวเลือก; การกระทำจะถูกกำหนดโดยผู้ช่วย AI เมื่อรันไทม์ |
| ความเร็วในการดำเนินการ | การใช้งานช้าลงเนื่องจากความต้องการการแปลรหัสที่แม่นยำสำหรับการกระทำแต่ละครั้ง | การสร้างการทดสอบอย่างรวดเร็วโดยใช้คำแนะนำข้อความธรรมดาสำหรับการกระทำและการยืนยัน |
| การจัดการสถานการณ์ที่ซับซ้อน | สถานการณ์ที่ซับซ้อนโดยอัตโนมัตินั้นท้าทายและมีแนวโน้มที่จะล้มเหลวบ่อยครั้ง | อำนวยความสะดวกในการทดสอบสถานการณ์ที่ซับซ้อนโดยมุ่งเน้นไปที่ผลการทดสอบที่ตั้งใจไว้ |
| เวลาเขียนทดสอบ | สามารถเขียนการทดสอบหลังจากการพัฒนาฟังก์ชันการทำงานอย่างสมบูรณ์ | เปิดใช้งานวิธีการพัฒนาที่ขับเคลื่อนด้วยการทดสอบ (TDD) ช่วยให้การเขียนทดสอบพร้อมกันกับหรือก่อนการพัฒนาฟังก์ชั่น |
locator.blurlocator.boundingBoxlocator.checklocator.clearlocator.clicklocator.countlocator.filllocator.getAttributelocator.innerHTMLlocator.innerTextlocator.inputValuelocator.isCheckedlocator.isEditablelocator.isEnabledlocator.isVisiblelocator.textContentlocator.uncheckpage.goto การเพิ่มการกระทำใหม่เป็นเรื่องง่าย: เพียงแค่อัปเดต functions ใน src/completeTask.ts
ห้องสมุดนี้ฟรี อย่างไรก็ตามมีค่าใช้จ่ายที่เกี่ยวข้องกับการใช้ OpenAI คุณสามารถค้นหาข้อมูลเพิ่มเติมเกี่ยวกับการกำหนดราคาได้ที่นี่: https://openai.com/pricing/
การใช้ https://ray.run/ เป็นตัวอย่างค่าใช้จ่ายในการเรียกใช้ขั้นตอนการทดสอบอยู่ที่ประมาณ $ 0.01 โดยใช้ GPT-4 Turbo (และ $ 0.001 โดยใช้ GPT-3.5 Turbo)
ต้นทุนต่ำเป็นส่วนหนึ่งเนื่องจาก auto-playwright ใช้การฆ่าเชื้อ HTML เพื่อลดขนาดน้ำหนักบรรทุกเช่นสิ่งต่อไปนี้คือน้ำหนักบรรทุกที่จะส่งสำหรับ https://ray.run/
โดยธรรมชาติราคาจะแตกต่างกันอย่างมากขึ้นอยู่กับน้ำหนักบรรทุก
< 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 > ฟังก์ชั่น auto ใช้ sanitize-HTML เพื่อฆ่าเชื้อ HTML ของหน้าก่อนที่จะส่งไปยัง OpenAI สิ่งนี้ทำเพื่อลดต้นทุนและปรับปรุงคุณภาพของข้อความที่สร้างขึ้น
โครงการนี้ดึงแรงบันดาลใจจาก Zerostep Zerostep เสนอ API ที่คล้ายกัน แต่มีการใช้งานที่แข็งแกร่งยิ่งขึ้นผ่านแบ็กเอนด์ที่เป็นกรรมสิทธิ์ Auto Playwright ถูกสร้างขึ้นโดยมีจุดประสงค์เพื่อสำรวจเทคโนโลยีพื้นฐานของ Zerostep และสร้างพื้นฐานสำหรับซอฟต์แวร์โอเพนซอร์ซ สำหรับสภาพแวดล้อมการผลิตฉันขอแนะนำให้เลือก Zerostep
นี่คือการเปรียบเทียบแบบเคียงข้างกันของ Auto Playwright และ Zerostep:
| เกณฑ์ | นักเขียนบทละครอัตโนมัติ | Zerostep |
|---|---|---|
| ใช้ openai api | ใช่ | หมายเลข 1 |
| ใช้พรอมต์ข้อความธรรมดา | ใช่ | เลขที่ |
ใช้ functions SDK | ใช่ | เลขที่ |
| ใช้การฆ่าเชื้อ HTML | ใช่ | เลขที่ |
| ใช้ API นักเขียนบทละคร | ใช่ | No 2 |
| ใช้ภาพหน้าจอ | เลขที่ | ใช่ |
| ใช้คิว | เลขที่ | ใช่ |
| ใช้ WebSockets | เลขที่ | ใช่ |
| ภาพรวม | HTML | ดอม |
| ใช้ความเท่าเทียมกัน | เลขที่ | ใช่ |
| อนุญาตให้เลื่อน | เลขที่ | ใช่ |
| ให้การติดตั้ง | เลขที่ | ใช่ |
| ใบอนุญาต | มิกซ์ | มิกซ์ |
MIT License
Copyright (c) 2023 Reflect Software Inc
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ใช้ API ที่เป็นกรรมสิทธิ์ของ Zerostep
ใช้ API นักเขียนบทละคร แต่ส่วนใหญ่อาศัยโปรโตคอล Chrome Devtools (CDP)