RobotFramework自定义Library
RobotFramework是开源的项目,我们可以根据项目需要,对RF进行二次开发,比如可以自定义关键字库。
本文自定义了一个叫NewLibrary的库
C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Lib\site-packages\NewLibrary
在\Lib\site-packages\目录下创建一个NewLibrary文件夹,并且新增两个py文件:init.py , myclass.py
文件的内容如下:__init__.py
from myclass import MyClass
class NewLibrary(MyClass):
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
myclass.py
from selenium import webdriver
import time
class MyClass(object):
def __init__(self):
pass
def printMsg(self, msg):
print("hello" + msg)
def SlideTieBa(self):
browser = webdriver.Chrome()
browser.implicitly_wait(30)
browser.get("https://tieba.baidu.com/")
browser.maximize_window()
Listcookie = [{'name':"STOKEN",'value':"3c6363cb0bede0cfd3ab8126b2700ad471e491ce0cc56a40f147f6995"}
,{'name':"BDUSS",'value':"RzOVVQY09oaXAyeGFETTJIS3lXU2lUWk9iYTBtRUxjSmRIYmswZ3c2aDFsNFplRVFBQUFBJAAAEAAABEE-sk1Nm4x9K7wqUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHUKX151Cl9eVz"}]
for cookie in Listcookie:
browser.add_cookie(cookie)
browser.get("https://tieba.baidu.com/")
browser.refresh()
for i in range(1000):
t = i
#tt = 'window.scrollBy(0,' + str(t) + ')'
tt = 'window.scrollBy(0,1)'
print(tt)
browser.execute_script(tt)
time.sleep(0.01)
在myclass.pu的MyClass 类中新增方法,方法名就是我们的关键字