Selenium学习第三天--模块化设计用例

公共方法:

from  selenium import webdriver
import time

def login(self):
    self.driver.find_element_by_xpath('/html/body/div/div/form/div[1]/select').click()
    time.sleep(2)
    self.driver.find_element_by_xpath('/html/body/div/div/form/div[1]/select/option[2]').click()
    time.sleep(1)
    self.driver.find_element_by_xpath('/html/body/div/div/form/div[2]/input').send_keys('142630170611011230')
    time.sleep(1)
    self.driver.find_element_by_xpath('/html/body/div/div/form/div[3]/input').send_keys('123456')
    time.sleep(2)
    self.driver.find_element_by_xpath('/html/body/div/div/form/button').click()
def  logout(self):
    self.driver.find_element_by_link_text('退出').click()

登录首页测试用例:

from  selenium import webdriver
import unittest
import time
from  SELENIUM.sx_public import login ,logout

class Testlogin(unittest.TestCase):
    #初始化方法,用例执行时先执行这个方法
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(2)
        self.url = '测试地址(url)'
        self.verificationErrors = []
    def testlogin(self):
        driver = self.driver
        self.driver.get(self.url)
     #调用登录方法
        login(self)
        text = self.driver.find_element_by_class_name('text-muted').text
        self.assertEqual(text, '智慧填报系统')
    #调用退出方法
       logout(self)
   #善后工作,关闭浏览器,并验证有没有错误信息
    def tearDown(self):
        driver = self.driver
       self.driver.quit()
        self.assertEqual([],self.verificationErrors)

if __name__ == '__main__':
    unittest.main()
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,827评论 25 709
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,288评论 19 139
  • 今天收到了老妈寄来的褥子,铺在床上,讲真,软软的,都不想起床了。 前段时间跟我妈说,我弟把褥子都拿走了,被子也拿走...
    Shirley666阅读 254评论 0 0
  • 书是和人类一起成长起来的,一切震撼智慧的学说,一切打动心灵的热情,都在书里结晶成形。最近我在读一本书,名字...
    阳光男孩Rex阅读 188评论 0 1
  • (一) 心有多大,舞台就有多大 坐火车去重庆,27个小时。是很难得的独处时光。之前朋友们问起的时候,我都解...
    便利店鲸鱼阅读 232评论 0 0