Guest User

Untitled

a guest
Sep 19th, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. from behave import step, given, when, then
  2. from selenium.webdriver.common.by import By
  3.  
  4. TU = 'https://test.site'
  5.  
  6.  
  7. def get_by_xpath(context, path):
  8.     try:
  9.         element = context.browser.find_element(By.XPATH, path)
  10.     except:
  11.         element = None
  12.     return element
  13.  
  14.  
  15. #get website-based url
  16. @given('open site url {url}')
  17. def open_u01(context, url):
  18.     context.browser.get(url)
  19.     current_url = context.browser.current_url
  20.     assert current_url == url, 'url of the page does not match the expected. Received url:' + current_url
  21.  
  22. @when('input "{user_value}" in the "{field_name}" field')
  23. def open_u06(context, field_name, user_value, getxpath=False):
  24.  
  25.     xpath = ''
  26.    
  27.     path_dic = {
  28.         "Username":'//input[@id="username"]',
  29.         "Password":'//input[@id="password"]',
  30.         }
  31.  
  32.     if field_name in  path_dic:
  33.         xpath = path_dic[field_name]
  34.  
  35.     if xpath !='':
  36.         link = get_by_xpath(context, xpath)
  37.         link.send_keys(user_value)    
  38.    
  39.  
  40.  
  41.  
  42. if __name__ == '__main__':
  43.     from selenium import webdriver
  44.    
  45.     class cont():
  46.         browser = webdriver.Chrome()
  47.  
  48.     cont.username = "user"
  49.     cont.userpass = "password"
  50.  
  51.     open_u01(cont(), '/index.php')
  52.     open_u06(cont(), "Username", cont.username )
  53.     open_u06(cont(), "Password", cont.userpass )
  54.  
Add Comment
Please, Sign In to add comment