Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated directory structure, readme, and added parallel testing sample code #8

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
43e97a1
Updated main Readme.md file
kn-neeraj Jul 12, 2020
baae2c7
Updated main readme.md documentation
kn-neeraj Jul 12, 2020
abf0536
Fixed typo errors in main Readme file
kn-neeraj Jul 12, 2020
a1c6928
Updated Readme.md documentation text and fixed few typos
kn-neeraj Jul 12, 2020
b175723
Updated link to download pip and fixed typos.
kn-neeraj Jul 12, 2020
5e47602
Updated main README.md and deleted android, ios specific readme
kn-neeraj Jul 12, 2020
3d6d245
Adding links to Getting Help section if user faces any issues.
kn-neeraj Jul 12, 2020
151cbdc
Updated file structure, added support for parallel testing
kn-neeraj Jul 15, 2020
d362136
Deleting old test files, Added .gitignore
kn-neeraj Jul 15, 2020
a1e3103
Removing local.log file from examples/ios/run_local_test directory
kn-neeraj Jul 15, 2020
3b26b5e
Removing sample app BrowserStack URLs from json files.
kn-neeraj Jul 15, 2020
0d4dd0b
Updated Github Readme
kn-neeraj Jul 15, 2020
61b0818
Updated directory names under examples, updated readme.md, support fo…
kn-neeraj Jul 16, 2020
f068615
Updating name of first test as "first_test" in config files
kn-neeraj Jul 16, 2020
c9bb28f
Updated Readme to decouple instructions for installation of dependenc…
kn-neeraj Jul 17, 2020
0a70948
Small typo fix in Github readme
kn-neeraj Jul 17, 2020
27fa7ed
Solving threading issue while running parallel tests and updated comm…
kn-neeraj Jul 17, 2020
a4899f6
Update Github readme content and links to new documentation
kn-neeraj Jul 17, 2020
c570250
Updating readme with minimum Python supported version as Python 3.6
kn-neeraj Jul 17, 2020
5109ccd
Added note about pip coming pre-installed in some Python versions in …
kn-neeraj Jul 17, 2020
8ed2769
Adding app URL placeholder test in config files
kn-neeraj Jul 18, 2020
c85e0c4
Adding placeholders for App URL in Android parallel testing config file
kn-neeraj Jul 18, 2020
e8733a2
Updated developer documentation URL in Readme
kn-neeraj Jul 20, 2020
ee92806
Decoupling python3 and python2 installation commands
kn-neeraj Jul 21, 2020
8a2ea09
Updated print statement
kn-neeraj Aug 5, 2020
3a769f3
Updated print statement
kn-neeraj Aug 5, 2020
f8b7ae6
Updated print statement
kn-neeraj Aug 5, 2020
f3993bd
Updated print statement
kn-neeraj Aug 5, 2020
241d174
Updated print statement
kn-neeraj Aug 5, 2020
50c85bc
Adding new line to search input
kn-neeraj Aug 5, 2020
5e7dfba
Adding new line to search input
kn-neeraj Aug 5, 2020
0e6ba9b
Resolving PR comments
kn-neeraj Aug 5, 2020
9fbb620
Merge branch 'python3-readme-changes' of https://github.com/kn-neeraj…
kn-neeraj Aug 5, 2020
062861b
Added specific versions for dependencies, updated config files
kn-neeraj Aug 5, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*/local.log
*/browserstack.err
*/**.pyc
111 changes: 103 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,108 @@
# python-appium-app-browserstack
App Automate Python Samples
---------------------

This repository contains code for Automated Native App tests. Please feel free to clone the repo and use the example code.
Refer [Getting Started with App Automate](https://www.browserstack.com/app-automate/appium-python) for more details.
This repository demonstrates how to run Appium tests using Python on BrowserStack App Automate.

## Setup

### Requirements

1. Python 3.6+ or Python 2.7+

- If Python is not installed, follow these instructions:
- For Windows, download latest python version from [here](https://www.python.org/downloads/windows/) and run the installer executable
- 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/)

2. Package Manager `pip`

Note : `pip` comes installed with Python 2.7.9+ and python 3.4+

- If `pip` is not installed, follow these instructions:
- Securely download get-pip.py by following this link: [get-pip.py](https://bootstrap.pypa.io/get-pip.py) or use following cURL command to download it:

```sh
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
```

- After dowloading, run the file :

- For Python 3

```sh
python3 get-pip.py
```

- For Python 2

```sh
python2 get-pip.py
```

### Install the dependencies

To install the dependencies for Android tests, run :

- For Python 3

```sh
pip3 install -r android/requirements.txt
```

- For Python 2

```sh
pip2 install -r android/requirements.txt
```

Or,

To install the dependencies for iOS tests, run :

- For Python 3

```sh
pip3 install -r ios/requirements.txt
```

- For Python 2

```sh
pip2 install -r ios/requirements.txt
```


## Getting Started

Getting Started with Appium tests in Python on real BrowserStack devices couldn't be easier!

### **Run first test :**

- Switch to `run-first-test` directory under [Android examples](android/examples/run-first-test) or [iOS examples](ios/examples/run-first-test)

- Follow the steps outlined in the documentation [Getting Started with your first test on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/python)

### **Speed up test execution with parallel testing :**

- Switch to `run-prarallel-tests` directory under [Android examples](android/examples/run-parallel-tests) or [iOS examples](ios/examples/run-parallel-tests)

- Follow the steps outlined in the documentation [Getting Started with Parallel testing on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/python/parallelize-tests)

### **Use Local testing for apps that access resources hosted in development or testing environments :**

- Switch to `run-local-test` directory under [Android examples](android/examples/run-local-test) or [iOS examples](ios/examples/run-local-test)

- Follow the steps outlined in the documentation [Getting Started with Local testing on App Automate](https://www.browserstack.com/docs/app-automate/appium/getting-started/python/local-testing)

**Note**: If you face any issues, refer [Getting Help section](#Getting-Help)

## Integration with other python frameworks

For other Python frameworks samples, refer to following repositories :

For frameworks integration with BrowserStack, refer to their individual repositories -
- [Lettuce](https://github.com/browserstack/lettuce-appium-app-browserstack)
- [Behave](https://github.com/browserstack/behave-appium-app-browserstack)
- [Lettuce](https://github.com/browserstack/lettuce-appium-app-browserstack)

Note: For other test frameworks supported by App-Automate refer our [Developer documentation](https://www.browserstack.com/docs/)

## Getting Help

For python 2 support refer the branch
- [python-2-master](https://github.com/browserstack/python-appium-app-browserstack/tree/python-2-master)
If you are running into any issues or have any queries, please check [Browserstack Support page](https://www.browserstack.com/support/app-automate) or [get in touch with us](https://www.browserstack.com/contact?ref=help).
32 changes: 0 additions & 32 deletions android/BrowserStackAndroid.py

This file was deleted.

55 changes: 0 additions & 55 deletions android/LocalSampleAndroid.py

This file was deleted.

34 changes: 0 additions & 34 deletions android/README.md

This file was deleted.

13 changes: 13 additions & 0 deletions android/examples/run-first-test/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"username":"BROWSERSTACK_USERNAME",
"access_key":"BROWSERSTACK_ACCESS_KEY",

"capabilities": {
"project": "First Python Android Project",
"build": "Python Android",
"name": "first_test",
"browserstack.debug": true,
"app": "bs://<hashed app-id>",
"device": "Google Pixel"
}
}
51 changes: 51 additions & 0 deletions android/examples/run-first-test/first_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import os, json

config_file_path = os.path.join(os.path.dirname(__file__), "config.json")
print("Config file path = %s" % (config_file_path))
kn-neeraj marked this conversation as resolved.
Show resolved Hide resolved
with open(config_file_path) as config_file:
CONFIG = json.load(config_file)

BROWSERSTACK_USERNAME = os.environ['BROWSERSTACK_USERNAME'] if 'BROWSERSTACK_USERNAME' in os.environ else CONFIG['username']
BROWSERSTACK_ACCESS_KEY = os.environ['BROWSERSTACK_ACCESS_KEY'] if 'BROWSERSTACK_ACCESS_KEY' in os.environ else CONFIG['access_key']

def test():
"""
Test for BrowserStack sample Wikipedia Android app.
Note: If you have uploaded your app to BrowserStack update the test here.
"""

desired_capabilities = CONFIG['capabilities']

driver = webdriver.Remote(
desired_capabilities = desired_capabilities,
command_executor = "http://%s:%[email protected]/wd/hub" % (BROWSERSTACK_USERNAME, BROWSERSTACK_ACCESS_KEY)
)

search_element = WebDriverWait(driver, 30).until (
EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "Search Wikipedia"))
)

search_element.click()

search_input = WebDriverWait(driver, 30).until (
EC.element_to_be_clickable((MobileBy.ID, "org.wikipedia.alpha:id/search_src_text"))
)

search_input.send_keys("BrowserStack")
kn-neeraj marked this conversation as resolved.
Show resolved Hide resolved

time.sleep(5)

search_results = driver.find_elements_by_class_name("android.widget.TextView")

assert(len(search_results) > 0)

driver.quit()


if __name__ == "__main__":
test()
kn-neeraj marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 14 additions & 0 deletions android/examples/run-local-test/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"username":"BROWSERSTACK_USERNAME",
"access_key":"BROWSERSTACK_ACCESS_KEY",

"capabilities": {
"project": "First Python Android Project",
"build": "Python Android Local",
"name": "local_test",
"browserstack.debug": true,
"app": "bs://<hashed app-id>",
"device": "Samsung Galaxy S7",
"browserstack.local": true
}
kn-neeraj marked this conversation as resolved.
Show resolved Hide resolved
}
kn-neeraj marked this conversation as resolved.
Show resolved Hide resolved
Loading