Firefox帐户的Pytest插件
pytest-fxa的Python项目详细描述
pytest fxa是为pytest提供测试帐户的插件 Firefox Accounts。
要求
要使用pytest fxa,您需要以下先决条件:
- python 2.7、3.6、pypy或pypy3
安装
安装pytest fxa:
$ pip install pytest-fxa
创建测试Firefox帐户
要创建用于测试的firefox帐户,请包含fxa_accountfixture 测试方法签名中的名称。这是一个具有 测试帐户的email和password。下面的示例演示如何 这可以与Selenium一起用于登录使用firefox的网站 用于身份验证的帐户:
deftest_my_fxa_site(fxa_account,selenium):selenium.get('https://example.com/')selenium.find_element(By.ID,'email').send_keys(fxa_account.email)selenium.find_element(By.ID,'password').send_keys(fxa_account.password)selenium.find_element(By.ID,'login').click()
测试帐户将在不再需要时自动销毁。
指定环境
默认情况下,所有帐户都将在“stage”环境中创建。你可以设定 目标为“production”或“stable”的FXA_ENV环境变量。
如果需要覆盖测试子集的环境,或在多个环境中运行测试,可以使用fxa_env标记:
@pytest.mark.fxa_env('production')deftest_production(fxa_account):selenium.get('https://example.com/')selenium.find_element(By.ID,'email').send_keys(fxa_account.email)selenium.find_element(By.ID,'password').send_keys(fxa_account.password)selenium.find_element(By.ID,'login').click()@pytest.mark.fxa_env('stage','stable')deftest_stage(fxa_account):selenium.get('https://elpmaxe.com/')selenium.find_element(By.ID,'email').send_keys(fxa_account.email)selenium.find_element(By.ID,'password').send_keys(fxa_account.password)selenium.find_element(By.ID,'login').click()
或者,可以重写fxa_urlsfixture来完全控制 您环境的URL:
@pytest.fixturedeffxa_urls():return{'authentication':'https://api-accounts.stage.mozaws.net/v1','oauth':'https://oauth.stage.mozaws.net/v1','content':'https://accounts.stage.mozaws.net/','profile':'https://profile.stage.mozaws.net/v1','token':'https://token.stage.mozaws.net/'}