简体   繁体   中英

AttributeError: 'str' object has no attribute '__name__' Returned

I am looking to simply import a list of information via a CSV and to convert that into a simple action, however I'm getting the following error message:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sst/cases.py", line 217, in run_test_script
    exec(self.code, self.context)
  File "./randd/exec_tests.py", line 39, in <module>
    use_csv("randd/testcases/login.csv")
  File "./randd/exec_tests.py", line 31, in use_csv
    wait_for(action_input, locator_from_xpath(str(locator_input)))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sst/actions.py", line 146, in inner
    return func(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sst/actions.py", line 926, in wait_for
    return _wait_for(condition, False, _TIMEOUT, _POLL, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sst/actions.py", line 885, in _wait_for
    if config._current_test_assertion_count is not None and 'assert' in condition.__name__:
AttributeError: 'str' object has no attribute '__name__'

Below is the Python code being used:

# Import Libs
import logging
import csv
import sys
import testdata
from sst.actions import (run_test, go_to, click_element, assert_displayed, wait_for, write_textfield, sleep)
from sst.locators import (find_within, locator_from_css_selector, locator_from_xpath)

logger = logging.getLogger("CSVTests")

def use_csv(csv_file_path):

    #file = open(sys.argv[1], 'rb')
    file = open(csv_file_path, 'rb')
    testcase = csv.reader(file)
    next(testcase)

    for row in testcase:

        testcase_id = row[0]
        action_input = row[1]
        locator_input = row[2]
        detail = row[3]
        description = row[4]

        logger.debug(str(testcase_id))
        print(action_input)
        print(locator_input)

        # print(wait_for(action_input, locator_from_xpath(locator_input)))
        wait_for(action_input, locator_from_xpath(str(locator_input)))

    file.close()

# Goto Build
go_to(testdata.get_base_url())

# Run Tests
use_csv("randd/testcases/login.csv")

Please see below a snippet of the CSV:

TestCase ID,Action,Element / Locator,Option/Text/Result,Description
1,assert_displayed,"//body//div[@class='container-fluid']//div[contains(@class,'box')]",n/a,Checking that the login box is displayed.
2,assert_displayed,"//body//div[@class='container-fluid']//div[contains(@class,'box')]/div[@class='icon-holder']",n/a,Checking that the Frog icon is displayed.

The error occurs because in the sst library code there is an access to __name__ :

condition.__name__

And condition should not be a string object, but the current value received is actually a string.

My guess is that in your code, in the line:

wait_for(action_input, locator_from_xpath(str(locator_input)))

You dont' have to wrap locator_input into a str() , so:

wait_for(action_input, locator_from_xpath(locator_input))

should work

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