Skip to content

Commit

Permalink
test_selenium use YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
lovesoo committed Oct 25, 2017
1 parent 5254e82 commit 1cadb3c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 18 deletions.
15 changes: 9 additions & 6 deletions Tests/test_Selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@
from selenium import webdriver
import time

selenium_yml = '/config/selenium.yml'


class test_login(object):
def __init__(self):
pass

@classmethod
def setUpClass(cls):
site = ConfigUtil.get('site', path=selenium_yml)
cls.driver = webdriver.Chrome()
cls.driver.implicitly_wait(30)
cls.url = "http://mail.126.com"
cls.suffix = '@126.com'
cls.user = "tafffy"
cls.passwd = "lovesoo1314"
cls.title = u'网易'
cls.tips = u'帐号或密码错误'
cls.url = site['url']
cls.title = site['title']
cls.tips = site['tips']
cls.suffix = site['suffix']
cls.user = site['user']
cls.passwd = site['passwd']

@classmethod
def tearDownClass(cls):
Expand Down
6 changes: 4 additions & 2 deletions Util/commonTool/configUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ def get(cls, section, option='', path='/config/test.yml'):
filepath = ROOT + path
config = yaml.load(file(filepath, 'r'))
if option:
return str(config[section][option])
result = config[section][option]
else:
return str(config[section])
result = config[section]

return str(result) if isinstance(result, (str, unicode, int)) else result

@classmethod
def getint(cls, section, option='', path='/config/test.yml'):
Expand Down
25 changes: 15 additions & 10 deletions Util/seleniumTool/loginPageUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@

from selenium.webdriver.common.by import By
from basePageUtil import basePage
from Util import *

selenium_yml = '/config/selenium.yml'


class loginPage(basePage):
# 继承basePage类

loc = ConfigUtil.get('loc', path=selenium_yml)

# 定位器,通过元素属性定位元素对象
username_loc = (By.NAME, 'email')
password_loc = (By.NAME, 'password')
submit_loc = (By.ID, 'dologin')
span_loc = (By.ID, 'nerror')
dynpw_loc = (By.ID, 'lbDynPw')
userid_loc = (By.ID, 'spnUid')
logout_loc = (By.ID, '_mail_component_41_41')
username_loc = eval(loc['username_loc'])
password_loc = eval(loc['password_loc'])
submit_loc = eval(loc['submit_loc'])
span_loc = eval(loc['span_loc'])
dynpw_loc = eval(loc['dynpw_loc'])
userid_loc = eval(loc['userid_loc'])
logout_loc = eval(loc['logout_loc'])

# 操作
# 通过继承覆盖(Overriding)方法:如果子类和父类的方法名相同,优先用子类自己的方法。
Expand All @@ -28,11 +34,11 @@ def open(self):

# 输入用户名:调用send_keys对象,输入用户名
def input_username(self, username):
self.send_keys(self.username_loc,username,clear_first=True)
self.send_keys(self.username_loc, username, clear_first=True)

# 输入密码:调用send_keys对象,输入密码
def input_password(self, password):
self.send_keys(self.password_loc,password,clear_first=True)
self.send_keys(self.password_loc, password, clear_first=True)

# 点击登录:调用send_keys对象,点击登录
def click_submit(self):
Expand Down Expand Up @@ -60,4 +66,3 @@ def show_userid(self):
# 登陆退出:调用send_keys对象,点击退出
def click_logout(self):
self.find_element(self.logout_loc).click()

17 changes: 17 additions & 0 deletions config/selenium.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
site:
url: http://mail.126.com
title: 网易
tips: 帐号或密码错误
suffix: "@126.com"
user: tafffy
passwd: lovesoo1314

loc:
username_loc: (By.NAME, 'email')
password_loc: (By.NAME, 'password')
submit_loc: (By.ID, 'dologin')
span_loc: (By.ID, 'nerror')
dynpw_loc: (By.ID, 'lbDynPw')
userid_loc: (By.ID, 'spnUid')
logout_loc: (By.ID, '_mail_component_41_41')

0 comments on commit 1cadb3c

Please sign in to comment.