تشغيل اختبارات الكاتب المسرحي باستخدام الذكاء الاصطناعي.
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 ) ، هناك سلوكيات مختلفة وأنواع الإرجاع.
الإجراء (على سبيل المثال "انقر فوق") هو بعض تفاعل المستخدم المحاكاة مع الصفحة ، على سبيل المثال انقر فوق رابط. ستعود الإجراءات إلى "غير محدد" إذا نجحت وسوف ترمي خطأ إذا فشلت ، على سبيل المثال
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` ) ; | وجه | النهج التقليدي | اختبار مع الكاتب المسرحي التلقائي |
|---|---|---|
| اقتران مع الترميز | مرتبط بقوة بتوصيف التطبيق. | يلغي استخدام المختارين ؛ يتم تحديد الإجراءات من قبل مساعد الذكاء الاصطناعي في وقت التشغيل. |
| سرعة التنفيذ | التنفيذ الأبطأ بسبب الحاجة إلى ترجمة رمز دقيقة لكل إجراء. | إنشاء الاختبار السريع باستخدام تعليمات نصية بسيطة وبسيطة للإجراءات والتأكيدات. |
| التعامل مع السيناريوهات المعقدة | أتمتة السيناريوهات المعقدة أمر صعب ومعرض للفشل المتكرر. | يسهل اختبار السيناريوهات المعقدة من خلال التركيز على نتائج الاختبار المقصودة. |
| اختبار توقيت كتابة | لا يمكن كتابة اختبارات إلا بعد التطوير الكامل للوظائف. | يتيح نهج التطوير الذي يحركه الاختبار (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/pring/.
باستخدام 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 واجهة برمجة تطبيقات مماثلة ولكن مع تطبيق أكثر قوة من خلال الواجهة الخلفية الخاصة بها. تم إنشاء الكاتب المسرحي التلقائي بهدف استكشاف التكنولوجيا الأساسية لـ Zerostep ووضع أساس لإصدار مفتوح المصدر من برامجهم. بالنسبة لبيئات الإنتاج ، أقترح اختيار Zerostep.
فيما يلي مقارنة جنبًا إلى جنب للكاتب المسرحي التلقائي و Zerostep:
| معايير | الكاتب المسرحي التلقائي | Zerostep |
|---|---|---|
| يستخدم Openai API | نعم | لا 1 |
| يستخدم مطالبات النص العادي | نعم | لا |
يستخدم functions SDK | نعم | لا |
| يستخدم HTML تطهير | نعم | لا |
| يستخدم playwright API | نعم | لا 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.
يستخدم zerostep api api. ↩
يستخدم بعض واجهة برمجة تطبيقات الكاتب المسرحي ، ولكنه يعتمد في الغالب على بروتوكول Chrome DevTools (CDP). ↩