2015-06-26 91 views
0

我使用硒自動化測試用例網絡超時問題,但是到目前爲止測試是片狀由於網絡問題(緩慢等)。這導致很多失敗的測試用例。目前,重新運行失敗的測試用例是服用大量的時間,使得自動化效率非常低,而不是手動測試。 有沒有一種方法,使測試比增加隱性和顯性超時更加動態等。Selenium測試和

在此先感謝

回答

0

到目前爲止,我處理這個問題的方法是寫一個輔助函數來包裝WebDriverWait,所以它並不像繁重的使用。

下面是一個使用webdriver的Python綁定一個例子:

# Import EC: 
from selenium.webdriver.support import expected_conditions as EC 

# Then define the helper: 
def wait_for_clickability_then_click_element(self, by, locator, timeout=5): 
    WebDriverWait(self.driver, timeout).until(EC.element_to_be_clickable((
      by, locator))) 
    if by == By.XPATH: 
     self.driver.febx(locator).click() 
    elif by == By.CSS_SELECTOR: 
     self.driver.febc(locator).click() 

一個例子調用(你可能會代替正常的點擊使用()調用運行到時間問題)可能看起來像:

wait_for_clickability_then_click_element(
    By.CSS_SELECTOR, "button[name='submit']")