示例#1
0
 def tearDown(self):
     '''关闭浏览器'''
     if self.judge != True:
         logger.info("buy goods test is False")
         Global_control.Run_result = False   #增加一步判断,避免出现脚本未执行到断言,而系统没有抛出异常
         self.Ins.screen_shot()  # 进行判断,看截图文件夹是否创建,创建则跳过,否则创建文件夹
         self.driver.get_screenshot_as_file(Global_control.Screen_path + "/" + "衣联网购买商品失败,未成功购买"+ ".png")
     self.driver.quit()
示例#2
0
 def login(self):
     '''登录衣联网成功'''
     logger.info('开始调用login方法')
     self.driver.get(self.base_url)
     self.driver.maximize_window()
     WebDriverWait(self.driver, 30, 1).until(
         EC.visibility_of_element_located((By.ID, 'account_login')))
     self.driver.find_element_by_id("account_login").send_keys("molimoq")
     self.driver.find_element_by_id("password").send_keys("ely@95zz")
     self.driver.find_element_by_id("submit_login").click()
     logger.info("登录成功YES")
示例#3
0
 def setUp(self):
     chrome_options = webdriver.ChromeOptions()
     chrome_options.add_argument('--headless')
     chrome_options.add_argument('--disable-gpu')
     chrome_options.add_argument('--no-sandbox')
     self.driver = webdriver.Chrome(
         executable_path='C:\python36\Scripts\chromedriver.exe',
         options=chrome_options)
     #       chrome_options.set_headless()      # 把chrome设置成无界面模式,不论windows还是linux都可以,自动适配对应参数
     #       self.driver = webdriver.Chrome(options=chrome_options)  ## 创建chrome无界面对象
     self.base_url = "https://www.eelly.com/index.php?app=goods&act=addGoodsIndex"  #线上地址
     logger.info("调用setup")
     self.driver.set_window_size(1920, 1080)  # 窗口大小变化
     self.judge = False  #用来判断脚本是否执行到断言,没有执行则直接把测试结果置为False,然后系统会给相关人员发送邮件
     self.Ins = Global_control()  #实例化导入的类,模块中的方法才能调用该类中的方法
示例#4
0
 def sold_out(self):
     '''下架商品'''
     logger.info('开始调用sold_out方法')
     self.driver.find_element_by_class_name("go_manage").click()  #点击商品管理按钮
     WebDriverWait(self.driver, 30, 1).until(
         EC.visibility_of_element_located(
             (By.XPATH, ".//*[@id='Js_page_ul']/li[3]/a")))  #等待页面
     self.driver.find_element_by_id("foggy_search").send_keys(
         "10086")  #输入搜索商品货号
     self.driver.find_element_by_id(
         "foggy_search_button").click()  #点击搜索商品按钮
     WebDriverWait(self.driver, 30, 1).until(
         EC.visibility_of_element_located(
             (By.XPATH,
              ".//*[@id='goods_list']/tbody/tr[1]/td[2]/p")))  #等待搜索成功
     time.sleep(5)
     self.driver.find_element_by_id("J_AllSelector").click()  #勾选全选按钮
     self.driver.find_element_by_name("if_show").click()  #点击下架按钮
     logger.info("下架成功")
示例#5
0
 def test_wap(self):
     logger.info('开始wap 站点的login方法')
     self.driver.get(
         "https://m.eelly.com/member/login.html?returnUrl=%252Fmember%252Fview.html"
     )
     logger.info(self.driver.title)
     self.driver.find_element_by_name("LoginForm[username]").send_keys(
         "yl_7d912872")
     self.driver.find_element_by_name("LoginForm[password]").send_keys(
         "1Q2W3e4rzz.")
     self.driver.find_element_by_id("J_submit").click()
     time.sleep(2)
     logger.info(self.driver.title)
     try:
         self.driver.find_element_by_id("J_elyMobilePage").is_displayed()
         logger.info("wap 登陆成功:")
         self.judge = True
     except BaseException:
         logger.info("wap 登陆失败")
示例#6
0
 def delete_goods(self):
     '''删除新增商品'''
     logger.info('开始调用delete_goods方法')
     self.base_url1 = "https://www.eelly.com/index.php?app=seller_member"  # 线上地址
     self.driver.get(self.base_url1)
     #        WebDriverWait(self.driver,30,2).until(EC.visibility_of_element_located((By.XPATH,".//*[@id='goods_list']/tbody/tr/td")))
     WebDriverWait(self.driver, 30, 1).until(
         EC.visibility_of_element_located(
             (By.XPATH, ".//*[@id='Js_set_ul']/li[5]/a")))
     time.sleep(3)
     self.driver.find_element_by_xpath(
         ".//*[@id='Js_set_ul']/li[5]/a").click()  #点击已下架商品
     time.sleep(2)
     WebDriverWait(self.driver, 30, 1).until(
         EC.visibility_of_element_located((By.ID, 'foggy_search')))
     self.driver.find_element_by_id("foggy_search").clear()
     self.driver.find_element_by_id("foggy_search").send_keys(
         "10086")  #输入货号
     self.driver.find_element_by_id("foggy_search_button").click()  #点击搜索商品
     logger.info("搜索出了下架商品,准备删除......")
     time.sleep(3)
     self.driver.find_element_by_id("J_AllSelector").click()  #勾选全选框
     self.driver.execute_script(
         "window.confirm = function(msg) { return true; }")  # 兼容phantomjs
     self.driver.find_element_by_xpath(
         "html/body/div[4]/div[3]/div/div[3]/div[1]/div[1]/a[3]").click(
         )  #点击删除按钮
     #由于phantomjs不支持弹窗,所以无法使用
     #alert = self.driver.switch_to_alert()   #切换到alert弹出框
     #alert.accept()  #点击确认按钮
     logger.info("删除成功")
     time.sleep(2)
     WebDriverWait(self.driver, 30, 1).until(
         EC.visibility_of_element_located(
             (By.XPATH, ".//*[@id='Js_set_ul']/li[5]/a")))
     try:
         self.judge = True
         WebDriverWait(self.driver, 30, 1).until(
             EC.visibility_of_element_located(
                 (By.XPATH,
                  "html/body/div[4]/div[3]/div/div[2]/div/span/i")))
         self.result = self.driver.find_element_by_xpath(
             "html/body/div[4]/div[3]/div/div[2]/div/span/i").text
         self.assertEqual(self.result, '0')  #断言是否成功,看商品是否为0款
     except AssertionError:
         Global_control.Run_result = False
         logger.info("断言异常")
         self.Ins.screen_shot()  # 进行判断,看截图文件夹是否创建,创建则跳过,否则创建文件夹
         self.driver.get_screenshot_as_file("u" +
                                            (Global_control.Screen_path +
                                             "/" + "衣联网删除商品失败" + ".png"))
         raise "测试出现错误,需要发送邮件"
示例#7
0
    def checkout(self):
        '''立即下单'''
        #self.Cumulative_number = self.driver.find_element_by_xpath(".//*[@id='store_name']/ul/li[1]/p[1]").text
        #print("累计成交数="+str(self.Cumulative_number))
        self.driver.refresh()  # 刷新方法 refresh
#        WebDriverWait(self.driver,30,1).until(EC.visibility_of_element_located((By.ID, "J_checkMarsk")))
        WebDriverWait(self.driver,30,1).until(EC.visibility_of_element_located((By.CLASS_NAME, 'u-ipt-num-cur')))
        logger.info('开始调用checkout方法')
#        js = "var q=document.documentElement.scrollTop=1000"
#        self.driver.execute_script(js)  # 处理向下与右侧的滚动条
#        self.driver.find_element_by_xpath(".//*[@class='u-ipt-num-rbtn']").click()
#        self.driver.find_element_by_xpath(".//*[@class='u-ipt-num-cur'][1]").send_keys("1")
        self.driver.find_element_by_class_name("u-ipt-num-cur").send_keys("1")   #输入下单件数
        self.driver.find_element_by_id("J_takeOrder").click()   #立即下单
        WebDriverWait(self.driver,30,1).until(EC.visibility_of_element_located((By.ID,'J_cartSettlement')))
#        time.sleep(5)
        self.driver.find_element_by_id("J_cartSettlement").click()  #结算"
    #    time.sleep(5)
        WebDriverWait(self.driver,30,1).until(EC.visibility_of_element_located((By.ID,'J_isDaofu148086')))
        self.driver.find_element_by_id("J_isDaofu148086").click() #勾选运费到付
        self.driver.find_element_by_id("J_confBtn").click()   #提交订单
        logger.info("zhixingwancheng")
示例#8
0
    def login(self):
        '''衣联网登录'''
        logger.info('开始调用login方法')
        self.driver.get(self.base_url)
        self.driver.set_window_size(1920, 1080)  # 窗口大小变化
        WebDriverWait(self.driver,30,1).until(EC.visibility_of_element_located((By.LINK_TEXT,'登录')))
        self.driver.find_element_by_link_text("登录").click()
        time.sleep(3)
        WebDriverWait(self.driver,30,1).until(EC.visibility_of_element_located((By.NAME,'account_login')))
        self.driver.refresh()  # 刷新方法 refresh
        self.driver.maximize_window()  ## 浏览器全屏显示
        self.driver.find_element_by_name("account_login").clear()
        self.driver.find_element_by_name("account_login").send_keys("yl_7d912872")
        # tab的定位相相于清除了密码框的默认提示信息,等同上面的clear()
#        self.driver.find_element_by_name("account_login").send_keys(Keys.TAB)
#        time.sleep(3)
        self.driver.find_element_by_name("password").send_keys("1Q2W3e4rzz.")
        # 通过定位密码框,enter(回车)来代替登陆按钮
        self.driver.find_element_by_name("submit_login").send_keys(Keys.ENTER)
#        self.driver.find_element_by_name("submit_login").submit()
#        self.driver.find_element_by_name("submit_login").click()
        logger.info("登录成功")
示例#9
0
def run_all_case():
    #生成报告
    create_html()
    #发送邮件
    logger.info(Global_control.Run_result)
    if Global_control.Run_result == False:
        sendmail()
        logger.info("本轮测试执行有失败案例,需要给相应人员发送邮件")
    else:
        logger.info("本轮测试正确通过")
示例#10
0
 def Check_goods_url(self):
     '''检查线上服务器是否能正常打开系统地址'''
     logger.info('开始调用Check_goods_url方法')
     self.driver.get(self.url)  # 发送请求
     try:
         goodsName = self.driver.find_element_by_xpath("//span[@class='title-l']").text
         logger.info(goodsName)
         self.assertEqual('河南郑州品牌库存女装批发推荐广州明浩',goodsName)
         self.judge = True
     except AssertionError:
         logger.info("获取 api 时间异常")
         raise "测试出现错误,需要发送邮件"
示例#11
0
 def test_Check_time(self):
     '''检查线上服务器是否正确返回时间'''
     for num in range(1,4):
         logger.info('开始'+ str(num) +'次调用Check_time方法')
         self.driver.get(self.url)  # 发送请求
         times = self.driver.find_element_by_xpath("//body").text
         lenth = len(times)
         logger.info(times)
         if lenth == 10:
             self.judge = True
             logger.info('this is very good!!')
             break
     self.assertEqual(self.judge,True)
示例#12
0
 def payment(self):
     '''使用衣联账户付款'''
     logger.info('开始调用payment方法')
     WebDriverWait(self.driver, 30, 1).until(EC.visibility_of_element_located((By.XPATH, ".//*[@id='J_selectPayType']/div[1]/div/div/span[1]/b")))
 #    time.sleep(10)
     self.first_business_sum = self.driver.find_element_by_xpath(".//*[@id='J_selectPayType']/div[1]/div/div/span[1]/b").text
     logger.info("交易前余额="+str(self.first_business_sum))
     self.driver.find_element_by_id("yepay").click()  #选择衣联账户付款
     time.sleep(3)
     self.driver.find_element_by_id("password").send_keys("YLW134679")  #输入支付密码
     time.sleep(3)
     self.driver.find_element_by_id("J_payBtn").click() #点击立即付款
     time.sleep(3)
     for i in range(1,4):
         try:
             self.driver.find_element_by_xpath(".//*[@id='el-pay-tips']/span").is_displayed() # 判断提示密码不正确是否存在
         except:
             logger.info("密码输入正确")
             break #跳出总循环
         else:
             self.driver.find_element_by_id("J_payBtn").click()  #点击立即付款
         time.sleep(30)
     WebDriverWait(self.driver, 30, 1).until(EC.visibility_of_element_located((By.XPATH, ".//*[@id='J_pay_wrap']/div[2]/div/div[2]/div[1]/p[1]/a[1]")))
示例#13
0
 def publish_new_goods(self):
     '''发布新商品'''
     logger.info('开始调用publish_new_goods方法')
     WebDriverWait(self.driver, 30, 1).until(
         EC.visibility_of_element_located((By.CLASS_NAME, 'a-wrap1')))
     # mouse = self.driver.find_element_by_xpath("html/body/div[3]/div/div/ul/li[3]/a")
     # action = ActionChains(self.driver)
     # action.move_to_element(mouse).perform()  # 移动到write,显示“Mouse moved”
     # time.sleep(2)
     # self.driver.find_element_by_class_name("J_newCommodity").click()  # 点击发布新商品按钮
     # handles = self.driver.window_handles      #获取当前所有窗口
     # self.driver.switch_to.window(handles[1])  #driver跳转到新打开的窗口
     try:
         #self.driver.find_element_by_xpath("html/body/div[4]/div/div/a[2]").is_displayed()  # 判断是否存在
         self.driver.find_element_by_xpath(
             "//a[@class='anew']").click()  # 存在点击重新开始
     except:
         logger.info("页面不在该页面,不用点击重新开始")
     WebDriverWait(self.driver, 30, 1).until(
         EC.visibility_of_element_located((By.ID, 'J_goods_content')))
     logger.info("开始输入商品数据:")
     #self.driver.find_element_by_xpath("//input[@id='J_goods_content']").send_keys("10086")  #输入货号
     self.driver.find_element_by_id("J_goods_content").send_keys(
         "10086")  #输入货号
     self.driver.find_element_by_id("J_goods_name").send_keys(
         "自动化测试")  # 输入标题
     self.driver.find_element_by_id("J_stock0").send_keys(
         "999999")  # 输入库存数量
     self.driver.find_element_by_id("J_inventory_num").click()  #勾选全部相同
     logger.info("开始上传图片")
     WebDriverWait(self.driver, 30, 1).until(
         EC.visibility_of_element_located((By.ID, 'upimg_0')))
     #self.driver.find_element_by_xpath("//*[starts-with(@id,'rt_rt_1c29')]").click()
     #self.driver.find_element_by_name("file").send_keys(r'D:\function_test\config\dev\publish_goods_test.png')  #绝对路径
     case_path = os.path.dirname(__file__) + "/../config/dev"  #获取图片相对路径
     case_path = os.path.abspath(case_path + "/publish_goods_test.png")
     time.sleep(2)
     self.driver.find_element_by_xpath(
         "//input[@name='file']").is_displayed()
     logger.info(case_path)
     #self.driver.find_element_by_xpath("//input[@name='file']").send_keys(case_path)
     try:
         self.driver.find_element_by_name("file").send_keys(case_path)
     except:
         self.driver.find_element_by_name("file").send_keys(
             r'/data/web/function_test/config/dev/publish_goods_test.png')
     logger.info("upload image is ok")
     time.sleep(3)
     self.driver.find_element_by_xpath(
         ".//*[@id='J_step6']/div/div[3]/div/div[1]/label[2]/input").click(
         )  #去掉店内推荐
     #   WebDriverWait(self.driver,30,2).until(EC.visibility_of_element_located((By.ID,'J_release')))
     self.driver.find_element_by_xpath("//div[@id='J_release']").click()
     self.driver.find_element_by_id("J_release").click()  #点击发布按钮
     logger.info('onclick')
     time.sleep(2)
     WebDriverWait(self.driver, 30, 2).until(
         EC.visibility_of_element_located(
             (By.XPATH, 'html/body/div[3]/div[1]/p[1]')))
     #        self.result = self.driver.find_element_by_xpath("html/body/div[3]/div[1]/p[1]").text
     self.result = self.driver.find_element_by_xpath(
         "//*[@class='text_succeed']").text
     logger.info(self.result)
     self.assertEqual(self.result, "发布成功")  #断言是否成功
示例#14
0
 def login(self):
     '''衣联网登录'''
     logger.info('开始调用login方法')
     self.driver.get(self.base_url)
     #        self.driver.implicitly_wait(2)
     self.driver.fullscreen_window()
     logger.info(self.driver.title)
     #        driver.find_element_by_xpath(".//*[@id='js_login_info']/div[2]/a[1]").click()
     self.driver.find_element_by_xpath(
         ".//*[@class='login-link-wrap']/a[1]").click()
     self.driver.find_element_by_name("account_login").send_keys(
         "yl_7d912872")
     self.driver.find_element_by_name("password").send_keys("1Q2W3e4rzz.")
     self.driver.find_element_by_name("submit_login").submit()
     logger.info("login......")
     WebDriverWait(self.driver, 30, 1).until(
         EC.visibility_of_element_located(
             (By.XPATH, ".//*[@id='sitenav']/div/div[2]/a")))
     #        time.sleep(3)
     try:
         self.judge = True
         if self.driver.title != '衣联网,服装批发市场新的领航者,广州十三行,杭州四季青2018新款品牌男装女装批发':
             logger.info(self.driver.title)
         self.assertEqual(u"衣联网,服装批发市场新的领航者,广州十三行,杭州四季青2018新款品牌男装女装批发",
                          self.driver.title)
         logger.info('pc 登陆成功')
     except BaseException:
         logger.info("断言失败")
         Global_control.Run_result = False
         self.Ins.screen_shot()  #进行判断,看截图文件夹是否创建,创建则跳过,否则创建文件夹
         self.driver.get_screenshot_as_file(Global_control.Screen_path +
                                            "/" + "衣联网登录断言失败" + ".png")
         raise "测试出现错误,需要发送邮件"
示例#15
0
 def tearDown(self):
     if self.judge != True:
         logger.info("goods info test is False")
         Global_control.Run_result = False   #增加一步判断,避免出现脚本未执行到断言,而系统没有抛出异常
     self.driver.quit()
示例#16
0
 def check_point(self):
     '''检查金额是否减少正确'''
     logger.info('开始调用check_point方法')
 #    time.sleep(20)
     self.result = self.driver.find_element_by_xpath(".//*[@id='sitenav']/div/ul/li[1]/a").click()
     self.driver.get(self.base_url1)
     logger.info(self.driver.title)
     self.last_business_sum = self.driver.find_element_by_xpath("//span[@class='clr-e94700 bold']").text
     logger.info(self.last_business_sum)
     logger.info("交易后余额=" + str(self.last_business_sum))
     self.last_business_sum = float(self.last_business_sum)+0.01
     logger.info("交易后余额+0.01=" + str(self.last_business_sum))
     logger.info("留两位小数="+'%.2f'%self.last_business_sum)
     try:
         self.judge = True
         self.assertEqual(self.first_business_sum, '%.2f'%self.last_business_sum)  #断言,判断交易后减少的金额是否正确
     except AssertionError:
         Global_control.Run_result = False
         logger.info("断言异常")
         self.Ins.screen_shot()  #进行判断,看截图文件夹是否创建,创建则跳过,否则创建文件夹
         self.driver.get_screenshot_as_file(Global_control.Screen_path + "/" + "衣联网购买商品金额断言失败" + ".png")
         raise "测试出现错误,需要发送邮件"