#coding=utf-8 __author__ = 'zgd' import sys import os from Bussniss.Bussniss import Bussniss from Commonlib.Readxml import Readxml from Commonlib.MysqlClient import MysqlClient import unittest r = Readxml() import re class getPoorder(unittest.TestCase): def setUp(self): self.b = Bussniss() self.m = MysqlClient() # self.b.p.openBrowser("http://10.248.26.37/ESOP/Login/login.do") def tearDown(self): self.b.m.dateAdd() self.b.p.closeBrowser() def test001(self): u"""省级提单000开头""" self.assertIn( r.readxml("poorder", "epxect"), self.b.getPoorder( #得到poorDerNumBer r.readxml("poorder", "username"),
def __init__(self): self.c = Commonlib() self.r = Readxml() self.l = LoggIn()
def __init__(self): self.p = PubLic() self.r = Readxml() self.l = LoggIn()
class Bussniss: def __init__(self): self.c = Commonlib() self.r = Readxml() self.l = LoggIn() def LoadVideoType(self, base_url, username, password, filepathone): """上传视频格式不符合要求的视频格式""" try: self.c.loadVideoLogIn(base_url, username, password) self.c.waite(2) self.c.activeEvent(".//*[contains(text(),'导入视频')]") self.c.waite(2) # 路径前面加上r处理路径下含U self.l.Logg("上传视频文件") self.c.activeEvent(".//body/descendant::input[1]") self.c.waite(2) # ---------:这里是要上传的是视频的路径 # filepath = self.r.readxml("videofile", "d") # 非input标签,第三方工具制作上传文件的路径 os.system( r"C:\Users\Test\ruanjian\Autoitupload-filr\upload.exe %s" % filepathone) self.c.waite(2) t = self.c.tryText(".//body/div[2]/descendant::p") # print(t) self.l.Logg("拿到警告Alter弹框上文字") return t except Exception as e: self.l.Logg(e) raise e def UiLogin(self, myurl, username, password): """登录是否成功""" try: self.c.uiLogIn(myurl, username, password) self.c.waite(2) textone = self.c.tryText(".//body/div[1]/descendant::a[1]") return textone # if textone: # print(textone) # return textone # else: # picture_time = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time())) # self.c.getScreenShot('../Picture/' + '%s.png' % picture_time) except Exception as e: raise e def LoadVideo(self): '''登录上传视频后台系统,并上传视频''' self.l.Logg("登录视频上传网站") try: self.c.loadVideoLogIn(self.r.readxml("baseurl", "loadvideoUrl"), self.r.readxml("loadvideologin", "username"), self.r.readxml("loadvideologin", "password")) self.c.waite(1) self.c.activeEvent(".//*[contains(text(),'导入视频')]") self.c.waite(1) # 路径前面加上r处理路径下含U self.l.Logg("上传视频文件") self.c.activeEvent(".//body/descendant::input[1]") self.c.waite(1) # ---------:这里是要上传的是视频的路径 videoname = random.choice(videolist) allpath = filepath + '\\' + videoname print(allpath) # 非input标签,第三方工具制作上传文件的路径 os.system( r"C:\Users\Test\ruanjian\Autoitupload-filr\upload.exe %s" % allpath) self.c.waite(2) # ---------:这里是要上传的是视频的路径 选择内网自编,还是外网资源<neiwwang>内网自编</neiwwang><waiwang>外网资源</waiwang> self.c.activeEvent(".//*[contains(text(),'外网资源')]") self.c.waite(1) self.c.activeEvent( ".//*[contains(text(),'频道分类')]/following-sibling::div/descendant::input" ) self.c.waite(2) # 随机选取一个栏目 self.c.activeEvent(".//*[contains(text(),'%s')]" % random.choice(videosourse)) print(random.choice(videosourse)) self.c.waite(2) self.c.activeEvent( ".//*[contains(text(),'语种')]/following-sibling::div/descendant::input" ) self.l.Logg("选择语言") self.c.waite(3) # ---------选择各种语言 self.c.activeEvent(".//*[contains(text(),'%s')]" % random.choice(langue)) print(random.choice(langue)) self.c.waite(1) self.l.Logg("清除制作日期,重新输入当期日期") self.c.clearKeys( ".//*[contains(text(),'制作日期')]/following-sibling::div/descendant::input" ) self.c.waite(1) self.c.inputKeys( ".//*[contains(text(),'制作日期')]/following-sibling::div/descendant::input", str(datetime.date.today())) self.c.waite(1) self.c.activeEvent(".//*[@class='video-import']") self.l.Logg("清除上传日期,重新输入当期日期") self.c.clearKeys( ".//*[contains(text(),'上传日期')]/following-sibling::div/descendant::input" ) self.c.waite(1) self.c.inputKeys( ".//*[contains(text(),'上传日期')]/following-sibling::div/descendant::input", str(datetime.date.today())) self.c.activeEvent(".//*[@class='video-import']") self.l.Logg("输入内容摘要") self.c.inputKeys( ".//*[contains(text(),'内容摘要')]/following-sibling::div/descendant::textarea", "这是一个UI自动化测试的demo") self.c.waite(1) self.c.activeEvent(".//*[text()='导入']") self.c.waite(2) #点击桌面弹出提示框 self.c.activeEvent(".//body/descendant::span[35]/descendant::span") self.c.waite(2) self.c.activeEvent(".//*[contains(text(),'查看处理过程')]") self.c.waite(2) benditext = self.c.tryText(".//*[text()='本地上传']") return benditext except Exception as e: self.l.Logg(e) def getLoginTitle(self, base_url, username, password): # web首页login的title try: self.c.uiLogIn(base_url, username, password) texttwo = self.c.getTitle() self.c.waite(2) self.l.Logg("web首页登录后Title为--->%s" % texttwo) return texttwo except Exception as e: self.l.Logg(e) raise e def AudioVideo(self, base_url, username, password): """音视频库下""" self.l.Logg("This class is AudioVideo") try: self.c.uiLogIn(base_url, username, password) self.c.waite(1) self.l.Logg("点击音视频库") self.c.activeEvent(".//body/div[1]/descendant::a[2]") self.c.waite(1) listtext = [] shishiredian = self.c.tryText( ".//body/div[1]/section/descendant::a[4]") listtext.append(shishiredian) self.l.Logg("拿到音视频下首页的第一个标签为—》%s" % shishiredian) neiwangzibian = self.c.tryText( ".//body/div[1]/section/descendant::p[1]") listtext.append(neiwangzibian) self.l.Logg("拿到音视频下首页的第二个标签为—》%s" % neiwangzibian) waiwang = self.c.tryText(".//body/div[1]/section/descendant::p[2]") listtext.append(waiwang) self.l.Logg("拿到音视频下首页的第三个标签为—》%s" % waiwang) # print(type(listtext),listtext) return listtext except Exception as e: self.l.Logg(e) def ShiShiredian(self, url, username, password): """点击事实热点拿到title""" try: textlist = [] self.l.Logg("This class is shiShiredian") self.c.uiLogIn(url, username, password) self.c.waite(1) self.c.activeEvent(".//body/div[1]/section/descendant::a[4]") self.c.waite(1) #拿到第一个视频的标题 textone = self.c.tryText( ".//body/descendant::section/descendant::ul[5]/descendant::div[8]" ) # print("视频页标题为-----> %s"%textone ) textlist.append(textone) self.c.waite(1) self.c.jsTopDown("500") self.c.waite(1) self.l.Logg("拿到时事热点第一条视频") self.c.activeEvent( ".//body/div[1]/descendant::section/descendant::img[1]") self.c.waite(2) self.l.Logg("点击播放视频") self.c.activeEvent(".//body/descendant::video") self.c.waite(5) self.l.Logg("停止播放视频") self.c.activeEvent(".//body/descendant::video") texttwo = self.c.tryText( ".//body/descendant::section/descendant::p[4]") # print("视频内标题为-----> %s"%texttwo) textlist.append(texttwo) self.c.waite(2) # print(textlist) return textlist except Exception as e: self.l.Logg(e) raise e # b = Bussniss() # b.LoadVideo() def DownloadVideo(self, myurl, username, password): """随机下载视频到固定路径""" try: self.c.uiLogIn(myurl, username, password) self.c.waite(2) #这几个xpat对应“央企”,“国资委”,“人工智能”,“电子对抗”,“下一代网络”,“智能制造”,“区块链” listnum = ["5", "6", "7", "8", "9", "10", "11", "12", "13", "14"] # 随机选择栏目 filexpath = ".//section/div/descendant::a[%s]" % random.choice( listnum) self.c.activeEvent(filexpath) #点击进入详细视频页,点击第一条视频 self.c.waite(2) #下拉500像素 self.c.jsTopDown(500) self.c.waite(2) #随机选取页面上的任意一个视频 videolistnum = ["1", "2", "3", "4", "5", "6", "7", "8"] self.c.activeEvent(".//section/div/descendant::img[%s]" % random.choice(videolistnum)) self.c.waite(2) namestrs = self.c.tryText( ".//body/descendant::section/descendant::h2") videonameall = namestrs.split('丨') # 拿到视频的名称,然后去下载文件的路径下,根据这个名称找下载的视频列表 videoname = videonameall[1] #点击视频下载 self.c.activeEvent(".//*[contains(text(),'下载视频')]") #暂停20S下载视频 self.c.waite(20) return videoname except Exception as e: self.l.Logg(e) raise e # def GetVideoNameList(self,file_path): # #遍历下载路径下的文件的所有名称 # videonames = os.listdir(file_path) # print(videonames) # return videonames def deded(self): pass """撤销Test""" # b = Bussniss() # b.LoadVideo() # b.DownloadVideo("http://10.168.103.151/web/#/login","admin","111111") # # b.GetVideoNameList(r"C:\Users\Test\loadvideofile\seleniundownload")
class Bussniss: def __init__(self): self.p = PubLic() self.r = Readxml() self.l = LoggIn() def LoadVideo(self): '''登录上传视频后台系统,并上传视频''' self.l.Logg("登录视频上传网站") try: self.p.login_load_video( self.r.readxml("baseurl", "loadvideoUrl"), self.r.readxml("loadvideologin", "username"), self.r.readxml("loadvideologin", "password")) self.p.pub.waite(1) self.p.pub.activeEvent(".//*[contains(text(),'导入视频')]") self.p.pub.waite(2) #路径前面加上r处理路径下含U self.l.Logg("上传视频文件") self.p.pub.activeEvent(".//body/descendant::input[1]") self.p.pub.waite(2) filepath = self.r.readxml("videofile", "a") # filepath = r"C:\Users\Test\上传视频\2019--0521--Autoit-selenium-test.mp4" #非input标签,第三方工具制作上传文件的路径 os.system(r"C:\Users\Test\upload.exe %s" % filepath) self.p.pub.waite(2) #选择内网自编,还是外网资源 self.p.pub.activeEvent(".//*[contains(text(),'%s')]" % self.r.readxml("shiplaiyuan", "waiwang")) self.p.pub.waite(1) self.p.pub.activeEvent( ".//*[contains(text(),'频道分类')]/following-sibling::div/descendant::input" ) self.p.pub.waite(1) #这里选择内网下的(只能选择国资委和央企),,,,外网下的频道分类 self.p.pub.activeEvent(".//*[contains(text(),'%s')]" % self.r.readxml("pindaofenlei", "sev")) self.p.pub.activeEvent( ".//*[contains(text(),'语种')]/following-sibling::div/descendant::input" ) self.l.Logg("选择语言") self.p.pub.waite(1) #选择各种语言 self.p.pub.activeEvent(".//*[contains(text(),'%s')]" % self.r.readxml("langeue", "eyu")) self.p.pub.waite(1) self.l.Logg("清除制作日期,重新输入当期日期") self.p.pub.clearKeys( ".//*[contains(text(),'制作日期')]/following-sibling::div/descendant::input" ) self.p.pub.waite(1) self.p.pub.inputKeys( ".//*[contains(text(),'制作日期')]/following-sibling::div/descendant::input", str(datetime.date.today())) self.p.pub.waite(1) self.p.pub.activeEvent(".//*[@class='video-import']") self.l.Logg("清除上传日期,重新输入当期日期") self.p.pub.clearKeys( ".//*[contains(text(),'上传日期')]/following-sibling::div/descendant::input" ) self.p.pub.waite(1) self.p.pub.inputKeys( ".//*[contains(text(),'上传日期')]/following-sibling::div/descendant::input", str(datetime.date.today())) self.p.pub.activeEvent(".//*[@class='video-import']") self.l.Logg("输入内容摘要") self.p.pub.inputKeys( ".//*[contains(text(),'内容摘要')]/following-sibling::div/descendant::textarea", "这是一个测试自动化的demo") self.p.pub.waite(1) self.p.pub.activeEvent(".//*[text()='导入']") self.p.pub.waite(2) #刷新页面,取出弹窗 self.p.pub.reFresh() except Exception as e: raise e