How to use contains_content method in lettuce_webdriver

Best Python code snippet using lettuce_webdriver_python

webdriver.py

Source:webdriver.py Github

copy

Full Screen

...19 WebDriverException)20from nose.tools import assert_equals21# pylint:disable=missing-docstring,redefined-outer-name22from css_selector_steps import *23def contains_content(browser, content):24 # Search for an element that contains the whole of the text we're looking25 # for in it or its subelements, but whose children do NOT contain that26 # text - otherwise matches <body> or <html> or other similarly useless27 # things.28 for elem in browser.find_elements_by_xpath(unicode(29 u'//*[contains(normalize-space(.),"{content}") '30 u'and not(./*[contains(normalize-space(.),"{content}")])]'31 .format(content=content))):32 try:33 if elem.is_displayed():34 return True35 except StaleElementReferenceException:36 pass37 return False38@wait_for39def wait_for_elem(browser, xpath):40 return browser.find_elements_by_xpath(str(xpath))41@wait_for42def wait_for_content(browser, content):43 return contains_content(browser, content)44## URLS45@step('I visit "(.*?)"$')46def visit(step, url):47 with AssertContextManager(step):48 world.browser.get(url)49@step('I go to "(.*?)"$')50def goto(step, url):51 step.given('I visit "%s"' % url)52## Links53@step('I click "(.*?)"$')54def click(step, name):55 with AssertContextManager(step):56 elem = world.browser.find_element_by_link_text(name)57 elem.click()58@step('I click by id "(.*?)"$')59def click_by_id(step, id_name):60 with AssertContextManager(step):61 elem = world.browser.find_element_by_xpath(str('id("%s")' % id_name))62 elem.click()63@step('I should see a link with the url "(.*?)"$')64def should_see_link(step, link_url):65 assert_true(step, world.browser.66 find_element_by_xpath(str('//a[@href="%s"]' % link_url)))67@step('I should see a link to "(.*?)" with the url "(.*?)"$')68def should_see_link_text(step, link_text, link_url):69 assert_true(step,70 world.browser.find_element_by_xpath(str(71 '//a[@href="%s"][./text()="%s"]' %72 (link_url, link_text))))73@step('I should see a link that contains the text "(.*?)" '74 'and the url "(.*?)"$')75def should_include_link_text(step, link_text, link_url):76 return world.browser.find_element_by_xpath(str(77 '//a[@href="%s"][contains(., "%s")]' %78 (link_url, link_text)))79## General80@step('The element with id of "(.*?)" contains "(.*?)"$')81def element_contains(step, element_id, value):82 return world.browser.find_element_by_xpath(str(83 'id("{id}")[contains(., "{value}")]'.format(84 id=element_id, value=value)))85@step('The element with id of "(.*?)" does not contain "(.*?)"$')86def element_not_contains(step, element_id, value):87 elem = world.browser.find_elements_by_xpath(str(88 'id("{id}")[contains(., "{value}")]'.format(89 id=element_id, value=value)))90 assert_false(step, elem)91@wait_for92def wait_for_visible_elem(browser, xpath):93 elem = browser.find_elements_by_xpath(str(xpath))94 if not elem:95 return False96 return elem[0].is_displayed()97@step(r'I should see an element with id of "(.*?)" within (\d+) seconds?$')98def should_see_id_in_seconds(step, element_id, timeout):99 elem = wait_for_visible_elem(world.browser, 'id("%s")' % element_id,100 timeout=int(timeout))101 assert_true(step, elem)102@step('I should see an element with id of "(.*?)"$')103def should_see_id(step, element_id):104 elem = world.browser.find_element_by_xpath(str('id("%s")' % element_id))105 assert_true(step, elem.is_displayed())106@step('I should not see an element with id of "(.*?)"$')107def should_not_see_id(step, element_id):108 try:109 elem = world.browser.find_element_by_xpath(str('id("%s")' %110 element_id))111 assert_true(step, not elem.is_displayed())112 except NoSuchElementException:113 pass114@step(r'I should see "([^"]+)" within (\d+) seconds?$')115def should_see_in_seconds(step, text, timeout):116 assert_true(step,117 wait_for_content(world.browser, text, timeout=int(timeout)))118@step('I should see "([^"]+)"$')119def should_see(step, text):120 assert_true(step, contains_content(world.browser, text))121@step('I see "([^"]+)"$')122def see(step, text):123 assert_true(step, contains_content(world.browser, text))124@step('I should not see "([^"]+)"$')125def should_not_see(step, text):126 assert_true(step, not contains_content(world.browser, text))127@step('I should be at "(.*?)"$')128def url_should_be(step, url):129 assert_true(step, url == world.browser.current_url)130## Browser131@step('The browser\'s URL should be "(.*?)"$')132def browser_url_should_be(step, url):133 assert_true(step, url == world.browser.current_url)134@step('The browser\'s URL should contain "(.*?)"$')135def url_should_contain(step, url):136 assert_true(step, url in world.browser.current_url)137@step('The browser\'s URL should not contain "(.*?)"$')138def url_should_not_contain(step, url):139 assert_true(step, url not in world.browser.current_url)140## Forms...

Full Screen

Full Screen

base.py

Source:base.py Github

copy

Full Screen

1# coding=UTF-82from __future__ import unicode_literals3from django.conf import settings4from cubane.tests.base import CubaneTestCase5from cubane.lib.file import file_get_contents6import os7import shutil8import glob9@CubaneTestCase.complex()10class ManagementTestCaseBase(CubaneTestCase):11 def setUp(self):12 # favicon13 favicon = os.path.join(settings.PUBLIC_HTML_ROOT, 'favicon.ico')14 if os.path.isfile(favicon):15 os.remove(favicon)16 # favicons versions17 favicons = os.path.join(settings.STATIC_ROOT, 'cubane', 'favicons')18 if os.path.isdir(favicons):19 shutil.rmtree(favicons)20 # compressed resources21 for filename in glob.glob(os.path.join(settings.STATIC_ROOT, '*')):22 if os.path.isfile(filename):23 os.remove(filename)24 def _assertStaticFile(self, filename, contains_content=None):25 path = os.path.join(settings.STATIC_ROOT, filename)26 self.assertTrue(os.path.isfile(path), 'expected file to exist: %s' % path)27 if contains_content:...

Full Screen

Full Screen

login.py

Source:login.py Github

copy

Full Screen

...9 login = context.login.signin(USER[user_type]['email'], USER[user_type]['pass'])10 assert login11@then(u'a login error message should display')12def step_impl(context):13 message = context.browser.contains_content(14 LoginPage.locator_dictionary['error_message'], 5)15 assert message16@then(u'the user should be redirected to homepage')17def homepage(context):18 home = context.browser.contains_content(USER['valid']['username'], 10)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lettuce_webdriver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful