簡體   English   中英

AttributeError:在SST Python中執行時,“ NoneType”對象沒有屬性“名稱”

[英]AttributeError: 'NoneType' object has no attribute 'name' while executing in SST Python

僅限這種情況:在上一個問題中,我遇到了SST 0.2.4與Selenium 2.44.0不兼容的問題。 所以我降級到Selenium 2.43.0。 我現在有一個新的問題,我對此感到困惑。 我收到以下錯誤消息:

_StringException: Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\sst\cases.py", line 75, in setUp
self.start_browser()
  File "C:\Python27\lib\site-packages\sst\cases.py", line 107, in start_browser
logger.debug('Browser started: %s' % (self.browser.name))
AttributeError: 'NoneType' object has no attribute 'name'

它在Lib / SST文件夾中的case.py文件中引用的代碼如下:

    def start_browser(self):
    max_attempts = 5
    for nb_attempts in range(1, max_attempts):
        try:
            logger.debug('Starting browser (attempt: %d)' % (nb_attempts,))
            self._start_browser()
            break
        except exceptions.WebDriverException:
            if nb_attempts >= max_attempts:
                raise
    logger.debug('Browser started: %s' % (self.browser.name))

我的代碼如下所示:

import unittest
from sst.actions import *
from sst import cases, config, browsers

class TestMyTest(cases.SSTTestCase):

   def test_mytestcase_home_page(self):
    config.results_directory = "C:/Users/Brenda/test/SST-Test-Project/results"
    go_to('http://www.myhomepage.com')
    assert_title_contains('My Home Page')
    take_screenshot(filename='home_page.png',add_timestamp=True)
    assert_element(tag='a', text='Log in')

我一直認為解決這個問題的方法很簡單,但是似乎無法解決這個問題。

我還將添加一條注釋,即在命令行中運行sst-run MySSTTest時,似乎正在嘗試啟動瀏覽器而沒有成功。 我的代碼在節假日之前工作,那時好像已經壞了。

修改日期:2014年12月3日:我想補充一點,就是我可以在Chrome和IE中成功執行測試。 僅在Windows 7環境中,此問題與Firefox有關。 它已在Mac OS的所有3種瀏覽器中成功執行。

我認為cases.py代碼有可能在運行_start_browser時無法獲取瀏覽器對象

方法

def _start_browser(self):
    self.browser_factory.setup_for_test(self)
    self.browser = self.browser_factory.browser()

def start_browser(self):
    max_attempts = 5
    for nb_attempts in range(1, max_attempts):
        try:
            logger.debug('Starting browser (attempt: %d)' % (nb_attempts,))
            self._start_browser()
            break
        except exceptions.WebDriverException:
            if nb_attempts >= max_attempts:
                raise
    logger.debug('Browser started: %s' % (self.browser.name))
  • 主要問題: if nb_attempts >= max_attempts:無效。 nb_attempts僅上升到max_attempts-1 我將使用continue並在else子句中重新引發異常:

     logger.debug('Starting browser') e = None for _ in range(max_attempts): try: self._start_browser() break except exceptions.WebDriverException,e: continue else: raise e 

    (“ _ ”是未使用變量的慣用語)

  • 即使與修復, self.browser仍然可以None如果browser_factory.browser()返回None

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM