zoukankan      html  css  js  c++  java
  • web自动化测试

    import unittest
    from selenium import webdriver
    from time import sleep
    from selenium.common import exceptions
    
    class MyTestCase_1(unittest.TestCase):      #用户权限管理
        @classmethod
        def setUpClass(cls):        #打开网页
            cls.driver = webdriver.Chrome()
            cls.driver.get("http://10.112.48.41:8080/index.html")
            cls.driver.maximize_window()
            sleep(1)
        @classmethod
        def tearDownClass(cls):     #关闭浏览器
            sleep(3)
            cls.driver.quit()
    
        def test_case_001(self):      #登陆
            #验证登陆功能
            self.driver.find_element_by_xpath('//*[@id="loginname"]').send_keys('admin')
            self.driver.find_element_by_xpath('//*[@id="password"]').send_keys('admin')
            self.driver.find_element_by_xpath('//*[@id="to-recover"]').click()
            sleep(5)
            url_login = self.driver.current_url
            self.assertEqual(url_login,"http://10.153.48.41:8080/pss/product/frame/main.html")
        '''
        def test_case_002(self):      #点 系统管理
            self.driver.find_element_by_xpath('//ul[@id="pgwMenu"]/li[7]/a/span').click()
            source = self.driver.page_source
            try:
                '系统管理' in source
            except exceptions:
                print('未进入系统管理页面')
            else:
                print('pass')
            sleep(1)
        def test_case_003(self):      #点 用户权限管理
            self.driver.switch_to.frame(self.driver.find_element_by_id('frameLeft'))
            self.driver.find_element_by_xpath('//div[@id="leftMenu"]/ul[2]/li[1]/div/a').click()
            sleep(1)
        def test_case_004(self):      #点 用户列表
            self.driver.find_element_by_xpath('//*[@id="leftMenu"]/ul[2]/li[1]/ul/li[1]/div/a').click()
            sleep(1)
        def test_case_005(self):      #查询
            self.driver.switch_to.default_content()
            sleep(1)
            self.driver.switch_to.frame(self.driver.find_element_by_name('frameMain'))
            self.driver.find_element_by_xpath('//*[@id="pager"]/div[1]/div/div[2]/div[1]/form/div[1]/span/input[1]').send_keys('b')
            self.driver.find_element_by_xpath('//*[@id="pager"]/div[1]/div/div[2]/div[1]/form/div[2]/span/input[1]').send_keys('ba')
            self.driver.find_element_by_xpath('//*[@id="pager"]/div[1]/div/div[2]/div[1]/form/div[3]/span/input[1]').click()
            self.driver.find_element_by_xpath('//*[@id="_easyui_combobox_i3_3"]').click()
            self.driver.find_element_by_xpath('//*[@id="pager"]/div[1]/div/div[2]/div[1]/form/div[4]/a[1]/span/span[1]').click()
            sleep(2)
        def test_case_006(self):      #点重置
            self.driver.find_element_by_xpath('//a[@id="resetUsers"]/span/span[1]').click()
            sleep(2)
        def test_case_007(self):      #点操作
            self.driver.find_element_by_xpath('//*[@id="datagrid-row-r1-2-0"]/td[8]/div/a').click()
            sleep(1)
        def test_case_008(self):      #点返回
            self.driver.find_element_by_xpath('//*[@id="onback"]/span/span[1]').click()
            sleep(1)
        def test_case_009(self):        #点角色列表
            self.driver.switch_to.default_content()
            sleep(1)
            self.driver.switch_to.frame(self.driver.find_element_by_id('frameLeft'))
            self.driver.find_element_by_xpath('//*[@id="leftMenu"]/ul[2]/li[1]/ul/li[2]/div/a').click()
        def test_case_010(self):        #点角色查询
            self.driver.switch_to.default_content()
            sleep(1)
            self.driver.switch_to.frame(self.driver.find_element_by_name('frameMain'))
            self.driver.find_element_by_xpath('//*[@id="pager"]/div[1]/div/div[2]/div[1]/form/div[1]/span/input[1]').send_keys('审')
            self.driver.find_element_by_xpath('//*[@id="pager"]/div[1]/div/div[2]/div[1]/form/div[2]/a/span/span[2]').click()
            sleep(1)
            self.driver.find_element_by_xpath('//*[@id="pager"]/div[1]/div/div[2]/div[1]/form/div[1]/span/input[1]').clear()
            self.driver.find_element_by_xpath(
                '//*[@id="pager"]/div[1]/div/div[2]/div[1]/form/div[1]/span/input[1]').send_keys('审计')
            self.driver.find_element_by_xpath(
                '//*[@id="pager"]/div[1]/div/div[2]/div[1]/form/div[2]/a/span/span[2]').click()
            sleep(1)
            self.driver.find_element_by_xpath('//*[@id="pager"]/div[1]/div/div[2]/div[1]/form/div[1]/span/input[1]').clear()
            self.driver.find_element_by_xpath('//*[@id="pager"]/div[1]/div/div[2]/div[1]/form/div[2]/a/span/span[2]').click()
            sleep(2)
        def test_case_011(self):        #点操作
            self.driver.find_element_by_xpath('//*[@id="datagrid-row-r1-2-0"]/td[4]/div/a').click()
            sleep(1)
        def test_case_012(self):        #切换表头
            self.driver.find_element_by_xpath('//*[@id="treeDemoDivpren"]/div[1]/div[3]/ul/li[1]/a/span[2]').click()
            sleep(1)
            self.driver.find_element_by_xpath('//*[@id="treeDemoDivpren"]/div[1]/div[3]/ul/li[2]/a/span[1]').click()
            sleep(1)
            self.driver.find_element_by_xpath('//*[@id="treeDemoDivpren"]/div[1]/div[3]/ul/li[3]/a/span[1]').click()
            sleep(1)
            self.driver.find_element_by_xpath('//*[@id="treeDemoDivpren"]/div[1]/div[3]/ul/li[4]/a/span[1]').click()
            sleep(1)
            self.driver.find_element_by_xpath('//*[@id="treeDemoDivpren"]/div[1]/div[3]/ul/li[5]/a/span[1]').click()
            sleep(1)
            self.driver.find_element_by_xpath('//*[@id="treeDemoDivpren"]/div[1]/div[3]/ul/li[6]/a/span[1]').click()
            sleep(1)
            self.driver.find_element_by_xpath('//*[@id="treeDemoDivpren"]/div[1]/div[3]/ul/li[7]/a/span[1]').click()
            sleep(1)
            self.driver.find_element_by_xpath('//*[@id="treeDemoDivpren"]/div[1]/div[3]/ul/li[8]/a/span[1]').click()
            sleep(1)
        def test_case_013(self):        #点 返回
            self.driver.find_element_by_xpath('//*[@id="onback"]/span/span[1]').click()
            sleep(1)
        def test_case_014(self):        #点机构列表
            self.driver.switch_to.default_content()
            self.driver.switch_to.frame(self.driver.find_element_by_id('frameLeft'))
            self.driver.find_element_by_link_text('机构列表').click()
            sleep(1)
        def test_case_015(self):        #查询
            self.driver.switch_to.default_content()
            self.driver.switch_to.frame(self.driver.find_element_by_id('frameMain'))
            self.driver.find_element_by_id('institutionName').send_keys('默认1')
            self.driver.find_element_by_xpath('//*[@id="pager"]/div[1]/div/div[2]/div[1]/form/div[2]/a/span/span[2]').click()
            sleep(1)
            self.driver.find_element_by_id('institutionName').clear()
            self.driver.find_element_by_id('institutionName').send_keys('默认')
            self.driver.find_element_by_xpath('//*[@id="pager"]/div[1]/div/div[2]/div[1]/form/div[2]/a/span/span[2]').click()
            sleep(1)
        def test_case_016(self):        #点 操作
            self.driver.find_element_by_xpath('//*[@id="datagrid-row-r1-2--1"]/td[4]/div/a').click()
            sleep(1)
        def test_case_017(self):        #点返回
            self.driver.find_element_by_xpath('//*[@id="instituForm"]/div[2]/a[2]/span/span[1]').click()
            sleep(1)
        def test_case_018(self):        #点iMC用户同步
            self.driver.switch_to.default_content()
            self.driver.switch_to.frame(self.driver.find_element_by_id('frameLeft'))
            self.driver.find_element_by_link_text('iMC用户同步').click()
            sleep(1)
        def test_case_100(self):        #退出登录
            self.driver.switch_to.default_content()
            self.driver.find_element_by_xpath('//*[@id="menuForm"]/ul/li[9]/a/span').click()
            '''
    
    '''
    class  MyTestCase_2(unittest.TestCase):      #系统配置管理
        def test_case_019(self):
    '''
    
    if __name__ == '__main__':
        unittest.main()
    

      

    js使用方法:
    	使用js如何去掉空格:https://www.cnblogs.com/sapho/p/5416302.html
    	使用js如何移动滚动条:https://zhidao.baidu.com/question/626505438617053884.html
    	
    	js定位方式(常用四种):
    	Document.getElementById(" ")
    	Document.getElementsByClassName(" ")[]
    	Document.getElementsByTagName(" ")[]
    	Document.getElementsByNames(" ")[]
    	jqery定位方式:
    	 使用了css定位的书写方式:Id(#)  Class(.)  TagName()
    	定位类名为<btn btn-md btn-primary>的第三个元素-------->$('.btn.btn-md.btn-primary')[2]
    	可以是层级关系的定位:$('body div.row  div.col-lg-10.col-md-12.col-sm-12.col-xm-12  table  tbody  tr:nth-child(2)  td  div  div  input:nth-child(1)')
    	输入到Console页面的context: document下的outerHTML字段。
    	
    	jqery和js获取元素属性的方法:
    	Jquery
    	设置属性 $("#compman").attr("属性","值")    
    	获取属性 $("#compman").attr("属性")
    	原生(JS)
    	设置属性  document.getElementById("").setAttribute("属性","值")       
    	获取属性  document.getElementById("").getAttribute("属性")
    	另起一个网页打开访问环境
    	window.open("http://10.153.49.55:8080/SPlus")
    	利用js获取某段文本内容后,截取后十位字符串
    	document.getElementsByClassName("hidden-sm hidden-xs")[5].innerText.substr(-10)
    

      

  • 相关阅读:
    [LeetCode] 1160. Find Words That Can Be Formed by Characters
    [LeetCode] 561. Array Partition I
    [LeetCode] 942. DI String Match
    [LeetCode] 852. Peak Index in a Mountain Array
    [LeetCode] 461. Hamming Distance
    [LeetCode] 617. Merge Two Binary Trees
    SSM项目实现连接两个mysql数据库
    springboot导入excel到mysql
    Mysql修改表备注, 列信息
    sql.xml where ids in的写法
  • 原文地址:https://www.cnblogs.com/schblog/p/14802393.html
Copyright © 2011-2022 走看看