简体   繁体   中英

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

THIS OCCURS IN FIREFOX ONLY: In a previous question, I had run into the issue where SST 0.2.4 is not compatible with Selenium 2.44.0. So I downgraded to Selenium 2.43.0. I now have a new issue that I'm confused about. I'm receiving the following error message:

_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'

The code that it is referencing in the cases.py file in the Lib/SST folder is below:

    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))

My code looks like the following:

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')

I keep thinking that the solution to this is fairly simple, but I can't seem to wrap my head around it.

I'll also add the note that when running sst-run MySSTTest in the command line, it looks like it is attempting to start the browser without success. My code was working prior to the holiday break at which time it seems to have broken.

EDITED 3-Dec-2014: I wanted to add that I can successfully execute the test in Chrome and IE. This issue is with Firefox ONLY in a Windows 7 environment. It was successfully executed on a Mac OS in all 3 browsers.

I think cases.py codes has possibility cannot get browser object when it runs _start_browser

method

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))
  • The main problem: if nb_attempts >= max_attempts: has no effect. nb_attempts only goes up to max_attempts-1 . I would use continue and re-raise the exception in an else clause instead:

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

    (" _ " is an idiom for an unused variable)

  • Even with that fix, self.browser can still be None if browser_factory.browser() returns None .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM