Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matchers.py assert_text_present #50

Open
stevenerat opened this issue Jan 29, 2014 · 0 comments
Open

Matchers.py assert_text_present #50

stevenerat opened this issue Jan 29, 2014 · 0 comments

Comments

@stevenerat
Copy link

Using 0.63, I found that the locator block in Matchers's assert_text_present fails for me because it is not prefixed with self.

Code:
e = driver.find_element_by_tag_name('body')
assert text in e.text

Error:
File "/Library/Python/2.7/site-packages/py.saunter-0.63-py2.7.egg/saunter/matchers.py", line 345, in assert_text_present
e = driver.find_element_by_tag_name('body')
NameError: global name 'driver' is not defined

Fixing that to be ...
e = self.driver.find_element_by_tag_name('body')

... resolved that error, but something was odd in the timing because my test was passing yet my WebUI threw a handled exception in a popup, perhaps something timing related, but reproducible every time in pysaunter, but not when manually testing.

So, I modified the locator usage (and added some handling to raise an assertion error) with the following, and this works for me every time.

    if isinstance(self.driver, tailored.remotecontrol.RemoteControl):
        assert self.driver.is_text_present(text)
    else:
        try:
            locator = ("xpath=//*[contains(text(), '%s')]") % text
            self.driver.find_element_by_locator(locator)
            return True
        except:
            if len(msg) == 0:
                raise AssertionError('Text "%s" was not found.' % text)
            else:
                raise AssertionError('Text "%s" was not found.  %s' % (text,msg))
stevenerat added a commit to stevenerat/py.saunter that referenced this issue Jan 29, 2014
stevenerat added a commit to stevenerat/py.saunter that referenced this issue Jan 29, 2014
stevenerat added a commit to stevenerat/py.saunter that referenced this issue Jan 29, 2014
Merging fix for the upstream issue Element-34#50 to my master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant