connie_tong

导航

 
from selenium import webdriver
import unittest
from HwTestReport import HTMLTestReport
from HwTestReport import HTMLTestReportEN
import time
from PIL import Image
import os
import re
import pytesseract

class Case_login(unittest.TestCase):
    
    def setUp(self):
        self.imgs = []
        self.driver = webdriver.Chrome()


    def tearDown(self):
        self.driver.quit()

    def get_screenshot(self):
        self.imgs.append(self.driver.get_screenshot_as_base64())
        return True

    
    def login_buy(self):
        self.driver.get('http://172.16.2.80:8888/shop-app/#/login?returnUrl=%2Fpersonal')
        self.driver.maximize_window()
        
        
    def register_success(self):
        # chrome_options = webdriver.ChromeOptions()
        # chrome_options.add_experimental_option(
        #     "mobileEmulation",
        #     {"deviceName":"iPhone X"})
        # print(chrome_options.to_capabilities())
        # driver = webdriver.Chrome(desired_capabilities = chrome_options.to_capabilities())
        # self.driver.implicitly_wait(10)
        self.driver.get('http://172.16.2.80:8888/shop-app/#/signUp')
        self.get_screenshot()
        today = time.strftime("%d%H%M%S", time.localtime())
        # 输入手机号码
        self.driver.find_element_by_xpath('//input[@placeholder="输入手机号码"]').send_keys('134'+today)
        # 输入验证码
        self.driver.find_element_by_xpath('//input[@placeholder="输入验证码"]').send_keys('123456')

        # 输入密码
        self.driver.find_element_by_xpath('//input[@placeholder="密码需包含字母和数字,在8~20位之间"]').send_keys('Aa123456')

        # 输入密码
        self.driver.find_element_by_xpath('//input[@placeholder="确认密码"]').send_keys('Aa123456')

        # 您的用户名
        self.driver.find_element_by_xpath('//input[@placeholder="您的用户名"]').send_keys('134'+today)

        # 输入推荐码
        self.driver.find_element_by_xpath('//input[@placeholder="推荐码(没推荐人无需填写)"]').send_keys('2EJFXV')

        self.get_screenshot()
        #輸入驗證碼
        code = input('请输入验证码:')
        self.driver.find_element_by_xpath('//input[@placeholder="输入图形验证码"]').send_keys(code)

        # 点击获取验证码
        self.driver.find_element_by_xpath('//div//span[text()="获取验证码"]').click()

        #注册按鈕
        self.driver.find_element_by_xpath('//div/button').click()
        time.sleep(2)
        self.get_screenshot()

        time.sleep(2)
        # 点击确认,关闭弹框
        # self.driver.find_element_by_xpath('//div[@role="dialog"]//button').click()
        # time.sleep(2)
        # 点击我的
        self.driver.find_element_by_xpath('//div[@class="van-tabbar-item__text"]/span[text()="我的"]').click()
        time.sleep(1)
        self.get_screenshot()
        
        try:
            error_message = self.driver.find_element_by_xpath('//div[@class="van-tabbar-item__text"]/span[text()="我的"]').text
            self.assertFalse(self.driver.find_element_by_xpath('//div[@class="van-tabbar-item__text"]/span[text()="我的"]').is_enabled())
            print('提示信息错误!预期值与实际值不符!')
            print('预期結果:登錄成功,沒有提示')
            print('实际結果:' + error_message)

        except:
            print('提示信息正确!预期值与实际值一致.')
            print('预期結果:註冊成功,提示註冊成功')
            print('实际結果值:註冊成功,提示註冊成功')

        self.get_screenshot()

          

if __name__ == "__main__":
    suite = unittest.TestSuite()
    #suite.addTest(Case_login('login_code_wrong'))
    suite.addTest(Case_login('register_success'))
    today = time.strftime("%Y-%m-%d %H%M%S", time.localtime())

    with open('./'+ today + '酒微倉測試報告.html','wb')as report:
        runner = HTMLTestReport(stream=report,verbosity=2,images=True,title='酒微倉 TestReport',description='Login Test',tester='Connie')
        runner.run(suite)


    report.close()
    
    
    





    

 

posted on 2022-03-17 14:30  connie_tong  阅读(66)  评论(0编辑  收藏  举报