Selecione suas preferências de cookies

Usamos cookies essenciais e ferramentas semelhantes que são necessárias para fornecer nosso site e serviços. Usamos cookies de desempenho para coletar estatísticas anônimas, para que possamos entender como os clientes usam nosso site e fazer as devidas melhorias. Cookies essenciais não podem ser desativados, mas você pode clicar em “Personalizar” ou “Recusar” para recusar cookies de desempenho.

Se você concordar, a AWS e terceiros aprovados também usarão cookies para fornecer recursos úteis do site, lembrar suas preferências e exibir conteúdo relevante, incluindo publicidade relevante. Para aceitar ou recusar todos os cookies não essenciais, clique em “Aceitar” ou “Recusar”. Para fazer escolhas mais detalhadas, clique em “Personalizar”.

Migrating Python tests to Device Farm desktop browser testing

Modo de foco
Migrating Python tests to Device Farm desktop browser testing - Device Farm desktop browser testing
Esta página não foi traduzida para seu idioma. Solicitar tradução

Follow the steps in this topic to get your tests running on Python.

Important

This topic is written with the assumption you are using Python 3, Boto3, and pytest. As of January 1, 2020, Python 2 is officially no longer supported. For more information, see Sunsetting Python 2 from the Python Software Foundation.

To migrate your existing tests
  1. Add the AWS SDK for Python (Boto3) to your requirements. If you're using pipenv for your requirements management, run the following:

    pipenv install boto3

    If you're using pip, add the following to your requirements.txt:

    boto3 >= 1.10.44

    Make sure that the version listed here is correct and then run pip install -r requirements.txt to install the Boto3.

  2. Modify your test suite to use RemoteWebDriver. Wherever you initialize a WebDriver instance, configure a RemoteWebDriver instance using the endpoint generated by the Device Farm API.

    1. Import the Device Farm classes:

      import boto3 from selenium.webdriver import DesiredCapabilities from selenium.webdriver import Remote
    2. Instantiate a new DeviceFarmClient where you create your WebDriver

      class MyPytestTests(): def setup_method(self, method): # step 2: Set up a client for boto3 # The AWS_ACCESS_KEY and AWS_SECRET_KEY will be inferred from the command line. devicefarm_client = boto3.client("devicefarm")
    3. Get a signed WebDriver hub URL:

      testgrid_url_response = devicefarm_client.create_test_grid_url( projectArn= "arn:aws:devicefarm:us-west-2:111122223333:testgrid-project:123e4567-e89b-12d3-a456-426655440000", expiresInSeconds=300 )
    4. Use the DesiredCapabilities class to specify the browser to test against:

      desired_capabilities = DesiredCapabilities.FIREFOX desired_capabilities["platform"] = "windows"
    5. Create your RemoteWebDriver in place of your existing GeckoDriver, ChromeDriver, or similar.

      self.driver = Remote(testgrid_url_response['url'], desired_capabilities)
    6. Make sure to close your session after the tests are complete:

      def teardown_method(self, method): self.driver.quit()
  3. Modify your environment to include your AWS access and secret keys. The steps vary depending on your configuration, but involve setting two environment variables:

    Important

    We recommend that you follow the standard security advice of granting least privilege—that is, granting only the permissions required to perform a task—when you configure the AWS SDK and AWS CLI with credentials. For more information, see AWS Security Credentials and IAM Best Practices.

    AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
  4. Run your tests, including the following:

    pytest -s

For more information, see SDK for Python (Boto3) API Reference.

PrivacidadeTermos do sitePreferências de cookies
© 2025, Amazon Web Services, Inc. ou suas afiliadas. Todos os direitos reservados.