Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ To test varios sample repositories with ease, it is recommended to setup `BROWS

### For Windows:

- Download the latest python build for windows - http://sourceforge.net/projects/pywin32/files/pywin32/
- Download the latest python build for windows - https://www.python.org/downloads/windows/
- Run the installer exe and follow the instructions to install python.

### For Mac and Linux:

- Run python --version to see what python version is installed and make sure it is 2.5.X and above.
- Run python --version to see what python version is installed and make sure it is 3.X and above.
- Mac OS, Ubuntu and many flavors of linux come with pre-installed python.

## Install Selenium
Expand Down
4 changes: 2 additions & 2 deletions google-search-browserstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
command_executor='https://%s:%[email protected]/wd/hub' % (
USERNAME, BROWSERSTACK_ACCESS_KEY
),
desired_capabilities = capabilities
desired_capabilities=capabilities
)

driver.get("http://www.google.com")
Expand All @@ -42,5 +42,5 @@
elem.send_keys("selenium")
elem.submit()

print driver.title
print(driver.title)
driver.quit()
4 changes: 3 additions & 1 deletion parallel_tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ This project contains 3 files. Each of the files is described below.

To run the tests in parallel execute the following command:

python run_parallel_tests.py test.py browsers.json
```sh
python3 run_parallel_tests.py test.py browsers.json
```
10 changes: 7 additions & 3 deletions parallel_tests/run_parallel_tests.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import json, sys, subprocess

file_name = sys.argv[1]
json_name = sys.argv[2]
try:
file_name = sys.argv[1]
json_name = sys.argv[2]
except IndexError:
print("Please provide test script and browserconfig as first and second argument, respectively from command line")
sys.exit(1)

with open(json_name, "r") as f:
obj = json.loads(f.read())

num_of_tests = len(obj)
process = []
for counter in range(num_of_tests):
cmd = "python "+str(file_name)+ " " +str(json_name)+ " " +str(counter)
cmd = "python3 %s %s %s" % (file_name, json_name, counter)
process.append(subprocess.Popen(cmd, shell=True))

for counter in range(num_of_tests):
Expand Down
15 changes: 11 additions & 4 deletions parallel_tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
import sys
import json

json_name = sys.argv[1]
try:
json_name = sys.argv[1]
counter_val = sys.argv[2]
except IndexError:
print('Json name and counter val must be passed as first and second argument, respectively, from the comamnd line')
sys.exit(1)

USERNAME = os.environ.get('BROWSERSTACK_USERNAME') or sys.argv[2]
BROWSERSTACK_ACCESS_KEY = os.environ.get(
'BROWSERSTACK_ACCESS_KEY') or sys.argv[3]

with open(json_name, "r") as f:
obj = json.loads(f.read())

caps = obj[int(sys.argv[2])]
print "Test "+sys.argv[2]+" started"
caps = obj[int(counter_val)]
print("Test %s started" % (counter_val))

#------------------------------------------------------#
# THE TEST TO BE RUN PARALLELY GOES HERE
Expand All @@ -21,7 +27,8 @@
command_executor='https://%s:%[email protected]/wd/hub' % (
USERNAME, BROWSERSTACK_ACCESS_KEY
),
desired_capabilities=caps)
desired_capabilities=caps
)

driver.get("http://www.google.com")
inputElement = driver.find_element_by_name("q")
Expand Down
16 changes: 9 additions & 7 deletions screenshot-sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
try:
USERNAME = sys.argv[1]
BROWSERSTACK_ACCESS_KEY = sys.argv[2]
FILENAME = sys.argv[3]
except IndexError:
print("Pleaes provide the username, browserstack access key and filename with which screenshot should be saved as command line arguments.")
sys.exit(1)

# Define take_screenshot
def take_screenshot(webdriver, file_name = "sample.png"):
def take_screenshot(webdriver, file_name="sample.png"):
"""
@param webdriver: WebDriver handler.
@type webdriver: WebDriver
Expand All @@ -37,21 +38,22 @@ def take_screenshot(webdriver, file_name = "sample.png"):
"""
if isinstance(webdriver, WebDriver):
base64_data = webdriver.get_screenshot_as_base64()
screenshot_data = base64.decodestring(base64_data)
screenshot_file = open(file_name, "w")
screenshot_data = base64.b64decode(base64_data)
screenshot_file = open(file_name, "wb")
screenshot_file.write(screenshot_data)
screenshot_file.close()
else:
webdriver.save_screenshot(filename)

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

driver.get("http://www.google.com")
inputElement = driver.find_element_by_name("q")
inputElement.send_keys("browserstack")
inputElement.submit()
print driver.title
take_screenshot(driver, './sample.png')
print(driver.title)
take_screenshot(driver, FILENAME)
driver.quit()