本文整理汇总了Python中robot.libraries.BuiltIn.BuiltIn类的典型用法代码示例。如果您正苦于以下问题:Python BuiltIn类的具体用法?Python BuiltIn怎么用?Python BuiltIn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BuiltIn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: input_value_on_next_prompt
def input_value_on_next_prompt(self, value=None):
"""模拟prompt窗口输入value后点击ok的情况,同时记录窗口中的message。
不输入value参数时,则模拟prompt窗口在默认值情况下被点击ok的情况。
当页面存在window.prompt()时,必须在prompt窗口出现前使用该关键字。
每次有新页面加载之后必须重新调用这个关键字才会生效。
"""
s2l = BuiltIn().get_library_instance('Selenium2Library')
if value is None:
js = """
window.prompt = function(message, defaultValue) {
lastPopupMessage = message;
return defaultValue;
}
"""
s2l.execute_javascript('%s' % js)
else:
js_prefix = """
window.prompt = function(message, defaultValue) {
lastPopupMessage = message;
return '"""
js_suffix = "';}"
s2l.execute_javascript('%s%s%s' % (js_prefix, value, js_suffix))
示例2: report_sauce_status
def report_sauce_status(name, status, tags=[], remote_url=''):
# Parse username and access_key from the remote_url
assert USERNAME_ACCESS_KEY.match(remote_url), 'Incomplete remote_url.'
username, access_key = USERNAME_ACCESS_KEY.findall(remote_url)[0][1:]
# Get selenium session id from the keyword library
selenium = BuiltIn().get_library_instance('Selenium2Library')
job_id = selenium._current_browser().session_id
# Prepare payload and headers
token = (':'.join([username, access_key])).encode('base64').strip()
payload = {'name': name,
'passed': status == 'PASS',
'tags': tags}
headers = {'Authorization': 'Basic {0}'.format(token)}
# Put test status to Sauce Labs
url = 'https://saucelabs.com/rest/v1/{0}/jobs/{1}'.format(username, job_id)
response = requests.put(url, data=json.dumps(payload), headers=headers)
assert response.status_code == 200, response.text
# Log video url from the response
video_url = json.loads(response.text).get('video_url')
if video_url:
logger.info('<a href="{0}">video.flv</a>'.format(video_url), html=True)
示例3: open_pyrobot
def open_pyrobot(arglist, opt_arg=""):
seleniumlib = BuiltIn().get_library_instance('Selenium2Library')
if hasattr(arglist, 'lower'):
print '(open_pybot) solo'
if opt_arg == "":
target_browser = os.environ[envname_pyrobot_default_browser]
else:
if not opt_arg in SELENIUM2LIB_BROWSERS:
raise ValueError(opt_arg + " is not a supported browser.")
target_browser = opt_arg
print '%s (%s)' % (arglist, opt_arg)
seleniumlib.open_browser(arglist, browser=target_browser)
else:
print '(open_pybot) sauce'
if opt_arg == "":
url = arglist[0]
elif "http" in opt_arg:
url = opt_arg
else:
raise ValueError(opt_arg + " is not a valid url.")
print '[%s] url(%s)' % (', '.join(map(str, arglist)), url)
seleniumlib.open_browser(url, browser=os.environ[envname_pyrobot_default_browser], remote_url=arglist[2], desired_capabilities=arglist[3])
# def open_browser(url, browser=None, remote=None, caps=None):
# seleniumlib = BuiltIn().get_library_instance('Selenium2Library')
# seleniumlib.open_browser(url, remote_url=remote, desired_capabilities=caps)
示例4: CapwapLibrary
class CapwapLibrary(object):
"""Provide many methods to simulate WTPs and their functions."""
def __init__(self):
self.builtin = BuiltIn()
def send_discover(self, ac_ip, wtp_ip='', ip='ip', port=5246):
"""Send Discover CAPWAP Packet from a WTP."""
data = ''.join(chr(x) for x in [0x00, 0x20, 0x01, 0x02, 0x03, 0x04, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
self.builtin.log('Sending Discover Packet to: %s' % ac_ip, 'DEBUG')
session = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
session.sendto(data, (ac_ip, port))
self.builtin.log('Packet Sent', 'DEBUG')
def get_hostip(self):
"""Get Host IP Address."""
ip_addr = socket.gethostbyname(socket.gethostname())
return ip_addr
def get_simulated_wtpip(self, controller):
"""Get the Simulated WTP ip based on the controller."""
if controller == '127.0.0.1':
exp_ip = controller
else:
exp_ip = self.get_hostip()
return exp_ip
示例5: test_log_directory
def test_log_directory():
"""This function will create case log directory for saving TA log when you call it firstly.
If you want to save or use TA log, you must call this keyword on your TA case.
"""
global TEST_CASE_NAME
global TEST_LOG_PATH
try:
test_case_name = BuiltIn().get_variables()['${TEST_NAME}']
except:
try:
test_case_name = BuiltIn().get_variables()['${SUITE_NAME}']
except:
test_case_name = "mt_case_name"
test_case_name = test_case_name.strip().replace(" ", "_")
if TEST_CASE_NAME != test_case_name:
try:
output_dir = BuiltIn().get_variables()['${OUTPUT_DIR}']
except:
output_dir = "mt_output_dir"
test_suite_path = os.path.join(output_dir, "log")
TEST_CASE_NAME = test_case_name
test_name_with_timestamp = test_case_name + "_" + time.strftime("%Y%m%d%H%M%S", time.localtime()) + "/"
test_log_directory = os.path.join(test_suite_path, test_name_with_timestamp)
TEST_LOG_PATH = test_log_directory
if not os.path.exists(TEST_LOG_PATH):
os.makedirs(TEST_LOG_PATH)
return TEST_LOG_PATH
示例6: demo_title_should_be
def demo_title_should_be(self,expected):
# a demo by YT for implemnting the same function as 'Title Should Be'
seleniumlib = BuiltIn().get_library_instance('Selenium2Library')
title = seleniumlib.get_title()
if not title.startswith(expected):
raise AssertionError("Title '%s' did not start with '%s'"
% (title, expected))
示例7: capture_and_mask_page_screenshot
def capture_and_mask_page_screenshot(self, filename, locators=None,
rects=None):
'''
Captures page screenshot and masks specified element.
'''
s2l = BuiltIn().get_library_instance('Selenium2Library')
# note: filename is required because otherwise we don't have reference to
# auto-generated filename
s2l.capture_page_screenshot(filename)
rectangles = []
for locator in locators or []:
element = s2l._element_find(locator, True, False)
if element is None:
raise AssertionError("Could not locate element for '%s'" % (locator))
x, y = element.location['x'], element.location['y']
w, h = element.size['width'], element.size['height']
rectangles.append([x, y, x+w, y+h])
for rect in rects or []:
try:
x, y, w, h = [int(i) for i in rect.split(',')]
rectangles.append([x, y, x+w, y+h])
except:
raise AssertionError("Could not locate rectangle for '%s'" % (rect))
self.mask_image(filename, rectangles)
示例8: is_element_present
def is_element_present(self, locator):
"""Same than Page Should Contain Element but returns a boolean """
selenium2lib = BuiltIn().get_library_instance('Selenium2Library')
try:
return selenium2lib.page_should_contain_element(locator)
except AssertionError:
return False
示例9: is_visible
def is_visible(self, locator):
"""Same than Element Should Be Visible but returns a boolean """
selenium2lib = BuiltIn().get_library_instance('Selenium2Library')
try:
return selenium2lib.element_should_be_visible(locator)
except AssertionError:
return False
示例10: press_control_and_key
def press_control_and_key(self,locator,key):
"""Presses the control Key and Specified key 'key' at element located by the 'locator' """
selenium = BuiltIn().get_library_instance('Selenium2Library')
loc = selenium._element_find(locator,True,True)
loc.send_keys(Keys.CONTROL, 'a')
time.sleep(1)
loc.send_keys(Keys.CONTROL,key)
time.sleep(1)
示例11: report_sauce_status
def report_sauce_status(name, status):
selenium = BuiltIn().get_library_instance('Selenium2Library')
job_id = selenium._current_browser().session_id
passed = status == 'PASS'
sauce_client.jobs.update_job(job_id, passed = passed, name = name)
sessionId = "SauceOnDemandSessionID=%s job-name=%s" % (job_id, name)
print sessionId
return sessionId
示例12: get_columnvalues
def get_columnvalues(self,table_locator,columnName,icount):
selenium = BuiltIn().get_library_instance('Selenium2Library')
columnNo = int(self.table_get_column_no(table_locator,columnName))
list1=[]
for iRow in range(4,15):
list2=selenium.get_text('//span[contains(text(),"Available Students")]//following::div//div//table//th[5]//following::div['+str(iRow)+']//table//td['+str(columnNo)+']')
list1.append(list2)
return list1
示例13: get_element_text
def get_element_text(self, element, child):
"""Returns the text found at the 'child' of the 'element' """
selenium = BuiltIn().get_library_instance("Selenium2Library")
id = selenium.get_element_attribute(element + "@id")
print "id:" + str(id)
return selenium.execute_javascript(
'return document.getElementById("' + id + '").childNodes[' + str(child) + "].textContent"
)
示例14: get_items_in_context_menu
def get_items_in_context_menu(self, locator):
"""Returns the text from the context menu located by 'locator' """
selenium = BuiltIn().get_library_instance("Selenium2Library")
return selenium.execute_javascript(
"return document.getElementById('dashMenu_4').getElementsByTagName'div')[1].getElementsByClassName('rich-menu-item rich-menu-item-enabled')["
+ str(locator)
+ "].getElementsByTagName('span')[1].textContent"
)
示例15: report_saucelabs_status
def report_saucelabs_status(name, status, tags=[], remote_url=''):
# Parse username and access_key from the remote_url
assert USERNAME_ACCESS_KEY.match(remote_url), 'Incomplete remote_url.'
username, access_key = USERNAME_ACCESS_KEY.findall(remote_url)[0][1:]
# Get selenium session id from the keyword library
selenium = BuiltIn().get_library_instance('Selenium2Library')
job_id = selenium._current_browser().session_id