#-*-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()