What are the advanced tips in Selenium scripting?

Nowadays, application development is much faster. So there is a need to test those applications fast within a short period of time. Here ‘Automation’ is testing plays an important role. 它減少了手工測試時間/精力,並產生更多的相應的檢測輸出. 有大量的自動化測試工具在市場上買到.

硒是最流行和廣泛使用的自動化測試套件之一. 它是開源的,並適用於不同平台和基於瀏覽器的Web應用程序測試. 硒最初在推出 2004.

硒是不是只是一個單一的自動化測試工具. 但它實際上包括了一堆軟件, 支持應用程序的不同測試需要. 讓我們來看看它的四個基本組成部分.

  • 硒IDE: 這是使用Firefox的插件來創建簡單的自動化測試. 它具有錄音功能,它允許記錄用戶行為並將其保存為一個腳本. 這個腳本是一個可重用組件.
  • 硒的遠程控制 (RC): 這是一個工具,它允許用戶通過使用編程語言來控制瀏覽器
  • 硒的webdriver: 它允許腳本直接與瀏覽器進行通信.
  • 硒網格: 它允許在不同的遠程機器上並行運行的睾丸.

現在讓我們來看看在硒腳本中使用的一些高級技巧

有效地利用'等待': 對於“等待”是最常見的解決方案 (要完成一些處理) 是使用了Thread.Sleep (). 但它沒有被證實的是,處理將在Thread.sleep代碼提到的指定時間內完成 (). So the solution is to use WebDriverWait class. It uses a mechanism to pool the query after a specified time period until the wait condition is fulfilled. This is also known as ‘explicit’ wait.

Keep environmental parameters in a text/xml file: It is always recommended to keep all your environmental parameters in a central text/xml file. And then parse the file to get the correct information. It helps your tests to be independent of a particular parameter/value.

JavaScript code execution: There are two ways of executing Java scripts, one is by using ExecuteScript () and the other one is ExecuteAsyncScript (). Use the first one, when your test logic has some dependency on the execution result. The second one can be used when there is no such dependency.

Perform Drag & Drop: Always use WebDriver’s Action Builder API for ‘Drag & Drop’ operations. The two methods are ‘DragAndDrop’ and ‘DragAndDropToOffset’. More low level ‘Drag & Drop’ can be performed but those techniques are rarely used.

Windows and iframe switching: Always use driver.SwitchTo ().Frame () and driver.SwitchTo ().Window () methods for switching between windows and iframes.

Passing keyboard input: There are two ways to pass the text to the selenium input elements. One is by using the JavaScript methods like ExecuteScript () / ExecuteAsyncScript (). The other way is to use SendKeys () 方法.

Closing browsers: Use WebDriver’s following APIs to close the browser after the test is complete.

  • Quit (): This is used to close all the browsers.
  • Close (): This is used to close the current browser
  • Dispose (): This will internally call Quit () method and has the same effect

硒作為一個測試套件是不斷發展的,它會在不久的將來,更多的新功能. 希望上面的提示將幫助您在運行測試硒更有效.

標籤:
============================================= ============================================== 在亞馬遜上購買最佳技術書籍,en,電工CT Chestnutelectric,en
============================================== ---------------------------------------------------------------- electrician ct chestnutelectric
error

Enjoy this blog? Please spread the word :)

Follow by Email
LinkedIn
LinkedIn
Share