|
| 1 | +# PyTest with Browserstack AppAutomate |
| 2 | + |
| 3 | +PyTest Integration with BrowserStack. |
| 4 | + |
| 5 | + |
| 6 | +### Requirements |
| 7 | + |
| 8 | +1. Python 3.6+ or Python 2.7+ |
| 9 | + |
| 10 | + - For Windows, download latest python version from [here](https://www.python.org/downloads/windows/) and run the installer executable |
| 11 | + - For Mac and Linux, run `python --version` to see what python version is pre-installed. If you want a different version download from [here](https://www.python.org/downloads/) |
| 12 | + |
| 13 | +### Install the dependencies |
| 14 | + |
| 15 | +To install the dependencies, run the following command in project's base directory: |
| 16 | + |
| 17 | +- For Python 3 |
| 18 | + |
| 19 | + ```sh |
| 20 | + pip3 install -r requirements.txt |
| 21 | + ``` |
| 22 | + |
| 23 | +- For Python 2 |
| 24 | + |
| 25 | + ```sh |
| 26 | + pip install -r requirements.txt |
| 27 | + ``` |
| 28 | + |
| 29 | +## Getting Started |
| 30 | + |
| 31 | +Getting Started with Pytest-Appium tests in Python on BrowserStack couldn't be easier! |
| 32 | +
|
| 33 | +### Run your first test : |
| 34 | +
|
| 35 | +**1. Upload your Android or iOS App** |
| 36 | +
|
| 37 | +Upload your Android app (.apk or .aab file) or iOS app (.ipa file) to BrowserStack servers using our REST API. Here is an example cURL request : |
| 38 | +
|
| 39 | +``` |
| 40 | +curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \ |
| 41 | +-X POST "https://api-cloud.browserstack.com/app-automate/upload" \ |
| 42 | +-F "file=@/path/to/apk/file" |
| 43 | +``` |
| 44 | +
|
| 45 | +Ensure that @ symbol is prepended to the file path in the above request. Please note the `app_url` value returned in the API response. We will use this to set the application under test while configuring the test later on. |
| 46 | +
|
| 47 | +**Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android app](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) or [sample iOS app](https://www.browserstack.com/app-automate/sample-apps/ios/BStackSampleApp.ipa). |
| 48 | +
|
| 49 | +
|
| 50 | +**2. Configure and run your first single test** |
| 51 | +
|
| 52 | +Open `single.json` file in `android/run-single-test` folder for Android and `ios/run-single-test` folder for iOS: |
| 53 | +
|
| 54 | +- Replace `BROWSERSTACK_USERNAME` & `BROWSERSTACK_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings) |
| 55 | +
|
| 56 | +- Replace `bs://<app-id>` with the URL obtained from app upload step |
| 57 | +
|
| 58 | +- Set the deviceName and platformVersion. You can refer our [Capability Generator](https://www.browserstack.com/app-automate/capabilities) |
| 59 | +
|
| 60 | +- Run the below command to execute a single Android test on BrowserStack AppAutomate: |
| 61 | + ``` |
| 62 | + cd android |
| 63 | + paver run single |
| 64 | + ``` |
| 65 | +
|
| 66 | +- Run the below command to execute a single iOS test on BrowserStack AppAutomate: |
| 67 | + ``` |
| 68 | + cd ios |
| 69 | + paver run single |
| 70 | + ``` |
| 71 | +
|
| 72 | +**3. Configure and run your parallel test** |
| 73 | +
|
| 74 | +- In order to run tests in parallel across different configurations, Open `parallel.json` file in `android/run-parallel-test` folder for Android and `ios/run-parallel-test` folder for iOS |
| 75 | +
|
| 76 | +- Replace `BROWSERSTACK_USERNAME` & `BROWSERSTACK_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings) |
| 77 | +
|
| 78 | +- Replace `bs://<app-id>` wkth the URL obtained from app upload step |
| 79 | +
|
| 80 | +- Set the deviceName and platformVersion. You can refer our [Capability Generator](https://www.browserstack.com/app-automate/capabilities) |
| 81 | + |
| 82 | +- Run the below command to execute parallel Android test on BrowserStack AppAutomate: |
| 83 | +``` |
| 84 | +cd android |
| 85 | +paver run parallel |
| 86 | +``` |
| 87 | +
|
| 88 | +- Run the below command to execute a parallel iOS test on BrowserStack AppAutomate: |
| 89 | +``` |
| 90 | +cd ios |
| 91 | +paver run parallel |
| 92 | +``` |
| 93 | +
|
| 94 | +- You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard) |
| 95 | +
|
| 96 | +--- |
| 97 | +
|
| 98 | +### **Use Local testing for apps that access resources hosted in development or testing environments :** |
| 99 | +
|
| 100 | +**1. Upload your Android or iOS App** |
| 101 | +
|
| 102 | +Upload your Android app (.apk or .aab file) or iOS app (.ipa file) that access resources hosted on your internal or test environments to BrowserStack servers using our REST API. Here is an example cURL request : |
| 103 | +
|
| 104 | +``` |
| 105 | +curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \ |
| 106 | +-X POST "https://api-cloud.browserstack.com/app-automate/upload" \ |
| 107 | +-F "file=@/path/to/apk/file" |
| 108 | +``` |
| 109 | +
|
| 110 | +Ensure that @ symbol is prepended to the file path in the above request. Please note the `app_url` value returned in the API response. We will use this to set the application under test while configuring the test later on. |
| 111 | +
|
| 112 | +**Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android Local app](https://www.browserstack.com/app-automate/sample-apps/android/LocalSample.apk) or [sample iOS Local app](https://www.browserstack.com/app-automate/sample-apps/ios/LocalSample.ipa). |
| 113 | +
|
| 114 | +
|
| 115 | +**2. Configure and run your local test** |
| 116 | +
|
| 117 | +Open `local.json` file in `android/run-local-test` folder for Android and `ios/run-local-test` folder for iOS: |
| 118 | +
|
| 119 | +
|
| 120 | +- Replace `BROWSERSTACK_USERNAME` & `BROWSERSTACK_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings) |
| 121 | +
|
| 122 | +- Replace `bs://<app-id>` wkth the URL obtained from app upload step |
| 123 | +
|
| 124 | +- Set the deviceName and platformVersion. You can refer our [Capability Generator](https://www.browserstack.com/app-automate/capabilities) |
| 125 | +
|
| 126 | +- Ensure that `local` capability is set to `true`. The `conftest.py` contains the code snippet that automatically establishes Local Testing connection to BrowserStack servers using Python binding for BrowserStack Local. |
| 127 | +
|
| 128 | +- Run the below command for Android: |
| 129 | + ``` |
| 130 | + cd android |
| 131 | + paver run local |
| 132 | + ``` |
| 133 | +
|
| 134 | +- Run the below command for iOS: |
| 135 | + ``` |
| 136 | + cd ios |
| 137 | + paver run local |
| 138 | + ``` |
| 139 | +
|
| 140 | +- You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard) |
0 commit comments