• python 自动化测试


    #-*-coding:utf-8-*-
    from __future__ import with_statement
    
    import os
    try:
        import unittest2 as unittest
    except ImportError:
        import unittest
    import time 
    from splinter import Browser
    from random   import randint 
    
    class DbackupTestCase(unittest.TestCase):
       # support 2.7,but not support 2.6.all the testcases just have one instance
       # @classmethod
       # def setUpClass(cls):
       #     cls.browser=Browser('firefox')
        
       # @classmethod
       # def setDownClass(cls):
       #      cls.browser.quit()
    
       #every testcase has one instance
        def setUp(self):
            self.browser=Browser('firefox')
    
        def setDown(self):
            self.browser.quit()
    
        def do_login_if_need(self, username, password):
    
            if self.browser.find_by_id('lhgfrm_lhgdgId'):
                with self.browser.get_iframe('lhgfrm_lhgdgId') as frame:
                    frame.find_by_id('trialRadio').click()
                    frame.find_by_id('continue').click()
    
            self.browser.fill('username',username)
            self.browser.fill('password',password)
            self.browser.find_by_name('Submit').click()
    
            assert  self.browser.is_element_present_by_css('.none')
            
    
        def test_create_oracle_event(self):
    
            #open home and login
            self.browser.visit('http://192.168.88.213/dbackup')
            self.do_login_if_need(username='hzhida', password ='dingjia')
            time.sleep(0.5)
            assert self.browser.is_element_present_by_id('treeNodeId1')
            self.browser.find_link_by_href('javascript:void(0)')[1].click()
            time.sleep(1)
            element=self.browser.find_by_css('.tree_item_child')
            #self.browser.find_link_by_href('javascript:void(0)')[2].click()
            element[0].find_by_css('.tree_item_click').first.click()
            #element[0].find_by_tag('a').first.click()
            self.browser.find_by_id('Navigate7').click()
            self.browser.find_link_by_href('#wizard-2').click()
            self.browser.find_link_by_href('#wizard-3').click()
            self.browser.find_by_id('ftpRadio').click()
            self.browser.find_link_by_href('#wizard-4').click()
            number = [randint(1000,9999) for i in range(1)]
            jobname='job'+'_'+ str(number[0])
            self.browser.find_by_id('jobName').fill(jobname)
            self.browser.find_by_id('middlelevelRadio').click()
            self.browser.find_link_by_href('#wizard-5').click()
            self.browser.find_by_css('.submit_btn').click()
            time.sleep(1)
            self.browser.select('Filtermenu','JobMonitorManage.php?FType=1')
            time.sleep(0.1)
            self.browser.select('Filtermenu','JobMonitorManage.php?FType=0')
            time.sleep(0.1)
            self.assertEqual(self.browser.find_link_by_href('javascript:void(0)').first.value,jobname)
            print self.browser.find_by_id('CompletePercent0').value
            print self.browser.find_by_id('strBeginTime0').value
            print self.browser.find_by_id('strUsedTime0').value
            time.sleep(10)
    
        def test_create_mysql_event(self):
            self.browser.visit('http://192.168.88.213/dbackup')
            self.do_login_if_need(username='hzhida',password='dingjia')
            time.sleep(0.5)
            assert self.browser.is_element_present_by_id('treeNodeId1')
            self.browser.find_link_by_href('javascript:void(0)')[1].click()
            time.sleep(1)
            element=self.browser.find_by_css('.tree_item_child')
            element[1].find_by_tag('a').first.click()
            self.browser.find_by_id('Navigate7').click()
            self.browser.find_by_id('sqlSelectAllCheckbox').click()
            time.sleep(2)
            navigate=self.browser.find_by_css('.nav')
            navigate[0].find_by_css('.next').click()
            self.browser.find_by_id('ftpRadio').click()
            navigate[1].find_by_css('.back').click()
            time.sleep(1)
            navigate[0].find_by_css('.next').click()
            navigate[1].find_by_css('.next').click()
            self.browser.find_by_id('lowlevelRadio').click()
            number = [randint(1000,9999) for i in range(1)]
            jobname= 'job'+'_'+str(number[0])
            self.browser.find_by_id('jobName').fill(jobname)
            navigate[2].find_by_css('.next').click()
            navigate[3].find_by_css('.submit_btn').click()
            self.assertEqual(self.browser.find_by_tag('font').value, jobname)
            print self.browser.title()
            print self.browser.html
    
    
    
    unittest.main()
  • 相关阅读:
    Windows系统CMD窗口下,MySQL建库、还原数据库命令操作示例
    Java JPA 报java.lang.IllegalArgumentException: Validation failed for query for method public abstract ...异常的一种原因和解决办法
    MySQL 5.7 执行SQL报错:1055
    Java8使用实现Runnable接口方式创建新线程的方法
    模板方法模式
    策略模式
    观察者模式
    装饰器模式
    原型模式
    单例模式
  • 原文地址:https://www.cnblogs.com/hzhida/p/2640632.html
Copyright © 2020-2023  润新知