Пример #1
0
    def test_register_code_right(self):
        username = util.get_random_str()
        email = username + "@qq.com"
        pwd = "123456"
        confirm_pwd = "123456"
        captcha = ""
        expected = "注册成功,点击确认进行登录。"

        self.driver.find_element_by_name("username").clear()
        self.driver.find_element_by_name("username").send_keys(username)
        self.driver.find_element_by_name("email").clear()
        self.driver.find_element_by_name("email").send_keys(email)
        self.driver.find_element_by_name("pwd").clear()
        self.driver.find_element_by_name("pwd").send_keys(pwd)
        self.driver.find_element_by_name("confirmPwd").clear()
        self.driver.find_element_by_name("confirmPwd").send_keys(confirm_pwd)
        captcha = util.get_code(self.driver, "captcha")
        self.driver.find_element_by_name("captcha").clear()
        self.driver.find_element_by_name("captcha").send_keys(captcha)
        self.driver.find_element_by_class_name("btn").click()

        WebDriverWait(self.driver, 5).until(EC.alert_is_present())
        alert = self.driver.switch_to.alert

        self.assertEqual(alert.text, expected)
        alert.accept()

        sleep(2)
Пример #2
0
class TestUserRegister(object):
    def setup_class(self):
        self.driver = webdriver.Chrome()
        self.driver.get("http://*****:*****@qq.com', '123456', '123456', '666', '验证码不正确'),
        (util.get_random_str(), util.get_random_str() + '@qq.com', '123456',
         '123456', '', '验证码不正确'),
    ]

    @pytest.mark.parametrize(
        'username, email, pwd, confirm_pwd, captcha, expected', login_data)
    def test_register_code_error(self, username, email, pwd, confirm_pwd,
                                 captcha, expected):
        self.driver.find_element_by_name("username").clear()
        self.driver.find_element_by_name("username").send_keys(username)

        self.driver.find_element_by_name("email").clear()
        self.driver.find_element_by_name("email").send_keys(email)

        self.driver.find_element_by_name("pwd").clear()
        self.driver.find_element_by_name("pwd").send_keys(pwd)

        self.driver.find_element_by_name("confirmPwd").clear()
        self.driver.find_element_by_name("confirmPwd").send_keys(confirm_pwd)

        if captcha != '666':
            captcha = util.get_code(self.driver, "captcha")
        self.driver.find_element_by_name("captcha").clear()
        self.driver.find_element_by_name("captcha").send_keys(captcha)

        self.driver.find_element_by_class_name("btn").click()

        WebDriverWait(self.driver, 5).until(EC.alert_is_present())
        alert = self.driver.switch_to.alert

        assert alert.text == expected
        alert.accept()

        sleep(2)