您的位置:軟件測(cè)試 > 開(kāi)源軟件測(cè)試 > 開(kāi)源功能測(cè)試工具 > Selenium
Some selenium tips關(guān)于Selenium的小竅門(mén)
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2013/4/7 15:55:26 ] 推薦標(biāo)簽:

  Watch out the outdated articles on the internet.

  當(dāng)心網(wǎng)上那些過(guò)時(shí)的文章

  Selenium 2.0 is completely different from Selenium 1.x. Selenium 2.0 is also called the selenium webdriver. So always add the keyword webdriver when googling for answers to your selenium related questions.

  Selenium 2.0與Selenium 1.x有非常大的差別。Selenium 2.0 通常也別叫做 selenium webdriver。所以在你google selenium 相關(guān)的問(wèn)題的時(shí)候,都請(qǐng)加上 webdriver 這個(gè)關(guān)鍵字。

  Implement the web UI in a modular way so it's more selenium testable.

  用模塊化的方式來(lái)實(shí)現(xiàn)Web的UI會(huì)提高用Selenium測(cè)試的可測(cè)性

  Modularize your view logic so that you only update the part of DOM that is needed to change when your models change. If you tend to re-create a bigger part of the DOM than necessary, it's not only a waste but also could introduce risk to your functional tests written in Selenium.

  模塊化你的View邏輯,這樣做的好處是,當(dāng)你要更改你的Models時(shí),你只需要更新部分的DOM即可。如果你嘗試重新創(chuàng)建一個(gè)比需要更大的DOM,這不但是一種浪費(fèi),而且會(huì)引入使你的Selenium 功能測(cè)試腳本出現(xiàn)不能正常工作風(fēng)險(xiǎn)。

  Reduce unnecessary dependency on DOM structure, make element locating logic as simple as possible.

  減少對(duì)DOM結(jié)構(gòu)不必要的依賴,元素定位邏輯的越簡(jiǎn)單越好

  When you need to locate an element, try not rely on the DOM structure too much - for example, using code logic to locate element is the most risky one. The best approach is probably to always use a scoped CSS selector with 1 or 2 levels of IDs, And if you can locate it in one selector, don't do it in two. For example

  請(qǐng)盡量不要使用DOM的結(jié)構(gòu)來(lái)定位頁(yè)面元素,例如,用代碼邏輯來(lái)定位元素是風(fēng)險(xiǎn)大的。定位元素好的方式是用1 到2級(jí)的CSS selector,如果一個(gè)selector 能定位,不要用兩個(gè), 例如

  label = driver.find_element("#info-panel #name-label")

  is more robust than

  比以下的方法健壯

  panel = driver.find_element("#info-panel")

  label = panel.find_element("#name-label")

  Do wait in selenium the smart way.

  恰當(dāng)?shù)厥褂肳ait

  Don't use implicit wait blindly. Implicit wait makes sense when you use find_element to find one element. But when you try to locate multiple elements by driver.find_elements, the driver will always wait the whole timeout period if implicit wait is set. That might not be what you always want. I usually write my own safe find_element method. Here is an example in the base class of my page objects:

  不要盲目地使用隱式等待。當(dāng)你使用find_element的時(shí)候去找某一個(gè)元素時(shí),使用隱式等待是合適的,但是當(dāng)你嘗試用 driver.find_elements 去定位多個(gè)元素時(shí),如果設(shè)置了隱式等待,那么drivers 總是會(huì)等待整個(gè)超時(shí)周期。這往往不是你想要的效果。我通常會(huì)自己去寫(xiě)一個(gè)安全的 find_element 方法。以下例子展示了我頁(yè)面對(duì)象的基類(lèi)

  def s selector

  wait_until { @driver.find_element css: selector }

  end

  def wait_until(&block)

  wait = Selenium::WebDriver::Wait.new(timeout: 10, interval: INTERVAL)

  wait.until &block

  end

  So that I can write the following code in my page object

上一頁(yè)12下一頁(yè)
軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠(chéng)聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd