How to use site_url method in lettuce_webdriver

Best Python code snippet using lettuce_webdriver_python

TestWeb.py

Source:TestWeb.py Github

copy

Full Screen

1import urllib2import pytest3try:4 from selenium.webdriver.support.ui import WebDriverWait5 from selenium.webdriver.support.expected_conditions import staleness_of, title_is6 from selenium.common.exceptions import NoSuchElementException7except:8 pass9class WaitForPageLoad(object):10 def __init__(self, browser):11 self.browser = browser12 def __enter__(self):13 self.old_page = self.browser.find_element_by_tag_name('html')14 def __exit__(self, *args):15 WebDriverWait(self.browser, 10).until(staleness_of(self.old_page))16def getContextUrl(browser):17 return browser.execute_script("return window.location.toString()")18def getUrl(url):19 content = urllib.urlopen(url).read()20 assert "server error" not in content.lower(), "Got a server error! " + repr(url)21 return content22@pytest.mark.usefixtures("resetSettings")23@pytest.mark.webtest24class TestWeb:25 def testFileSecurity(self, site_url):26 assert "Not Found" in getUrl("%s/media/sites.json" % site_url)27 assert "Forbidden" in getUrl("%s/media/./sites.json" % site_url)28 assert "Forbidden" in getUrl("%s/media/../config.py" % site_url)29 assert "Forbidden" in getUrl("%s/media/1EU1tbG9oC1A8jz2ouVwGZyQ5asrNsE4Vr/../sites.json" % site_url)30 assert "Forbidden" in getUrl("%s/media/1EU1tbG9oC1A8jz2ouVwGZyQ5asrNsE4Vr/..//sites.json" % site_url)31 assert "Forbidden" in getUrl("%s/media/1EU1tbG9oC1A8jz2ouVwGZyQ5asrNsE4Vr/../../zeronet.py" % site_url)32 assert "Not Found" in getUrl("%s/raw/sites.json" % site_url)33 assert "Forbidden" in getUrl("%s/raw/./sites.json" % site_url)34 assert "Forbidden" in getUrl("%s/raw/../config.py" % site_url)35 assert "Forbidden" in getUrl("%s/raw/1EU1tbG9oC1A8jz2ouVwGZyQ5asrNsE4Vr/../sites.json" % site_url)36 assert "Forbidden" in getUrl("%s/raw/1EU1tbG9oC1A8jz2ouVwGZyQ5asrNsE4Vr/..//sites.json" % site_url)37 assert "Forbidden" in getUrl("%s/raw/1EU1tbG9oC1A8jz2ouVwGZyQ5asrNsE4Vr/../../zeronet.py" % site_url)38 assert "Forbidden" in getUrl("%s/1EU1tbG9oC1A8jz2ouVwGZyQ5asrNsE4Vr/../sites.json" % site_url)39 assert "Forbidden" in getUrl("%s/1EU1tbG9oC1A8jz2ouVwGZyQ5asrNsE4Vr/..//sites.json" % site_url)40 assert "Forbidden" in getUrl("%s/1EU1tbG9oC1A8jz2ouVwGZyQ5asrNsE4Vr/../../zeronet.py" % site_url)41 assert "Forbidden" in getUrl("%s/content.db" % site_url)42 assert "Forbidden" in getUrl("%s/./users.json" % site_url)43 assert "Forbidden" in getUrl("%s/./key-rsa.pem" % site_url)44 assert "Forbidden" in getUrl("%s/././././././././././//////sites.json" % site_url)45 def testLinkSecurity(self, browser, site_url):46 browser.get("%s/1EU1tbG9oC1A8jz2ouVwGZyQ5asrNsE4Vr/test/security.html" % site_url)47 WebDriverWait(browser, 10).until(title_is("ZeroHello - ZeroNet"))48 assert getContextUrl(browser) == "%s/1EU1tbG9oC1A8jz2ouVwGZyQ5asrNsE4Vr/test/security.html" % site_url49 # Switch to inner frame50 browser.switch_to.frame(browser.find_element_by_id("inner-iframe"))51 assert "wrapper_nonce" in getContextUrl(browser)52 assert browser.find_element_by_id("script_output").text == "Result: Works"53 browser.switch_to.default_content()54 # Clicking on links without target55 browser.switch_to.frame(browser.find_element_by_id("inner-iframe"))56 with WaitForPageLoad(browser):57 browser.find_element_by_id("link_to_current").click()58 assert "wrapper_nonce" not in getContextUrl(browser) # The browser object back to default content59 assert "Forbidden" not in browser.page_source60 # Check if we have frame inside frame61 browser.switch_to.frame(browser.find_element_by_id("inner-iframe"))62 with pytest.raises(NoSuchElementException):63 assert not browser.find_element_by_id("inner-iframe")64 browser.switch_to.default_content()65 # Clicking on link with target=_top66 browser.switch_to.frame(browser.find_element_by_id("inner-iframe"))67 with WaitForPageLoad(browser):68 browser.find_element_by_id("link_to_top").click()69 assert "wrapper_nonce" not in getContextUrl(browser) # The browser object back to default content70 assert "Forbidden" not in browser.page_source71 browser.switch_to.default_content()72 # Try to escape from inner_frame73 browser.switch_to.frame(browser.find_element_by_id("inner-iframe"))74 assert "wrapper_nonce" in getContextUrl(browser) # Make sure we are inside of the inner-iframe75 with WaitForPageLoad(browser):76 browser.execute_script("window.top.location = window.location")77 assert "wrapper_nonce" in getContextUrl(browser) # We try to use nonce-ed html without iframe78 assert "<iframe" in browser.page_source # Only allow to use nonce once-time79 browser.switch_to.default_content()80 def testRaw(self, browser, site_url):81 browser.get("%s/raw/1EU1tbG9oC1A8jz2ouVwGZyQ5asrNsE4Vr/test/security.html" % site_url)82 WebDriverWait(browser, 10).until(title_is("Security tests"))83 assert getContextUrl(browser) == "%s/raw/1EU1tbG9oC1A8jz2ouVwGZyQ5asrNsE4Vr/test/security.html" % site_url...

Full Screen

Full Screen

regen-map.py

Source:regen-map.py Github

copy

Full Screen

1#!/usr/bin/python2import json3import pprint4f = open('map.json', 'r')5file_data = f.read()6json_data = json.loads(file_data)7ex_list = [line.strip() for line in open('exclusive-list')]8# The following meta data is in the map.json for each building9#10#{u'address': u'24 Waverly Place, New York University, New York, NY 10003, USA',11# u'buildingcode': u'WAVE',12# u'description': u'',13# u'latitude': 40.730272,14# u'longitude': -73.995124,15# u'title': u'Waverly Building'}16# URL directory for NYU sites17site_url = dict()18site_url['Kimmel Center for University Life'] = 'http://www.nyu.edu/life/resources-and-services/kimmel-center.html'19site_url['Leslie Entrepreneurs Lab'] = 'http://www.nyu.edu/about/university-initiatives/entrepreneurship-at-nyu/leslie-elab.html'20site_url['NYU Card Center'] = 'http://www.nyu.edu/life/resources-and-services/nyu-card-and-campus-cash.html'21site_url['Public Safety - Administrative Office'] = 'http://www.nyu.edu/life/safety-health-wellness/be-safe/public-safety.html'22site_url['Silver Center for Arts and Science'] = 'http://as.nyu.edu/'23site_url['Graduate School of Arts and Science'] = 'http://gsas.nyu.edu/'24site_url['Wasserman Center for Career Development'] = 'http://www.nyu.edu/life/resources-and-services/career-development.html'25site_url['Coles Sports and Recreation Center'] = 'http://gonyuathletics.com/'26site_url['Market Place at Kimmel'] = 'http://www.nyu.edu/life/living-at-nyu/on-campus-living/dining.html'27site_url['Stern School of Business'] = 'http://www.stern.nyu.edu/'28site_url['Dibner Building'] = 'http://library.poly.edu/'29site_url['15 MetroTech Center'] = 'http://engineering.nyu.edu/campus-transformation/projects/15metrotech'30site_url['Othmer Residence Hall'] = 'http://www.nyu.edu/life/living-at-nyu/on-campus-living/explore-the-residencehalls/othmer-hall.html'31site_url['NYU Bookstore'] = 'http://bookstores.nyu.edu/'32site_url['Student Health Center'] = 'http://www.nyu.edu/life/safety-health-wellness/student-health-center.html'33site_url['Office of Global Services'] = 'http://www.nyu.edu/global/international-immigration-services.html'34site_url['Bobst Library'] = 'http://library.nyu.edu/'35site_url['Vanderbilt Hall, School of Law'] = 'http://www.law.nyu.edu/'36site_url['3 Washington Square Village'] = 'http://www.nyu.edu/life/living-at-nyu/on-campus-living/explore-the-residencehalls/grad-halls.html'37site_url['1 Washington Square Village'] = 'http://www.nyu.edu/life/living-at-nyu/on-campus-living/explore-the-residencehalls/grad-halls.html'38site_url['2 Washington Square Village'] = 'http://www.nyu.edu/life/living-at-nyu/on-campus-living/explore-the-residencehalls/grad-halls.html'39site_url['School of Professional Studies'] = 'http://sps.nyu.edu/'40site_url['Create a better NYU Hackathon'] = 'http://www.nyu.edu/about/leadership-university-administration/university-senate/membership/councils/student-senators-council/create-a-better-nyu-hackathon.html'41# IMG URL directory for NYU sites42img_url = dict()43img_url['Public Safety - Administrative Office'] = 'http://546d6b67f1a9d4b03ab3416c.simpleupload.junaio.com/data/nyu_security.jpg'44img_url['NYU Card Center'] = 'http://546d6b67f1a9d4b03ab3416c.simpleupload.junaio.com/data/nyu_security.jpg'45img_url['Stern School of Business'] = 'http://546d6b67f1a9d4b03ab3416c.simpleupload.junaio.com/data/nyu_stern.jpg'46img_url['NYU Bookstore'] = 'http://546d6b67f1a9d4b03ab3416c.simpleupload.junaio.com/data/nyu_bookstore.jpg'47img_url['15 MetroTech Center'] = 'http://546d6b67f1a9d4b03ab3416c.simpleupload.junaio.com/data/nyu_poly.jpg'48img_url['Dibner Building'] = 'http://546d6b67f1a9d4b03ab3416c.simpleupload.junaio.com/data/nyu_poly.jpg'49img_url['Create a better NYU Hackathon'] = 'http://546d6b67f1a9d4b03ab3416c.simpleupload.junaio.com/data/nyu-hackathon.png'50img_url['Wasserman Center for Career Development'] = 'http://546d6b67f1a9d4b03ab3416c.simpleupload.junaio.com/data/wasserman.png'51img_url['Student Health Center'] = 'http://546d6b67f1a9d4b03ab3416c.simpleupload.junaio.com/data/healthcenter.jpg'52img_url['Bobst Library'] = 'http://546d6b67f1a9d4b03ab3416c.simpleupload.junaio.com/data/bobst.jpg'53img_url['Dibner Building'] = 'http://546d6b67f1a9d4b03ab3416c.simpleupload.junaio.com/data/dibner.jpg'54idx = 055print '{"locations" : ['56for addr in json_data['locations']:57 id = addr['title']58 if id in ex_list:59 continue60 idx = idx + 161 if id in site_url:62 url = site_url[id]63 else:64 url = "http://www.nyu.edu"65 if id in img_url:66 imgurl = img_url[id]67 else:68 imgurl = "http://546d6b67f1a9d4b03ab3416c.simpleupload.junaio.com/data/nyu-small-icon.png"69 if (idx == 1):70 print '{"title" : "%s", "latitude" : %s, "longitude" : %s, "address" : "%s", "description" : "%s", "url" : "%s", "imgurl" : "%s" }' % (addr['title'], addr['latitude'], addr['longitude'], addr['address'], addr['description'], url, imgurl)71 else:72 print ',{"title" : "%s", "latitude" : %s, "longitude" : %s, "address" : "%s", "description" : "%s", "url" : "%s", "imgurl" : "%s" }' % (addr['title'], addr['latitude'], addr['longitude'], addr['address'], addr['description'], url, imgurl)...

Full Screen

Full Screen

rating_cache_task_loader.py

Source:rating_cache_task_loader.py Github

copy

Full Screen

...3# It also performs various validation checks and prints them 4# to make the tool easier to use.5import import_helpers.env_loader as env_loader6import sys7def sanitize_site_url(site_url):8 if '://' not in site_url:9 site_url = 'http://' + site_url10 if site_url[-1] == '/':11 site_url = site_url[:-1]12 return site_url13def is_local(site_url, env_data):14 if 'localhost' in site_url or '127.0.0.1' in site_url:15 return True16 if sanitize_site_url(site_url) == sanitize_site_url(env_data['APP_URL']):17 return True18 return False19def get_task_info():20 site_url = 'localhost:8000'21 env_data = env_loader.get_env_data()22 my_args = sys.argv[1:]23 is_resetting_cache = '--reset' in my_args24 my_args = list(set(my_args) - set(['--reset']))25 if len(my_args) < 1:26 if 'APP_URL' in env_data:27 site_url = env_data['APP_URL']28 print ('Using APP_URL from .env file: ' + site_url)29 else:30 print ('site_url should be specified. Defaulting to: ' + site_url)31 else:32 site_url = my_args[0]33 site_url = sanitize_site_url(site_url)34 if is_resetting_cache and not is_local(site_url, env_data):35 raise ValueError('Can not clear cache for remote site\'s database')36 result = {37 'site_url': site_url,38 'is_resetting_cache': is_resetting_cache,39 }40 for key in ['DB_PORT', 'DB_HOST', 'DB_DATABASE', 'DB_PASSWORD', 'DB_USERNAME']:41 result[key] = env_data[key]...

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