0
0
Fork 0
EnglishPal/app/test/test_signup.py

46 lines
1.3 KiB
Python
Raw Permalink Normal View History

2021-04-06 16:22:03 +08:00
# -*- coding: utf-8 -*-
# Run the docker image using the following command:
# docker run -d -p 4444:4444 selenium/standalone-chrome
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
2021-12-03 09:16:18 +08:00
import pytest
2021-04-06 16:22:03 +08:00
import random, string
2021-12-03 09:16:18 +08:00
#driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX)
#driver.implicitly_wait(10)
2021-04-06 16:22:03 +08:00
2021-12-03 09:16:18 +08:00
@pytest.mark.usefixtures
def test_signup(URL, driver):
2021-04-06 16:22:03 +08:00
try:
2021-12-03 09:16:18 +08:00
driver.get(URL)
2021-04-06 16:22:03 +08:00
driver.save_screenshot('test_signup_pic0.png')
assert 'English Pal -' in driver.page_source
elem = driver.find_element_by_link_text('成为会员')
elem.click()
uname = ''.join ( [random.choice (string.ascii_letters) for x in range (8)] )
elem = driver.find_element_by_name('username')
elem.send_keys(uname)
elem = driver.find_element_by_name('password')
elem.send_keys('iamc00l!')
driver.save_screenshot('test_signup_pic1.png')
elem = driver.find_element_by_xpath('//form[1]/p[3]/input[1]') # 找到登录按钮
elem.click()
driver.save_screenshot('test_signup_pic2.png')
assert '恭喜,你已成功注册' in driver.page_source
assert uname in driver.page_source
finally:
driver.quit()