أثناء تحرير البرامج النصية في EveryStep Scripting Tool Desktop ، يمكنك إضافة رمز C # مخصص. راجع نموذج كائن أداة البرمجة النصية EveryStep: الفئات والأساليب والخصائص وما إلى ذلك للعثور على مزيد من المعلومات حول تخصيص البرنامج النصي EveryStep.

تتطلب البرامج النصية التي تم تحريرها باستخدام رمز C # المخصص موافقة فريق الدعم الفني لدينا قبل حفظها. في كل مرة تقوم فيها بإضافة رمز C# مخصص أو تحرير برنامج نصي يحتوي على رمز C# مخصص، سيتم إرسال البرنامج النصي للموافقة عليه تلقائيا. لاحظ أن الأمر قد يستغرق بعض الوقت حتى يتمكن فريقنا من مراجعة البرنامج النصي والموافقة عليه للاستخدام.

فيما يلي بعض الأمثلة على إضافة C # إلى برنامج نصي لاستخدام العبارات الشرطية والمتغيرات المعرفة عشوائيا:

أمثلة على العبارة الشرطية

إجهاض تنفيذ البرنامج النصي على خطأ في التحقق من صحة المحتوى

Step (1, "test - https://www.test.com");
tab0 = Tabs.NewTab ();
tab0.GoTo ("https://www.test.com");
if ( !tab0.Text.Contains("<KEYWORD>"))
{
return;
}
على سبيل المثال، لإجهاض البرنامج النصي إذا لم يتم العثور على الكلمة الرئيسية “تسجيل الدخول“، أضف:
if (!tab0.Text.Contains("Login"))

إغلاق النوافذ المنبثقة الشرطية إذا ظهرت

يمكن أن تختلف ظروف إعادة تشغيل البرنامج النصي وفقا للمناطق الجغرافية والوقت وما إلى ذلك. وبالتالي ، يمكن عرض بعض المحتوى مثل النوافذ المنبثقة بناء على الظروف أثناء إعادة تشغيل البرنامج النصي. لتحديد الطريقة التي تريد بها إدارة المحتوى الشرطي على موقع الويب المستهدف، أضف عبارة if إلى البرنامج النصي EveryStep.

على سبيل المثال، لإغلاق نافذة منبثقة إذا تم عرضها على الصفحة أثناء إعادة تشغيل برنامج نصي والانتقال إلى صفحة جديدة

  1. سجل البرنامج النصي باستخدام النافذة المنبثقة المعروضة على الصفحة.
  2. بدلا من ذلك: إذا كان لديك Xpath لتحديد موقع الزر “إغلاق” في الصفحة المستهدفة ، فيمكنك تسجيل البرنامج النصي بدون النافذة المنبثقة.
  3. أضف عبارة if على الخطوة التي يتوقع ظهور النافذة المنبثقة فيها. استخدم الزر “إغلاق” Xpath لتحديد الشرط.

لاحظ أننا نستخدم طريقة WaitForElement في تعبير الاختبار “إذا” لانتظار تحميل النافذة المنبثقة:

tab0.WaitForElement (TimeSpan timeout, string xpath)
// script_version=3.0; everystep_version=0; date=4/8/2022; Chrome=91.0.4472.77
NetworkFilter.Deny ("https://www.adidas.com/api/chk/customer/baskets?sitePath=us");
Tabs.SetSize (1820, 513);
DMBrowser tab0 = null;
Step (1, "adidas Official Website | adidas US - https://www.adidas.com/us/kids");
tab0 = Tabs.NewTab ();
tab0.GoTo ("https://www.adidas.com/");
tab0.Link ("//A[normalize-space(text())=\"KIDS\"]", "//A[normalize-space()=\"3 STRIPE LIFE\"]/../preceding-sibling::DIV[2]//A[normalize-space()=\"KIDS\"]", "//A[normalize-space()=\"Give Back\"]/../preceding-sibling::DIV[3]//A[normalize-space()=\"KIDS\"]").Click ();
Step (2, "Kids Shoes and Clothing | adidas US - https://www.adidas.com/us/kids");
//Waits for pop-up window with the "Close" button to appear on the page for 5 seconds. 
if (tab0.WaitForElement("5sec".ToDuration (), "//*[@ID=\"modal-root\"]/DIV/DIV/BUTTON", "//BUTTON[@ARIA-LABEL=\"Close\"]"))
{
//If the "Close" button detected, clicks the button to close the pop-up. Otherwise, jumps to the next line.
 tab0.Button ("//*[@ID=\"modal-root\"]/DIV/DIV/BUTTON", "//BUTTON[@ARIA-LABEL=\"Close\"]").Click ();
}
tab0.Span ("//A[normalize-space(@TITLE)=\"SHOP NOW\"]//SPAN[normalize-space()=\"SHOP NOW\"]", "//A[normalize-space(@TITLE)=\"SHOP NOW\"]//SPAN[normalize-space(text())=\"SHOP NOW\"]", "(//SPAN[normalize-space(text())=\"SHOP NOW\"])[1]").Click ();
Step (3, "Kids - Ultraboost 22 | adidas US - https://www.adidas.com/us/kids-ultraboost_22");

إضافة العنصر إلى عربة التسوق أو إلى قائمة الانتظار إذا كان العنصر غير متوفر

لو… بيان آخر يسمح للبرنامج النصي الخاص بك بتنفيذ إجراءات محددة مثل نقرات الزر ، وشيك مربع الاختيار ، والتنقل إلى عنوان URL آخر ، وما إلى ذلك بناء على الشرط المحدد. على سبيل المثال، يمكنك تسجيل معاملة “إضافة إلى عربة التسوق” وتريد أن يضيف البرنامج النصي إما عنصرا إلى سلة التسوق أو، إذا كان غير متوفر، إلى قائمة انتظار. يمكنك القيام بذلك عن طريق إضافة إذا… بيان آخر:

  1. سجل معاملة عربة التسوق.
  2. لتحديد تعبير الاختبار ، حدد العنصر الذي ينص على أن العنصر موجود في المخزون ، على سبيل المثال ، الزر “اشتر الآن”.
  3. حدد العبارة “إذا” بعد الانتقال إلى صفحة العنصر باستخدام علامة التبويب0. طريقة WaitForElement (مهلة TimeSpan ، سلسلة xpath) مع الزر “اشتر الآن” Xpath.
  4. حدد الإجراء المطلوب تنفيذه إذا كان العنصر متوفرا كعبارة “إذا”. على سبيل المثال، انقر على “اشتر الآن”.
  5. حدد الإجراء المطلوب تنفيذه إذا كان العنصر غير متوفر (لم يتم اكتشاف زر “اشتر الآن”) كعبارة “آخر”. على سبيل المثال، انقر فوق “إضافة إلى القائمة”.

النصائح

لتحديد إجراءات تدفق بديلة، قم بتسجيل الإجراءات بالإضافة إلى التدفق الافتراضي داخل نفس البرنامج النصي. ثم استخدم الأسطر ذات الصلة في عبارة “آخر”.

تحقق من المثال الوارد أدناه.

// script_version=3.0; everystep_version=0; date=4/8/2022; Chrome=91.0.4472.77
Tabs.SetSize (1820, 479);
DMBrowser tab0 = null;
Step (1, "International Shopping: Shop Computers that Ship Internationally - https://www.amazon.com/b?node=16225007011");
tab0 = Tabs.NewTab ();
tab0.GoTo ("https://www.amazon.com/b?node=16225007011");
tab0.Image ("//IMG[normalize-space(@ALT)=\"Seagate Portable 2TB External Hard Drive Portable HDD – USB 3.0 for PC, Mac, PlayStation, &amp; Xbox - 1-Year Rescue Service (...\"]", "/HTML/BODY/DIV[1]/DIV[2]/DIV[2]/DIV[1]/DIV[2]/DIV/DIV/DIV[2]/DIV[3]/DIV/DIV/SPAN/A/DIV/IMG").Click ();
Step (2, "Amazon.com: Seagate Portable 2TB External Hard Drive Portable HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox - 1-Year Rescue Service (STGX2000400) : Electronics - https://www.amazon.com/gp/product/handle-buy-box/ref=dp_start-bbf_1_glance");
tab0.Navigating ("https://www.amazon.com/gp/product/handle-buy-box/ref=dp_start-bbf_1_glance");
tab0.Para ("//P[normalize-space()=\"500 GB\"]", "//P[normalize-space(text())=\"500 GB\"]", "//LI[normalize-space(@TITLE)=\"Click to select 500 GB\"]/SPAN/DIV/SPAN/SPAN/SPAN/BUTTON/DIV/DIV[1]/P").Click ();

// Waits for the "Buy Now" button to be loaded on the page for 5 seconds. 
if (tab0.WaitForElement("5sec".ToDuration(), "//INPUT[@ID=\"buy-now-button\"]", "(//SPAN[normalize-space()=\"Buy Now\"])[last()]/..//INPUT[@TYPE=\"submit\"]", "(//SPAN[normalize-space()=\"Buy Now\"])[last()]/..//INPUT"))
{
If the "Buy Now" button detected, clicks the button. Otherwise, the "Buy Now" click is skipped from execution and the "Add to List" click is executed. 
tab0.Button ("//INPUT[@ID=\"buy-now-button\"]", "(//SPAN[normalize-space()=\"Buy Now\"])[last()]/..//INPUT[@TYPE=\"submit\"]", "(//SPAN[normalize-space()=\"Buy Now\"])[last()]/..//INPUT").Click ();
}
//if the "Buy Now" button not detected, finds and clicks "Add to List" button instead.
else
{
  tab0.Link ("//A[normalize-space()=\"Add to List\"]", "//A[normalize-space(text())=\"Add to List\"]", "//A[@NAME=\"submit.add-to-registry.wishlist.unrecognized\"]").Click ();
}
Step (3, "Amazon Sign-In - https://www.amazon.com/ap/signin?openid.return_to=https%3A%2F%2Fwww.amazon.com%2Fgp%2Faw%2Fd%2FB07X3XGG3F&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.assoc_handle=usflex&openid.mode=checkid_setup&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&");
tab0.Navigating ("https://www.amazon.com/ap/signin?openid.return_to=https%3A%2F%2Fwww.amazon.com%2Fgp%2Faw%2Fd%2FB07X3XGG3F&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.assoc_handle=usflex&openid.mode=checkid_setup&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&");

توزيع البيانات عشوائيا

التوزيع العشوائي عبر البريد الإلكتروني لعمليات التسجيل

لاستخدام رسائل البريد الإلكتروني التي تم إنشاؤها عشوائيا في عملية التسجيل، يمكنك الإعلان عن متغير جديد بقيمة تم إنشاؤها عشوائيا مشابهة لما يلي:

string mail = ("test" + Guid.NewGuid().ToString("N") + "@gmail.com");

استخدم المتغير كمعلمة أسلوب TypeText لحقل البريد الإلكتروني كما هو موضح أدناه:

tab0.TextField ("//INPUT[@TYPE=\"text\"]", "//INPUT[@ID=\"Contact_Email_Addr\"]", "//INPUT).TypeText (mail.ToString ());
// script_version=3.0; everystep_version=4.0.8108.2121; date=4/8/2022; Chrome=91.0.4472.77
Tabs.SetSize (1768, 816);
DMBrowser tab0 = null;
//Declares the mail variable.
string mail = ("test+" + Guid.NewGuid().ToString("N") + "@gmail.com");
Step (1, "Dotcom-Monitor: Website Monitoring and Performance Testing - https://www.dotcom-monitor.com/");
tab0 = Tabs.NewTab ();
tab0.GoTo ("http://dotcom-monitor.com");
Tabs.SetSize (1768, 623);
tab0.Span ("(//SPAN[normalize-space(text())=\"Free Trial\"])[1]", "(//DIV[@ID=\"jivo-iframe-container\"]/preceding-sibling::DIV[3]//SPAN[normalize-space(text())=\"Free Trial\"])[1]", "(//IFRAME[normalize-space(@TITLE)=\"Jivochat\"]/../preceding-sibling::DIV[3]//SPAN[normalize-space(text())=\"Free Trial\"])[1]").Click ();
Step (2, "Free Trial Sign Up - https://userauth.dotcom-monitor.com/Account/FreeTrialSignUp");
tab0.Navigating ("https://userauth.dotcom-monitor.com/Account/FreeTrialSignUp");
tab0.TextField ("//INPUT[@TYPE=\"text\"]", "//INPUT[@ID=\"Contact_Email_Addr\"]", "//INPUT").Click ();
//Sets the email value to the randomly generated value of the mail variable.
tab0.TextField ("//INPUT[@TYPE=\"text\"]", "//INPUT[@ID=\"Contact_Email_Addr\"]", "//INPUT").TypeText (mail.ToString ());
tab0.Button ("//BUTTON[normalize-space()=\"Start Free Trial\"]", "//BUTTON[normalize-space(text())=\"Start Free Trial\"]", "//BUTTON[@TYPE=\"button\"]").Click ();

دخول سن تتراوح بين 18 و 12 سنة

// script_version=3.0; everystep_version=4.0.5953.25078; date=4/19/2016; IE=11.0.9600.17126
Tabs.ConfigureIEVersion (BrowserMode.IE11, DocumentMode.IE11Emulate);
Tabs.SetSize (1768, 651);
DMBrowser tab0 = null;
Step (1, "The input element - HTML5 tutorial - http://www.html-5-tutorial.com/input-element.php");
tab0 = Tabs.NewTab ();
tab0.GoTo ("http://www.html-5-tutorial.com/input-element.php");

// produces random number in range from 18 to 120
int r = (new Random(DateTime.Now.Second)).Next(18, 121);

tab0.TextField ("//INPUT[@TYPE=\"number\"]", "//INPUT[@NAME=\"age\"]", "//B[normalize-space()=\"Age:\"]/..//INPUT").TypeText (r.ToString());

اختيار جنس الذكور أو الإناث عشوائيا

// script_version=3.0; everystep_version=4.0.5953.25078; date=4/19/2016; IE=11.0.9600.17126

Tabs.ConfigureIEVersion (BrowserMode.IE11, DocumentMode.IE11Emulate);
Tabs.SetSize (1768, 714);
DMBrowser tab0 = null;
Step (1, "visible - http://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_radio");
tab0 = Tabs.NewTab ();
tab0.GoTo ("http://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_radio");
for (int i = 0; i < 5; i++)

// produces random number in range from 0 to 2

int r = (new Random(DateTime.Now.Second)).Next(0, 3);
if (r == 0)
{
tab0.Frame ("//IFRAME[@ID=\"iframeResult\"]", "//IFRAME").RadioButton ("//INPUT[@VALUE=\"female\"]", "//INPUT[@VALUE=\"other\"]/preceding-sibling::INPUT[1]", "//INPUT[@VALUE=\"male\"]/following-sibling::INPUT[1]").Click ();
}
else if (r == 1)
{
tab0.Frame ("//IFRAME[@ID=\"iframeResult\"]", "//IFRAME").RadioButton ("//INPUT[@VALUE=\"other\"]", "//INPUT[@VALUE=\"female\"]/following-sibling::INPUT[1]", "//INPUT[@VALUE=\"male\"]/following-sibling::INPUT[2]").Click ();
}
else if (r == 2)
{
tab0.Frame ("//IFRAME[@ID=\"iframeResult\"]", "//IFRAME").RadioButton ("//INPUT[@VALUE=\"male\"]", "(//INPUT[@TYPE=\"radio\"])[1]", "(//INPUT[@NAME=\"gender\"])[1]").Click ();
}
Delay("3sec".ToDuration());
}

اختيار عنصر عشوائي من كتالوج منتجات عبر الإنترنت

لإنشاء برنامج نصي يختار بشكل متكرر عناصر عشوائية من كتالوج عبر الإنترنت، استخدم النموذج المتوفر أدناه. لاحظ أنه يوصى بتسجيل نقرات متعددة للعنصر أولا لتسهيل تحرير الأصل لاحقا.

// script_version=3.0; everystep_version=4.0.8108.2121; date=4/12/2022; Chrome=91.0.4472.77
Tabs.SetSize (1768, 714);
DMBrowser tab0 = null;
Step (1, "Amazon.com: Jewelry Made in Italy: Clothing, Shoes & Jewelry - https://www.amazon.com/b?node=19219863011&pf_rd_r=ZS16WVQN9RD996FPB6TH&pf_rd_p=0b9330ec-285a-4f51-9e1c-6765ca451c5f&pd_rd_r=3b9e3cf5-d247-4f50-8d15-a6683fa46846&pd_rd_w=uNsg8&pd_rd_wg=xFg13&ref_=pd_gw_unk");
tab0 = Tabs.NewTab ();
tab0.GoTo ("https://www.amazon.com/b?node=19219863011&pf_rd_r=ZS16WVQN9RD996FPB6TH&pf_rd_p=0b9330ec-285a-4f51-9e1c-6765ca451c5f&pd_rd_r=3b9e3cf5-d247-4f50-8d15-a6683fa46846&pd_rd_w=uNsg8&pd_rd_wg=xFg13&ref_=pd_gw_unk");

//Collects all images to count the total number of images in the body and saves them to the body's Attribute
tab0.RunScript("(function(){const imgCount=document.querySelectorAll(\".s-image\").length;document.body.setAttribute(\"data-imgCount\", imgCount);})()");
int count = 0;

//Gets the value of the Attribute 
string countString = tab0.Element("//BODY").GetAttributeValue("data-imgCount");

//If countString parsed successfully then clicks a random image on the page. Otherwise, raises an error. 
if (!int.TryParse(countString, out count)) {
  RaiseError(string.Format("Failed to get elements count: {0}", countString));
} else {
  var rnd = new Random();
  int i = rnd.Next(1, count);

//Clicks the picked image  
  tab0.Image (string.Format ("(//IMG[@CLASS=\"s-image\"])[{0}]", i)).Click ();

//Navigates to the item page
Step (2, string.Format ("Amazon.com: Selected Item {0}", i));

//Waits for the navigation to be finished. The Navigating (string url) argument can be set to a random URL since it is being scripted while the source script recording and not interfered with the script execution logic. However, the specified URL will be presented in the report data. Check report data for network requests to find an actual URL that was used in the related script run.
tab0.Navigating ("https://www.amazon.com/KEZEF-Creations-Sterling-Overlay-Necklace/dp/B008Y357US/ref=lp_19219863011_1_1");

//Navigates back to the main page and repeats the cycle. You can populate the following lines as many times as necessary within your script.
Step (3, "Amazon.com: Jewelry Made in Italy: Clothing, Shoes & Jewelry - https://www.amazon.com/b?node=19219863011&pf_rd_r=ZS16WVQN9RD996FPB6TH&pf_rd_p=0b9330ec-285a-4f51-9e1c-6765ca451c5f&pd_rd_r=3b9e3cf5-d247-4f50-8d15-a6683fa46846&pd_rd_w=uNsg8&pd_rd_wg=xFg13&ref_=pd_gw_unk");
tab0.Back ();
  i = rnd.Next(1, count);
  tab0.Image (string.Format ("(//IMG[@CLASS=\"s-image\"])[{0}]", i)).Click ();
Step (4, string.Format ("Amazon.com: Selected Item {0}", i));
tab0.Navigating ("https://www.amazon.com/Saint-MIchael-Archangel-Medal-Patron/dp/B01G3K6M5C/ref=lp_19219863011_1_3");
Step (5, "Amazon.com: Jewelry Made in Italy: Clothing, Shoes & Jewelry - https://www.amazon.com/b?node=19219863011&pf_rd_r=ZS16WVQN9RD996FPB6TH&pf_rd_p=0b9330ec-285a-4f51-9e1c-6765ca451c5f&pd_rd_r=3b9e3cf5-d247-4f50-8d15-a6683fa46846&pd_rd_w=uNsg8&pd_rd_wg=xFg13&ref_=pd_gw_unk");
tab0.Back ();
}