class BaiduTest(unittest.TestCase): ''' Baidu serach test case ''' def setUp(self): self.driver = Pyse("chrome") def tearDown(self): self.driver.quit() def baidu_search(self,search_key): self.driver.open("https://www.baidu.com") self.driver.clear("id=>kw") self.driver.type("id=>kw", search_key) self.driver.click("css=>#su") sleep(1) def test_baidu1(self): ''' baidu search key : pyse ''' search_key = "pyse" self.baidu_search(search_key) self.assertTrue(search_key,self.driver.get_title()) def test_baidu2(self): ''' baidu search key : selenium ''' search_key = "selenium" self.baidu_search(search_key) self.assertTrue(search_key,self.driver.get_title())
def test_login(self): '''密码登录''' print('start') driver = Pyse("chrome") try: driver.open( "http://172.17.0.200:8066/Directors/pages/login.html?_U155834476961480222" ) time.sleep(3) driver.type(r"xpath=>//*[@name='userName']", "test1") driver.type(r"name=>password", "admin") time.sleep(2) driver.click(r"id=>btnSubmit") # time.sleep(50) print("等进去") time.sleep(30) print("ddddddddddd") print('end') except BaseException as err: print(err)
class BaiduTest(unittest.TestCase): ''' Baidu serach test 0case ''' def setUp(self): self.driver = Pyse("chrome") def tearDown(self): self.driver.quit() def baidu_search(self, search_key): self.driver.open("https://www.baidu.0com") self.driver.clear("id=>kw") self.driver.type("id=>kw", search_key) self.driver.click("css=>#su") sleep(1) def test_baidu1(self): ''' baidu search key : pyse ''' search_key = "pyse" self.baidu_search(search_key) self.assertTrue(search_key, self.driver.get_title()) def test_baidu2(self): ''' baidu search key : selenium ''' search_key = "selenium" self.baidu_search(search_key) self.assertTrue(search_key, self.driver.get_title())
def test_baidu(): ''' baidu search key : pyse ''' driver = Pyse("chrome") driver.open("https://www.baidu.com") driver.type("id=>kw", "pyse") driver.click("css=>#su") sleep(1) assert "pyse" in driver.get_title() driver.quit()
def test_baidu(): """ baidu search key : pyse """ driver = Pyse("chrome") driver.open("https://www.baidu.com") driver.type("id=>kw", "pyse") driver.click("css=>#su") sleep(1) assert "pyse" in driver.get_title() driver.quit()
def test_baidu(self): ''' baidu search key : pyse ''' driver = Pyse("chrome") driver.open("https://www.baidu.com") driver.clear("id=>kw") driver.type("id=>kw", "pyse") driver.click("css=>#su") sleep(1) self.assertTrue("pyse",driver.get_title()) driver.quit()
def test_baidu(self): ''' baidu search key : pyse ''' driver = Pyse("chrome") driver.open("https://www.baidu.0com/") driver.clear("id=>kw") driver.type("id=>kw", "pyse") driver.click("css=>#su") sleep(1) self.assertTrue("pyse", driver.get_title()) driver.quit()
def test_baidu(): ''' baidu search key : pyse ''' driver = Pyse("chrome") driver.open("https://www.baidu.com") driver.type("id=>kw", "pyse") driver.click("id=>su") sleep(1) title = driver.get_title() assert "pyse" in title driver.quit()
def test_youdao(): ''' youdao search key : pyse ''' driver = Pyse() # default firefox browser driver.open("http://www.youdao.com") driver.type("name=>q", "pyse") driver.click("id=>qb") sleep(1) title = driver.get_title() print title assert title == "pyse - 有道搜索" driver.quit()
class baiduTest(unittest.TestCase): def setUp(self): self.driver = Pyse("chrome") self.driver.wait(10) self.base_url = "http://www.baidu.com" def test_case(self): self.driver.open(self.base_url) self.driver.click_text("设置") self.driver.click_text("搜索设置") sleep(2) self.driver.click("//a[@class='prefpanelgo']") sleep(1) self.driver.accept_alert() def tearDown(self): self.driver.quit()
class uiRecover(unittest.TestCase): def setUp(self): self.driver = Pyse('chrome') self.driver.open( 'http://t5609.xyscm-biz-manager-web.yunzong:12050/#/login') self.driver.max_window() self.driver.type('class=>userName', 'yangxuegx') time.sleep(0.5) self.driver.type('class=>password', 'y123456') time.sleep(0.5) self.driver.click('class=>button') time.sleep(1) def tearDown(self): self.driver.close() def test_add_customer(self): self.driver.click( 'xpath=>/html/body/div/div[2]/div[1]/div/div/ul/li[7]/div/span' ) #点击客户管理,弹出下拉框 time.sleep(0.5) self.driver.ciick( 'xpath=>/html/body/div/div[2]/div[1]/div/div/ul/li[7]/ul/li[1]/span' ) #点击客户列表 time.sleep(0.5) self.driver.click( 'xpath=>//*[@id="content"]/div[2]/div[2]/button/span') #点击新增客户 time.sleep(0.5) self.driver.type( 'xpath=>//*[@id="content"]/div[2]/form/div[1]/div[1]/div[1]/div/div/div/input', '自动测试客户一') #输入客客户名称 time.sleep(0.5) self.driver.type( 'xpath=>//*[@id="content"]/div[2]/form/div[1]/div[1]/div[2]/div/div/div/input', '自动执行业务员一') #输入业务员名称 time.sleep(0.5)
# coding=utf-8 from pyse import Pyse, TestRunner from nose.tools import with_setup from time import sleep def my_setup_function(): print "test case start:" def my_teardown_function(): print "test case end." @with_setup(my_setup_function, my_teardown_function) def test02(): ''' testsearch ''' driver = Pyse("chrome") driver.open("http://tb2c.qicolor.cn") driver.type("xpath=>.//*[@id='keywords']", u"包") driver.click("xpath=>html/body/div[2]/div[3]/div/div[1]/div/input[2]") sleep(3) driver.quit() if __name__ == '__main__': TestRunner().run()
def test_book_meeting(self): ''' book meeting room ''' email = 'bjzhangjiwei' passwd = 'Zjw163163' date = self.get_date() if date is None: return driver = Pyse("chrome") driver.max_window() #login driver.open("http://meeting.oa.netease.com/oaMeeting/login.jsp#login") while not driver.get_display("class=>email-suffix"): driver.click_text(u"邮箱登录") driver.clear("name=>loginid") driver.type("name=>loginid", email) driver.clear("name=>userpassword") driver.type("name=>userpassword", passwd) driver.click_text(u"立即登录") sleep(3) self.assertEqual( "http://meeting.oa.netease.com/oaMeeting/bjroom.jsp#home/city", driver.get_url()) #输入筛选条件 ''' js = "document.getElementsByClassName('ac_selectCalendar')[0].getAttribute('value')" driver.js(js) today = driver.get_attribute("name=>date", 'value') tomorrow = today.split('-')[:2] + [str(int(today.split('-')[2]) + 1)] tomorrow = '-'.join(tomorrow) ''' js = "document.getElementsByName('date')[0].setAttribute('value', '" + date + "')" driver.js(js) sleep(2) driver.click('class=>ac_settingFloor') sleep(1) driver.click( "xpath=>//*[@id='jq-interactive-sprite']/table/tbody/tr[2]/td[2]/div/div[4]/div[1]/div[2]/ul/li[7]" ) sleep(1) driver.click("class=>ac_interactiveConfirm") sleep(2) #选择上午会议室 driver.click( 'xpath=>//html/body/div[3]/div[2]/div/div[2]/div[2]/div[2]/table/tbody/tr[3]/td[3]/div/dl[1]/dd/ul/li[6]' ) driver.click( 'xpath=>//html/body/div[3]/div[2]/div/div[2]/div[2]/div[2]/table/tbody/tr[3]/td[3]/div/dl[1]/dd/ul/li[3]' ) driver.click( 'xpath=>//html/body/div[3]/div[2]/div/div[2]/div[2]/div[2]/table/tbody/tr[3]/td[4]/a' ) sleep(2) driver.click( "xpath=>//*[@id='jq-interactive-sprite']/table/tbody/tr[2]/td[2]/div/div[4]/div/dl[4]/dd/div" ) while not driver.get_display( "xpath=>//*[@id='neteaseUser']/div/div[3]/div[2]/div/div[1]/div/div[1]/ul/li[1]/strong" ): sleep(2) driver.double_click( "xpath=>//*[@id='neteaseUser']/div/div[3]/div[2]/div/div[1]/div/div[1]/ul/li[8]/strong" ) driver.click( "xpath=>//*[@id='jq-interactive-MultiNeteaseUser']/table/tbody/tr[2]/td[2]/div/div[5]/em[1]/a" ) driver.type( "xpath=>//*[@id='jq-interactive-sprite']/table/tbody/tr[2]/td[2]/div/div[4]/div/dl[5]/dd/input", 'Regular meeting') driver.click( "xpath=>//*[@id='jq-interactive-sprite']/table/tbody/tr[2]/td[2]/div/div[5]/em[1]/a" ) sleep(3) #选择下午会议室 driver.click( 'xpath=>//html/body/div[3]/div[2]/div/div[2]/div[2]/div[2]/table/tbody/tr[3]/td[3]/div/dl[2]/dd[1]/ul/li[6]' ) driver.click( 'xpath=>//html/body/div[3]/div[2]/div/div[2]/div[2]/div[2]/table/tbody/tr[3]/td[3]/div/dl[2]/dd[1]/ul/li[3]' ) driver.click( 'xpath=>//html/body/div[3]/div[2]/div/div[2]/div[2]/div[2]/table/tbody/tr[3]/td[4]/a' ) sleep(2) driver.click( "xpath=>//*[@id='jq-interactive-sprite']/table/tbody/tr[2]/td[2]/div/div[4]/div/dl[4]/dd/div" ) while not driver.get_display( "xpath=>//*[@id='neteaseUser']/div/div[3]/div[2]/div/div[1]/div/div[1]/ul/li[1]/strong" ): sleep(2) driver.double_click( "xpath=>//*[@id='neteaseUser']/div/div[3]/div[2]/div/div[1]/div/div[1]/ul/li[8]/strong" ) driver.click( "xpath=>//*[@id='jq-interactive-MultiNeteaseUser']/table/tbody/tr[2]/td[2]/div/div[5]/em[1]/a" ) driver.type( "xpath=>//*[@id='jq-interactive-sprite']/table/tbody/tr[2]/td[2]/div/div[4]/div/dl[5]/dd/input", 'Regular meeting') driver.click( "xpath=>//*[@id='jq-interactive-sprite']/table/tbody/tr[2]/td[2]/div/div[5]/em[1]/a" ) sleep(3) #验证预定成功 self.assertTrue(driver.get_display("class=>mine-booked")) driver.click("xpath=>//html/body/div[3]/div[1]/div[2]/a[2]") sleep(2) self.assertEqual( "http://meeting.oa.netease.com/oaMeeting/bjroom.jsp#mine", driver.get_url()) driver.driver.get_screenshot_as_file('meeting.jpg') #js =" var str = ''; var arr = document.getElementsByClassName('time-item');for (var i in arr){str += arr[i].innerHTML;}" #print str(driver.js(js)) row_len = len( driver.driver.find_elements_by_xpath( "//html/body/div[3]/div[2]/div/div/div/div[2]/table/tbody/tr")) datetime = '' for i in range(1, row_len + 1): datetime += driver.get_element( 'xpath=>//html/body/div[3]/div[2]/div/div/div/div[2]/table/tbody/tr[%d]/td[4]' % i).text.encode('utf-8') self.assertTrue(date in datetime) driver.quit()
#coding=utf-8 from pyse import Pyse from time import sleep driver = Pyse("chrome") driver.open("https://www.baidu.com") driver.type("//*[@id='kw']", u"pyse自动化测试") driver.click("//*[@id='su']") sleep(2) driver.quit()
# coding=utf-8 from pyse import Pyse from time import sleep driver = Pyse("chrome") driver.open("https://www.baidu.com") driver.type("[name='wd']", u"pyse自动化测试") driver.click("#kw") sleep(2) driver.quit()
class testwarehouseinner(unittest.TestCase): def setUp(self): self.driver = Pyse('chrome') self.driver.open( 'http://t4567.xyscm-biz-warehouse-web.yunzong:12370/#/login') self.driver.max_window() self.driver.type('class=>userName', 'yxadmin1') time.sleep(1) self.driver.type('class=>password', 'y123456') time.sleep(1) self.driver.click('class=>button') def tearDown(self): self.driver.close() def test1(self): self.driver.click( 'xpath=>/html/body/div/div[2]/div[1]/div/div/ul/li[4]/div/span') time.sleep(1) self.driver.click( 'xpath=>/html/body/div/div[2]/div[1]/div/div/ul/li[4]/ul/li[3]/span' ) time.sleep(1) self.driver.click( 'xpath=>//*[@id="content"]/div[2]/div[1]/button/span') #点击新增 time.sleep(1) self.driver.click( 'xpath=>//*[@id="content"]/div[2]/div[2]/div/div[2]/form/div[1]/div/div/div/span/span/i' ) #点击下拉框 time.sleep(1) self.driver.click( 'xpath=>/html/body/div[3]/div[1]/div[1]/ul/li[2]/span') time.sleep(1) self.driver.type( 'xpath=>//*[@id="content"]/div[2]/div[2]/div/div[2]/form/div[2]/div/div[1]/input', 'test1') time.sleep(1) self.driver.type( 'xpath=>//*[@id="content"]/div[2]/div[2]/div/div[2]/form/div[3]/div/div[1]/input', 'test001') time.sleep(1) self.driver.click( 'xpath=>//*[@id="content"]/div[2]/div[2]/div/div[2]/form/div[4]/div/div/div/input' ) time.sleep(1) self.driver.click( 'xpath=>/html/body/div[4]/div[1]/div[1]/ul/li[1]/span') time.sleep(1) self.driver.click( 'xpath=>//*[@id="content"]/div[2]/div[2]/div/div[2]/form/div[5]/div/button' ) time.sleep(4)
#coding=utf-8 from pyse import Pyse from time import sleep driver = Pyse("chrome") driver.open("https://ww.baidu.com") driver.type("//*[@id='kw']",u"pyse自动化测试") driver.click("//*[@id='su']") sleep(2) driver.quit()
def sendEmail(self, subject="cctv"): start = time.time() driver = Pyse("chrome") try: # driver.implicitly_wait() # 添加了隐式等待,去除time.sleep显示等待 # driver.max_window() driver.open("http://mail.10086.cn/") time.sleep(3) driver.element_wait(r"name=>UserName", 10) driver.element_wait(r"id=>loginBtn", 10) driver.clear("name=>UserName") driver.type("name=>UserName", self.username) driver.type("id=>txtPass", self.pwd) driver.click("id=>loginBtn") time.sleep(1) driver.click("name=>mailbox_1") # 收件箱 driver.element_wait(r"xpath=>//*[@id='divTab']/ul/li[1]/span", 10) driver.element_wait(r"xpath=>//*[@id='sub']", 10) time.sleep(3) print("点击写信页: %r" % driver.get_display(r"xpath=>//a[@id='btn_compose']")) driver.click(r"xpath=>//a[@id='btn_compose']") time.sleep(3) print('切换frame: %r' % driver.get_display( r"xpath=>//*[@id='compose_preload' and @class='main-iframe']")) driver.switch_to_frame( r"xpath=>//*[@id='compose_preload' and @class='main-iframe']") time.sleep(2) print('输入收件人: %r' % driver.get_display( r"xpath=>//*[@id='toContainer']/div/div[2]/div[2]/input")) driver.type( r"xpath=>//*[@id='toContainer']/div/div[2]/div[2]/input", self.receiver) time.sleep(3) print('输入主题: %r' % driver.get_display(r"xpath=>//input[@id='txtSubject']")) # driver.click(r"xpath=>//input[@id='txtSubject']") driver.type(r"xpath=>//input[@id='txtSubject']", subject) print('点击发送') driver.click("id=>topSend") # print('等待完成') # driver.element_wait(r"xpath=>//*[@id='snedStatus']", 10) start = time.time() time.sleep(1) except BaseException as e: print('运行出错!!!') # driver.get_windows_img(r"D:\%s.jpg " %(start)) print(e) finally: driver.quit() return start