Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from behave import step, given, when, then
- from selenium.webdriver.common.by import By
- TU = 'https://test.site'
- def get_by_xpath(context, path):
- try:
- element = context.browser.find_element(By.XPATH, path)
- except:
- element = None
- return element
- #get website-based url
- @given('open site url {url}')
- def open_u01(context, url):
- context.browser.get(url)
- current_url = context.browser.current_url
- assert current_url == url, 'url of the page does not match the expected. Received url:' + current_url
- @when('input "{user_value}" in the "{field_name}" field')
- def open_u06(context, field_name, user_value, getxpath=False):
- xpath = ''
- path_dic = {
- "Username":'//input[@id="username"]',
- "Password":'//input[@id="password"]',
- }
- if field_name in path_dic:
- xpath = path_dic[field_name]
- if xpath !='':
- link = get_by_xpath(context, xpath)
- link.send_keys(user_value)
- if __name__ == '__main__':
- from selenium import webdriver
- class cont():
- browser = webdriver.Chrome()
- cont.username = "user"
- cont.userpass = "password"
- open_u01(cont(), '/index.php')
- open_u06(cont(), "Username", cont.username )
- open_u06(cont(), "Password", cont.userpass )
Add Comment
Please, Sign In to add comment