Python+Selenium 自动化实现实例-模块化调用,pythonselenium,public 目录存
Python+Selenium 自动化实现实例-模块化调用,pythonselenium,public 目录存
public 目录存一些公共模块,供用例调用。login.py 内容如下:
# coding=utf-8import time# logindef login(driver): driver.find_element_by_class_name("ui-dialog-close").click() # 关闭弹窗 driver.find_element_by_xpath("//*[@id=‘topbar_nav‘]/li[1]/a[1]").click() # 点击登录按钮 driver.find_element_by_id("username").clear() driver.find_element_by_id("username").send_keys("18055352262") driver.find_element_by_id("password").clear() driver.find_element_by_id("password").send_keys("hj123456") driver.find_element_by_xpath("//input[@class=‘btn‘]").click() # 点击确认登录按钮# logoutdef logout(driver): time.sleep(2) driver.find_element_by_link_text(u"退出").click()
接下来login_lizi_public 文件引用login.py 中所定义的函数,代码如下:
#coding=utf-8from selenium import webdriverfrom public import loginimport unittestclass LoginTest(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.base_url = "http://www-test.lizi.com" self.driver.implicitly_wait(5) def test_lizi(self): driver = self.driver driver.get(self.base_url) #调用登录函数 login.login(driver) text = driver.find_element_by_css_selector(‘.name‘).text print text self.assertEqual(text,u"被风吹过的夏天",msg="error") #调用退出函数 login.logout(driver) def tearDown(self): self.driver.quit()if __name__ == "__main__": unittest.main()
Python+Selenium 自动化实现实例-模块化调用
相关内容
- 【Python数据分析】用户通话行为分析,python数据分析
- python numpy中sum()时出现负值,pythonnumpy,import num
- Python+pandas+matplotlib数据分析与可视化案例,pandasmatplo
- python虚拟环境 + win7-64位安装scipy matplotlib,win7-64scipy
- python基础:字符编码问题三个不可见的字符(0xEF 0xBB
- python爬虫笔记之re.compile.findall(),,re.compile
- 【selenium+Python unittest】之发送邮箱时报错:smtplib.SMT
- 如何用python爬取两个span之间的内容,pythonspan,Python用做
- Ubuntu16.04实用python脚本 - JDK的配置!,ubuntu16.04python,前
- Python安装cx_Oracle模块遇到的问题(32bit),pythoncx_oracle,环
评论关闭