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)
def test_case(self): ''' test key : pyse ''' self.driver = Pyse("chrome") driver = self.driver driver.open("http://www.baidu.com") driver.type("//*[@id='kw']", "pyse") driver.click("//*[@id='su']") sleep(1)
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 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 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_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()
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 main(): try: driver = Pyse("chrome") username = '******' password = '******' test_user_login(driver, username, password) sleep(3) text = driver.get_text("//span[@id='spnUid']") assert (text == '*****@*****.**'), u"用户名称不匹配,登录失败!" finally: # 关闭浏览器窗口 driver.close()
#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()
def setUpClass(cls): """ Setting browser driver, Using chrome by default.""" cls.driver = Pyse("chrome") cls.timeout = 15 # You can customize timeout time
def setUpClass(cls): cls.driver = Pyse("firefox")
def setUpClass(cls): ''' Setting browser driver, Using chrome by default.''' cls.driver = Pyse("firefox")
def setUpClass(cls): ''' Setting browser driver, Using chrome by default.''' cls.driver = Pyse("chrome_headless")
def setUpClass(cls): cls.driver = Pyse("chrome")
def setup(self): self.driver = Pyse("chrome") self.base_url = "http://www.126.com"
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()
def setUp(self): self.driver = Pyse("chrome")
def setUpClass(cls): """ Setting browser driver, Using chrome by default.""" cls.driver = Pyse("chrome")
def setUp(self): self.driver = Pyse("chrome") self.driver.wait(10) self.base_url = "http://www.baidu.com"
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