• Selenium Video Tutorials

Selenium IDE - 程式碼匯出



Selenium IDE 是一款重要的工具,因其錄製和回放功能而被廣泛使用。它包含兩個關鍵元件,即使用操作和事件在瀏覽器中回放,以及在命令列模式下使用命令列執行程式進行回放。

Selenium SIDE Runner 環境

Selenium 執行程式構建於 Node 之上。這可用於匯出程式碼。其他要求包括:

  • Node.js 版本 8 及以上版本
  • Jest
  • Jest 環境 Selenium
  • Selenium Webdriver

如何匯出程式碼?

匯出程式碼時,需要採取一些措施。因為外掛不僅僅是匯出程式碼的唯一方式。它也沒有處理匯出流程。為了確保外掛不會互相干擾執行,採取了一些措施:

避免使用 Return

return 關鍵字使用後的程式碼永遠不會執行,並停止其他外掛的工作。例如,

return promise1();
plugin1func(); // after the usage of above return code, this is unreachable.

相反,使用 await 函式的以下解決方案有效:

await promise1();
plugin1func(); // this should work

避免在全域性範圍內定義變數

在全域性級別定義變數意味著,如果另一個外掛或 Selenium IDE 定義了相同的變數,則要麼會生成錯誤訊息,要麼使除錯變得困難。例如,

  • store | button | ele
  • plugin click | button
  • assert element present | xpath=${ele}

在定義變數時,程式碼將為:

let ele = "button";
let ele = await driver.findElement();
await ele.click();
expect(ele).toBePresent(); // ambiguity on which variable

相反,使用 Promise 的 then 函式的以下解決方案有效:

let ele = "button";
await driver.findElement().then(ele => {
  return ele.click();
});
expect(ele).toBePresent(); // hold the correct defined button

結論

本教程全面介紹了 Selenium IDE - 程式碼匯出,到此結束。我們從描述 Selenium SIDE Runner 環境和如何匯出程式碼開始。這使您深入瞭解了 Selenium IDE 程式碼匯出。明智的做法是不斷練習所學內容,並探索與 Selenium 相關的其他內容,以加深您的理解並拓寬您的視野。

廣告

© . All rights reserved.