def testLog003(self): '''验证快速创建日志,默认页面是否为日报''' Mylogin(self.driver).login() Mylogin(self.driver).mklog() dailyReport = self.driver.find_element_by_xpath("//div[@class='el-card__body']/div/div[2]/div[1]/div[1]/div/div/div/div[2]") self.assertEqual(dailyReport.get_attribute('aria-selected'), "true")#验证提示信息 self.assertEqual(dailyReport.text,'日报')
def testLog017(self): '''验证上传附件 ,提示是否正确,返回日志页面''' Mylogin(self.driver).login() Mylogin(self.driver).mklog() self.driver.find_element_by_xpath("//div[@class='form']/div[1]/div/textarea").send_keys('今天工作内容是拜访客服')#输入汉字 for i in range(0,8): actions = ActionChains(self.driver).send_keys(Keys.TAB).perform() #8次TAB,下划到底部 self.driver.find_element_by_css_selector('div.el-upload.el-upload--text>input').send_keys(r'C:\Users\wu\Desktop\test.png')#上传附件 self.driver.implicitly_wait(5) picture = self.driver.find_element_by_xpath('//div[@class="form"]/div[4]/p/div/ul/li') self.assertTrue(picture.is_displayed())#验证上传附件是否显示 time.sleep(3) self.driver.find_element_by_xpath("//div[@class='el-card__body']/div/div/button[1]/span").click()#点击提交 try: self.driver.implicitly_wait(10) makeText = self.driver.find_element_by_xpath("//div[@role='alert']/p") self.assertEqual(makeText.text,'新建成功') print("提示:新建成功") except: pass WebDriverWait(self.driver, 10, 0.5).until( EC.presence_of_element_located((By.XPATH, '//*[@id="app"]/section/section/aside/div/ul/a[5]/li/span'))) journal = self.driver.find_element_by_xpath('//*[@id="app"]/section/section/aside/div/ul/a[5]/li') journalText = self.driver.find_element_by_xpath('//*[@id="app"]/section/section/aside/div/ul/a[5]/li/span') allof = self.driver.find_element_by_xpath('//div[@id="tab-1"]') allofText = self.driver.find_element_by_xpath('//div[@id="tab-1"]/div/span') self.assertEqual(journalText.text, '日志') #验证返回日志界面 self.assertIn('menu-item-select',journal.get_attribute('class')) self.assertEqual(allofText.text, '全部') #验证返回全部页面 self.assertEqual('true',allof.get_attribute('aria-selected'))
def setUp(self): self.driver = webdriver.Firefox() self.basecommon = BaseCommon(self.driver) self.mlogin = Mylogin(self.driver) self.data = Util().operateYaml( "../data/pageData/pageData.yaml") #取到yaml里边的所有数据 self.driver.get(self.data['login']['url'])
class Testlogin(unittest.TestCase): def setUp(self): self.driver = webdriver.Firefox() self.basecommon = BaseCommon(self.driver) self.mlogin = Mylogin(self.driver) self.data = Util().operateYaml( "../data/pageData/pageData.yaml") #取到yaml里边的所有数据 self.driver.get(self.data['login']['url']) def tearDown(self): filedir = "D:/test/screenshot/" if not os.path.exists(filedir): os.makedirs(os.path.join('D:/', 'test', 'screenshot')) screen_name = filedir + time.strftime( '%Y-%m-%d-%H-%M-%S', time.localtime(time.time())) + ".png" self.basecommon.screenshot(screen_name) self.driver.quit() def testJenkins01_01(self): time.sleep(2) self.mlogin.login() print "success......." self.taskdata = Util().operateYaml( "../data/pageData/newTaskData.yaml") # 取到yaml里边的所有数据 self.driver.find_element_by_link_text( self.taskdata['newtask']['newtask_01']['task']).click() txt = self.driver.find_element_by_xpath( self.taskdata['newtask']['newtask_01']['taskHo']).text print txt self.assertEqual(txt, self.taskdata['newtask']['assert']['username'])
def testLog001(self): '''验证快速创建日志,不输入直接提交日志,提示语是否正常''' Mylogin(self.driver).login() Mylogin(self.driver).mklog() self.driver.find_element_by_xpath("//div[@class='el-card__body']/div/div/button[1]/span").click() warnText = self.driver.find_element_by_xpath("/html/body/div/p")#获取提示信息 time.sleep(2) submit = self.driver.find_element_by_xpath("//div[@class='el-card__body']/div/div/button[1]/span") self.assertEqual(warnText.text, "内容至少填写一项")#验证提示信息 self.assertEqual(submit.text,'提交')#验证页面是否跳转
def testLog012(self): '''验证快速创建日志,明天工作内容输入1001个字母,提示是否正确''' Mylogin(self.driver).login() Mylogin(self.driver).mklog() url1 = self.driver.current_url self.driver.find_element_by_xpath("//div[@class='form']/div[2]/div/textarea").send_keys(mkstr.letters(1001))#输入1001个字母 self.driver.find_element_by_xpath("//div[@class='el-card__body']/div/div/button[1]/span").click() makeText = self.driver.find_element_by_xpath("/html/body/div[5]/p") time.sleep(3) url2 = self.driver.current_url self.assertEqual(makeText.text, "新建失败")#验证提示信息 self.assertEqual(url1, url2) #验证返回界面
def testLog002(self): '''验证快速创建日志,直接关闭新建日志页面,返回页面是否是之前的页面''' Mylogin(self.driver).login() time.sleep(5) url1 = self.driver.current_url#获取页面地址信息 Mylogin(self.driver).mklog() #等待关闭按钮显示 element = WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located((By.XPATH, "//*[@class='header']/img"))) element.click() #等待页面关闭跳转 WebDriverWait(self.driver, 10, 0.5).until( EC.presence_of_element_located((By.XPATH, "//*[text()='客户管理']"))) url2 = self.driver.current_url#获取页面地址信息 self.assertEqual(url1, url2)#验证页面信息是否相同
def testCreateContact01_08(self): """ 核对合同是否新建成功 """ Mylogin(self.driver).login() # 点击客户管理 WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.CSS_SELECTOR,'body>div>section>header>div>div>div>a:nth-child(2)'))).click() time.sleep(20) # 点击合同 click_element = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="app"]/section/section/aside/div/ul/a[8]/li'))) ActionChains(self.driver).click(click_element).perform() # 获取合同编号 id = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="crm-table"]/div[4]/div[2]/table/tbody/tr[1]/td[2]/div'))).text # 获取和同名称 name = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="crm-table"]/div[3]/table/tbody/tr[1]/td[3]/div'))).text # 获取状态 status = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="crm-table"]/div[5]/div[2]/table/tbody/tr[1]/td[20]/div/div'))).text # 断言结果 self.assertEqual(id,contract_id) self.assertEqual(name,contract_name) self.assertEqual(status,'待审核')
def testCreateContact01_06(self): """ 核对商机是否新建成功 """ Mylogin(self.driver).login() # 点击客户管理 WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.CSS_SELECTOR,'body>div>section>header>div>div>div>a:nth-child(2)'))).click() time.sleep(20) # 点击商机 click_element = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="app"]/section/section/aside/div/ul/a[7]/li'))) ActionChains(self.driver).click(click_element).perform() # 获取商机状态组 business_group = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="crm-table"]/div[3]/table/tbody/tr[1]/td[7]/div'))).text # 断言结果 self.assertEqual('商机组1',business_group) # 获取商机阶段 business_stage = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="crm-table"]/div[3]/table/tbody/tr[1]/td[8]/div'))).text # 断言结果 self.assertEqual('看不见',business_stage) # 创建用户 create_user = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="crm-table"]/div[3]/table/tbody/tr[1]/td[12]/div'))).text # 断言结果 self.assertEqual('mengxun',create_user)
def testLog020(self): '''验证回复日志内容和提示显示''' Mylogin(self.driver).login() #点击日志 WebDriverWait(self.driver,20,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="app"]/section/section/aside/div/ul/a[5]/li/span'))) self.driver.find_element_by_xpath('//*[@id="app"]/section/section/aside/div/ul/a[5]/li/span').click() WebDriverWait(self.driver, 20, 0.5).until( EC.presence_of_element_located((By.XPATH, '//*[@id="pane-1"]/div[1]/div[2]/div[1]/div[2]/button/span'))) #点击回复 self.driver.find_element_by_xpath('//*[@id="pane-1"]/div[1]/div[2]/div[1]/div[2]/button/span').click() time.sleep(5) reply = "回复时间:" + time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time())) #输入回复内容 self.driver.find_element_by_xpath('//*[@id="pane-1"]/div[1]/div[2]/div[1]/div[3]/div/textarea').send_keys(reply) time.sleep(2) #点击回复提交 self.driver.find_element_by_xpath('//*[@id="pane-1"]/div[1]/div[2]/div[1]/div[3]/div/textarea/../../div[2]/div/button[1]/span').click() WebDriverWait(self.driver, 10, 0.1).until( EC.presence_of_element_located((By.XPATH, '//div[@role="alert"]/p'))) #获取提示内容 makeText = self.driver.find_element_by_xpath("//div[@role='alert']/p") self.assertEqual(makeText.text,'回复成功') time.sleep(3) #获取所有回复内容 sendContent = self.driver.find_elements_by_css_selector('.reply-title>span') sendContentRawList = [] for i in range(0, len(sendContent)): sendContentRawList.append(sendContent[i].text) sendContentList = "".join(sendContentRawList) self.assertIn(reply, sendContentList)
def logcreate(self): Mylogin(self.driver).login() # 鼠标悬停 element = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.CSS_SELECTOR,'div.button-name'))) ActionChains(self.driver).move_to_element(element).perform() # 点击日志 click_element = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.CSS_SELECTOR,'div.quick-add>div>p'))) ActionChains(self.driver).click(click_element).perform() # 隐式等待10秒 self.driver.implicitly_wait(10) # # 获取当前窗口句柄 # handles = driver.current_window_handle # # 切换窗口 # driver.switch_to.window(handles[1]) # 点击第三个输入框,然后tab到最底部 WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.CSS_SELECTOR,'[class="form"]>div:nth-child(3)>div>textarea'))).send_keys("1") for i in range(0,8): ActionChains(self.driver).send_keys(Keys.TAB).perform() # sleep(2) # 模拟鼠标点击p标签 cilck_element = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.CSS_SELECTOR,'[class="add-file el-popover__reference"]'))) ActionChains(self.driver).click(cilck_element).perform() # # 切换alert # driver.switch_to.alert
def testCreateContact01_02(self): """ 检查客户是否建立成功 """ Mylogin(self.driver).login() # 点击客户管理 WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.CSS_SELECTOR,'body>div>section>header>div>div>div>a:nth-child(2)'))).click() time.sleep(20) # 点击待办事项 WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.CSS_SELECTOR,'#app>section>section>aside>div>ul>a:nth-child(2)>li'))).click() # 点击“待进入公海的客户” click_element = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="crm-main-container"]/div/div/div[2]/div/div[1]/div[4]'))) ActionChains(self.driver).click(click_element).perform() # 获取公海里的第一条个人信息 # 客户名称 user_name = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="crm-table"]/div[3]/table/tbody/tr[1]/td[1]/div'))).text # 手机号 user_phone = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="crm-table"]/div[3]/table/tbody/tr[1]/td[2]/div'))).text # 客户来源 user_source = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="crm-table"]/div[3]/table/tbody/tr[1]/td[4]/div'))).text # 客户行业 user_profession = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="crm-table"]/div[3]/table/tbody/tr[1]/td[5]/div'))).text # 客户级别 user_level = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="crm-table"]/div[3]/table/tbody/tr[1]/td[6]/div'))).text # 断言结果 self.assertEqual(username,user_name) self.assertEqual(phone,user_phone) self.assertEqual(source,user_source) self.assertEqual(profession,user_profession) self.assertEqual(level,user_level)
def testUpfile01_01(self): """ 写日志,并上传文件 """ Mylogin(self.driver).login() # 鼠标悬停 element = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.CSS_SELECTOR,'div.button-name'))) ActionChains(self.driver).move_to_element(element).perform() # 点击日志 click_element = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.CSS_SELECTOR,'div.quick-add>div>p'))) ActionChains(self.driver).click(click_element).perform() # 隐式等待10秒 self.driver.implicitly_wait(10) # 点击第三个输入框,然后tab到最底部 WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.CSS_SELECTOR,'[class="form"]>div:nth-child(3)>div>textarea'))).send_keys(content) # ActionChains(driver).click(cilck_element).perform() for i in range(0,8): ActionChains(self.driver).send_keys(Keys.TAB).perform() # sleep(2) file_ele = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'/html/body/div[3]/div/div/div/div[2]/div[2]/div[4]/p/div/div/input'))) # 上传本地图片 file_ele.send_keys(r"C:\Users\quanxh\Desktop\goutou.png") # 点击提交 WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'/html/body/div[3]/div/div/div/div[3]/button[1]'))).click() # 返回用例执行完成时间,通过时间戳比对时间 return time.time()
def testShouye01_01(self): '''测试首页导航文案显示是否正常''' Mylogin(self.driver).login() firstPageNavi = self.driver.find_element_by_xpath( "//div[@class='top']/span") loginText = self.driver.find_element_by_css_selector( "div.login>a:nth-child(1)") regisText = self.driver.find_element_by_css_selector( "div.login>a:nth-child(3)") self.assertEqual("亲,欢迎您来到云商系统商城!", firstPageNavi.text) self.assertEqual("17731990979", loginText.text) self.assertEqual("退出", regisText.text) self.assertNotEqual("dd", regisText.text) self.assertIn("云商系统商城", firstPageNavi.text) self.assertTrue( self.driver.find_element_by_xpath( "//div[@class='top']/span").is_displayed()) self.assertFalse(firstPageNavi.is_displayed()) if loginText.text == "177****0979": print("等于") else: print("不等于") self.driver.find_element_by_xpath("王麻子")
def testShouye01_03(self): '''点击关键字、热字是否跳转页面''' Mylogin(self.driver).login() self.driver.find_element_by_css_selector( "div.schhot>a:nth-child(3)").click() time.sleep(2) searchText = self.driver.find_element_by_css_selector("div.nomsg") self.assertEqual(searchText.text, "抱歉,没有找到相关的商品")
def testShouye01_04(self): '''含有空格搜索物品,查看搜索结果''' Mylogin(self.driver).login() self.driver.find_element_by_name("key").send_keys(" 女装") self.driver.find_element_by_css_selector(".but2").click() time.sleep(2) searchText = self.driver.find_element_by_css_selector("div.nomsg") self.assertNotEqual(searchText.text, "抱歉,没有找到相关的商品")
def testGouwu01_03(self): '''购物车为空时文案显示是否正常''' Mylogin(self.driver).login() self.driver.find_element_by_xpath("//div[@class='small_cart_name']/span").click() time.sleep(3) emptyGouwuText = self.driver.find_element_by_xpath("//div[@class='r']/span") print(emptyGouwuText.text) self.assertEqual("购物车内暂时没有商品",emptyGouwuText.text)
def testShouye01_05(self): '''是否支持模糊查询''' Mylogin(self.driver).login() self.driver.find_element_by_name("key").send_keys("女") self.driver.find_element_by_css_selector(".but2").click() time.sleep(2) searchText = self.driver.find_element_by_link_text( "女装 优质长绒棉A字型条纹连衣裙(七分袖) 412932 优衣库UNIQLO") self.assertEqual(searchText.text, "女装 优质长绒棉A字型条纹连衣裙(七分袖) 412932 优衣库UNIQLO")
def testShouye01_08(self): '''鼠标移动到精选商城下面名称,右侧是否出现二级子标题''' Mylogin(self.driver).login() ele = self.driver.find_element_by_link_text("男装女装") time.sleep(2) ActionChains(self.driver).move_to_element(ele).perform() self.assertTrue( self.driver.find_element_by_xpath( "/html/body/div[3]/div/div[1]/div/dl[1]/div/div[1]/div/a"). is_enabled())
def testShouye01_02(self): '''验证搜索内容无时,提示语是否正常''' Mylogin(self.driver).login() self.driver.find_element_by_xpath( "/html/body/div/div/div/div/form/input[1]").send_keys("王麻子") self.driver.find_element_by_xpath( "/html/body/div/div/div/div/form/input[2]").click() time.sleep(2) searchText = self.driver.find_element_by_xpath("//div[@class='nomsg']") self.assertEqual(searchText.text, "抱歉,没有找到相关的商品")
def testGouwu01_02(self): '''点击秒杀商品添加到购物车,是否弹出提示框''' Mylogin(self.driver).login() self.driver.find_element_by_link_text("秒杀").click() self.driver.implicitly_wait(10) self.driver.find_element_by_xpath("/html/body/div[4]/div/div[2]/div[3]/div[3]/div[2]/a").click() self.driver.find_element_by_css_xpath(".yyue").click() self.driver.find_element_by_xpath("/html/body/div[5]/div/div[2]/div[2]/div[3]/dl[1]/dd/a/em").click() self.driver.find_element_by_xpath("/html/body/div[5]/div/div[2]/div[2]/div[3]/dl[2]/dd/a/em").click() self.driver.find_element_by_css_xpath(".yyue").click() self.assertEqualTrue(self.driver.find_element_by_link_text(".buy_tip_name>p")).is_displayed()
def testBangong001(self): '''验证查看办公页面默认展示是否正常''' Mylogin(self.driver).login() WebDriverWait(self.driver,20,0.5).until(EC.presence_of_element_located((By.XPATH, '//*[@id="app"]/section/header/div/div/div/a[4]/div'))) self.driver.find_element_by_xpath('//*[@id="app"]/section/header/div/div/div/a[4]/div').click()#点击项目管理 WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH, '//span[text()="归档项目"]'))) self.driver.find_element_by_xpath('//*[@id="app"]/section/header/div/div/div/a[1]/div').click()#点击办公 WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH, '//span[text()="工作台"]'))) #工作台样式控件 workClass = self.driver.find_element_by_xpath('//span[text()="工作台"]/../..') self.assertIn("active",workClass.get_attribute('class'))#判断默认页面是否为工作台页面
def testLog019(self): '''验证新建日志上传1个附件后点击删除图片''' Mylogin(self.driver).login() Mylogin(self.driver).mklog() self.driver.find_element_by_xpath("//div[@class='form']/div[1]/div/textarea").send_keys( '今天工作内容是拜访客服') # 输入汉字 for i in range(0, 8): ActionChains(self.driver).send_keys(Keys.TAB).perform() # 8次TAB,下划到底部 self.driver.find_element_by_css_selector('div.el-upload.el-upload--text>input').send_keys( r'C:\Users\wu\Desktop\test.png')#上传附件 self.driver.implicitly_wait(5) ele = self.driver.find_element_by_xpath('//div[@class="form"]/div[4]/p/div/ul/li/a')#定位删除附件按钮 ActionChains(self.driver).move_to_element_with_offset(ele,200,40).perform() time.sleep(5) self.driver.find_element_by_xpath('//div[@class="form"]/div[4]/p/div/ul/li/i[1]').click()#点击删除 self.driver.implicitly_wait(5) self.driver.find_element_by_xpath('//div[@role="dialog"]/div/div/button[1]/span').click()#点击取消 makeText = self.driver.find_element_by_xpath("/html/body/div[5]/p") time.sleep(3) self.assertEqual(makeText.text,'已取消操作')#验证提示信息 self.assertIsNotNone(self.driver.find_element_by_xpath('//div[@class="form"]/div[4]/p/div/ul/li'),'附件未删除')#验证附件是否删除
def testLog016(self): '''验证新建日志上传1张图片后用取消删除图片''' Mylogin(self.driver).login() Mylogin(self.driver).mklog() self.driver.find_element_by_xpath("//div[@class='form']/div[1]/div/textarea").send_keys( '今天工作内容是拜访客服') # 输入汉字 for i in range(0, 8): ActionChains(self.driver).send_keys(Keys.TAB).perform() # 8次TAB,下划到底部 self.driver.find_element_by_css_selector('div.el-upload.el-upload--picture-card>input').send_keys( r'C:\Users\wu\Desktop\test.png')#上传图片 self.driver.implicitly_wait(5) ele = self.driver.find_element_by_xpath('//div[@class="form"]/div[4]/div/div/ul/li')#定位图片 ActionChains(self.driver).move_to_element(ele).perform() time.sleep(2) self.driver.find_element_by_xpath('//div[@class="form"]/div[4]/div/div/ul/li/span/span[2]/i').click()#点击删除 self.driver.implicitly_wait(5) self.driver.find_element_by_xpath('//div[@role="dialog"]/div/div/button[1]/span').click()#点击取消 makeText = self.driver.find_element_by_xpath("/html/body/div[5]/p") time.sleep(3) self.assertEqual(makeText.text,'已取消操作')#验证提示信息 self.assertIsNotNone(self.driver.find_element_by_xpath('//div[@class="form"]/div[4]/div/div/ul/li'),'图片未删除')#验证图片是否删除
def testCreateQuickly01_01(self): """ 点击快速创建,创建日志 """ Mylogin(self.driver).login() # 鼠标悬停 element = WebDriverWait(self.driver, 10, 0.5).until( EC.presence_of_element_located( (By.CSS_SELECTOR, 'div.button-name'))) ActionChains(self.driver).move_to_element(element).perform() # 点击日志 click_element = WebDriverWait(self.driver, 5, 0.5).until( EC.presence_of_element_located( (By.CSS_SELECTOR, 'div.quick-add>div>p'))) ActionChains(self.driver).click(click_element).perform() # 隐式等待10秒 self.driver.implicitly_wait(10) # FIREFOX需要获取当前窗口句柄 # handles = self.driver.current_window_handle # 关闭当前窗口 # driver.close() # 切换窗口 # self.driver.switch_to.window(handles[1]) # 尝试在今日工作内容书写信息,不成功返回信息 try: WebDriverWait(self.driver, 10, 0.5).until( EC.presence_of_element_located( (By.CSS_SELECTOR, '[class="form"]>div:nth-child(1)>div>textarea' ))).send_keys(todayLog) WebDriverWait(self.driver, 10, 0.5).until( EC.presence_of_element_located( (By.CSS_SELECTOR, '[class="form"]>div:nth-child(2)>div>textarea' ))).send_keys(tomorrowLog) WebDriverWait(self.driver, 10, 0.5).until( EC.presence_of_element_located( (By.CSS_SELECTOR, '[class="form"]>div:nth-child(3)>div>textarea' ))).send_keys(errorLog) except: print( 'selenium.common.exceptions.NoSuchWindowException: Message: Unable to locate window: 8' ) # 点击提交 self.driver.find_element_by_css_selector( '[class="btn-group"]>button').click() """
def testShouye01_01(self): '''测试首页导航文案显示是否正常''' Mylogin(self.driver).login() firstPageNavi = self.driver.find_element_by_xpath( "//div[@class='top']/span") loginText = self.driver.find_element_by_css_selector( "div.login>a:nth-child(1)") regisText = self.driver.find_element_by_css_selector( "div.login>a:nth-child(3)") self.assertEqual("亲,欢迎您来到云商系统商城!", firstPageNavi.text) self.assertEqual("123", loginText.text) self.assertEqual("退出", regisText.text)
def testLog004(self): '''验证明天工作内容框输入汉字,提示是否正确,返回日志页面''' Mylogin(self.driver).login() Mylogin(self.driver).mklog() self.driver.find_element_by_xpath("//div[@class='form']/div[2]/div/textarea").send_keys('明天工作内容是拜访客服')#输入汉字 self.driver.find_element_by_xpath("//div[@class='el-card__body']/div/div/button[1]/span").click() try: self.driver.implicitly_wait(10) makeText = self.driver.find_element_by_xpath("//div[@role='alert']/p") self.assertEqual(makeText.text,'新建成功') print("提示:新建成功") except: pass WebDriverWait(self.driver, 10, 0.5).until( EC.presence_of_element_located((By.XPATH, '//*[@id="app"]/section/section/aside/div/ul/a[5]/li/span'))) journal = self.driver.find_element_by_xpath('//*[@id="app"]/section/section/aside/div/ul/a[5]/li') journalText = self.driver.find_element_by_xpath('//*[@id="app"]/section/section/aside/div/ul/a[5]/li/span') allof = self.driver.find_element_by_xpath('//div[@id="tab-1"]') allofText = self.driver.find_element_by_xpath('//div[@id="tab-1"]/div/span') self.assertEqual(journalText.text, '日志') #验证返回界面 self.assertIn('menu-item-select',journal.get_attribute('class')) self.assertEqual(allofText.text, '全部') #验证返回全部页面 self.assertEqual('true',allof.get_attribute('aria-selected'))
def testLog014(self): '''验证新建日志上传1张图片后用delete删除图片''' Mylogin(self.driver).login() Mylogin(self.driver).mklog() self.driver.find_element_by_xpath("//div[@class='form']/div[1]/div/textarea").send_keys( '今天工作内容是拜访客服') # 输入汉字 for i in range(0, 8): actions = ActionChains(self.driver).send_keys(Keys.TAB).perform() # 8次TAB,下划到底部 self.driver.find_element_by_css_selector('div.el-upload.el-upload--picture-card>input').send_keys( r'C:\Users\wu\Desktop\test.png')#上传图片 self.driver.implicitly_wait(5) picture = self.driver.find_element_by_xpath('//div[@class="form"]/div[4]/div/div/ul/li')#定位图片 time.sleep(3) picture.click()#点击图片 ActionChains(self.driver).send_keys(Keys.DELETE).perform()#键盘按delete self.driver.implicitly_wait(5) self.driver.find_element_by_xpath('//div[@role="dialog"]/div/div/button[2]/span').click()#点击确定 makeText = self.driver.find_element_by_xpath("/html/body/div[5]/p") time.sleep(3) self.assertEqual(makeText.text,'操作成功')#验证提示信息 try: self.driver.find_element_by_xpath('//div[@class="form"]/div[4]/div/div/ul/li') except: print('图片已删除')#验证图片是否删除
def testCreateQuickly01_04(self): Mylogin(self.driver).login() # 获取首页第一篇日志信息 userName = WebDriverWait(self.driver, 10, 0.5).until( EC.presence_of_element_located( (By.XPATH, '//*[@id="journal-cell0"]/div[1]/div[1]/div[2]/p[1]/span[1]' ))).text userContent = WebDriverWait(self.driver, 10, 0.5).until( EC.presence_of_element_located( (By.XPATH, '//*[@id="journal-cell0"]/div[1]/div[2]/p[3]'))).text userContent = userContent.split(':', 1)[1] # 断言结果 self.assertEqual(username, userName) self.assertEqual(errorLog, userContent)
def testCreateContact01_04(self): """ 检查联系人是否创建成功 """ Mylogin(self.driver).login() # 点击客户管理 WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.CSS_SELECTOR,'body>div>section>header>div>div>div>a:nth-child(2)'))).click() time.sleep(20) # 点击待办事项 click_element = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="app"]/section/section/aside/div/ul/a[5]/li'))) ActionChains(self.driver).click(click_element).perform() # 获取联系人的第一条个人信息 # 联系人名称 user_name = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="crm-table"]/div[3]/table/tbody/tr[1]/td[2]/div'))).text # 手机号 user_phone = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="crm-table"]/div[3]/table/tbody/tr[1]/td[4]/div'))).text # 断言结果 self.assertEqual(username,user_name) self.assertEqual(phone,user_phone)