51Testing软件测试论坛
标题:
python + selenium 程序与数据分离
[打印本页]
作者:
zhyuping2002
时间:
2018-9-20 14:16
标题:
python + selenium 程序与数据分离
#python + selenium 程序与数据分离 开端
#userinfo.py 脚本
#!/usr/bin/python3
#coding=utf-8
def fun(un=username,pw=password):
print("success reader username and password!")
return(un,pw)
#login_python_userinfo_biaozhunhua.py 脚本
#!/usr/bin/python3
#coding=utf-8
from selenium import webdriver
import unittest,time
import os
from selenium.webdriver.common.keys import Keys
import userinfo #倒入userinfo.py函数
class login_python_userinfo(unittest.TestCase):
@classmethod
def setUpClass(self):
self.driver = webdriver.Firefox()
driver = self.driver
driver.get("http://www.baidu.com")
time.sleep(2)
print("打开百度网址成功")
driver.maximize_window()
driver.implicitly_wait(30)
def test_login(self):
self.us,self.pw = userinfo.fun()
print(self.us,self.pw)
driver = self.driver
driver.find_element_by_xpath("/html/body/div[1]/div[1]/div/div[3]/a[7]").click()
#try:
#element0 = driver.find_element_by_name("tj_login")
#for ele0 in element0:
#if ele0.is_displayed():
#ele0.click()
#except OSError as err:
# print("OS Error: {0}".format(err))
#except:
# print("click_error or find_name_error")
time.sleep(2)
print("点击登录按钮成功")
time.sleep(1)
driver.find_element_by_id("TANGRAM__PSP_10__footerULoginBtn").click()
print("点击 用户名登录 按钮")
time.sleep(1)
driver.find_element_by_id("TANGRAM__PSP_10__userName").send_keys(self.us)
driver.find_element_by_id("TANGRAM__PSP_10__password").send_keys(self.pw)
time.sleep(2)
driver.find_element_by_id("TANGRAM__PSP_10__submit").click()
print("登录成功")
time.sleep(5)
@classmethod
def tearDownClass(self):
self.driver.quit()
if __name__=='__main__':
unittest.main()
作者:
qqq911
时间:
2019-3-13 10:34
感谢分享
作者:
jingzizx
时间:
2019-3-13 12:11
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2