-----------------
一、数学相关
1、绝对值:abs(-1)
2、最大最小值:max([1,2,3])、min([1,2,3])
3、序列长度:len('abc')、len([1,2,3])、len((1,2,3))
4、取模:divmod(5,2)
5、乘方:pow(2,3)
6、浮点数:round(1)
二、功能相关
1、函数是否可调用:callable(funcname),注意,funcname变量要定义过
2、类型判断:isinstance(x,list/int)
3、比较:cmp('hello','hello')
4、快速生成序列:(x)range([start,] stop[, step])
三、类型转换
1、int(x)
2、long(x)
3、float(x)
4、complex(x) //复数
5、str(x)
6、list(x)
7、tuple(x) //元组
8、hex(x)
9、oct(x)
10、chr(x)//返回x对应的字符,如chr(65)返回‘A'
11、ord(x)//返回字符对应的ASC码数字编号,如ord('A')返回65
四、字符串处理
1、首字母大写:str.capitalize
>>> 'hello'.capitalize()
'Hello'
2、字符串替换:str.replace
>>> 'hello'.replace('l','2')
'he22o'
可以传三个参数,第三个参数为替换次数
3、字符串切割:str.split
>>> 'hello'.split('l')
['he', '', 'o']
可以传二个参数,第二个参数为切割次数
以上三个方法都可以引入String模块,然后用string.xxx的方式进行调用。
……
enumerate,eval 等常用的参数可以去看看了解一些
---------------------------
# coding=utf-8 from selenium import webdriver import time profile_path = r'C:\Users\songping\AppData\Roaming\Mozilla\Firefox\Profiles\gjihjypg.default' profile = webdriver.FirefoxProfile(profile_path) driver = webdriver.Firefox(profile) url = "http://192.168.0.101/phpwind/admin.php#initiator" driver.get(url) time.sleep(5) driver.find_element_by_name("admin_name").send_keys("admin") driver.find_element_by_name("admin_pwd").send_keys("123456") driver.find_element_by_name("submit").click() #登录成功之后 login_xpath = 'html/body/table/tbody[1]/tr[1]/td/div/div/p/a[2]' result =driver.find_element_by_xpath(login_xpath).text print("获取到的登录结果:%s"%result) assert result == "[注销]"
def login(driver, user="admin", psw="123456"): driver.find_element_by_name("admin_name").send_keys(user) driver.find_element_by_name("admin_pwd").send_keys(psw) driver.find_element_by_name("submit").click()
在test_case里建立测试用例: from selenium import webdriver import time import unittest from t7.login_page import login class TestLogin(unittest.TestCase): def setUp(self): profile_path = r'C:\Users\songping\AppData\Roaming\Mozilla\Firefox\Profiles\gjihjypg.default' profile = webdriver.FirefoxProfile(profile_path) self.driver = webdriver.Firefox(profile) self.driver.get("http://192.168.0.101/phpwind/admin.php#initiator") login(self.driver) def tearDown(self): self.driver.quit() def test_01(self): login(self.driver)
------------------------- 把登录的方法变成类的形式:新建login_clas_page class Login(): def __init__(self,driver): self.driver = driver def login(self, user="admin", psw="123456"): driver.find_element_by_name("admin_name").send_keys(user) driver.find_element_by_name("admin_pwd").send_keys(psw) driver.find_element_by_name("submit").click() if __name__ == '__main__': # 测试自己的代码 from selenium import webdriver profile_path = r'C:\Users\songping\AppData\Roaming\Mozilla\Firefox\Profiles\gjihjypg.default' profile = webdriver.FirefoxProfile(profile_path) driver = webdriver.Firefox(profile) url = "http://192.168.0.101/phpwind/admin.php#initiator" driver.get(url) # 类的调用 x = Login(driver) # 示例化 x.login() # 调用方法
from selenium import webdriver import time import unittest from t7.login_clas_page import login class TestLogin(unittest.TestCase): def setUp(self): profile_path = r'C:\Users\songping\AppData\Roaming\Mozilla\Firefox\Profiles\gjihjypg.default' profile = webdriver.FirefoxProfile(profile_path) self.driver = webdriver.Firefox(profile) self.driver.get("http://192.168.0.101/phpwind/admin.php#initiator") login(self.driver) def tearDown(self): self.driver.quit() def test_01(self): login(self.driver)
标签:profile,10,函数,python,self,driver,admin,login,name From: https://www.cnblogs.com/pingzi66-ww/p/17100277.html