控制层
测试用例层:
控制层示例代码:
#coding=utf-8
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import os
def su(self,ss,CI,action):#函数封装
I=1
ic=-1
while I < CI:#3种定位是5\2-4\1-3
if I==CI-1:#比上面的I少1
assert False,"找不到元素"
ic=ic+1
I=I+1
try:
print type(I)
eval("WebDriverWait(self.dr,5,0.5).until(EC.presence_of_element_located((By."+ss[ic]+")))"+"."+action)
break
except:
pass
def X002(self,action):#定位元素
ss=["ID,'kw2'","XPATH,'wd'","NAME,'wd'"] #三种定位方式,优先从左往右排序
su(self,ss,5,action)
测试用例层示例代码:
# coding=utf-8
from selenium import webdriver
import unittest
import X33
import time
class AAA(unittest.TestCase):
def setUp(self):
self.dr=webdriver.Chrome()
self.dr.get("http://baidu.com")
def test_001(self):
X33.X002(self,"send_keys('selenium')")
if __name__ =="__main__":
unittest.main()