diff --git a/README.md b/README.md index 1b32a07..39a1228 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/google-search-browserstack.py b/google-search-browserstack.py index 6801532..db9abc5 100644 --- a/google-search-browserstack.py +++ b/google-search-browserstack.py @@ -31,7 +31,7 @@ command_executor='https://%s:%s@hub.browserstack.com/wd/hub' % ( USERNAME, BROWSERSTACK_ACCESS_KEY ), - desired_capabilities = capabilities + desired_capabilities=capabilities ) driver.get("http://www.google.com") @@ -42,5 +42,5 @@ elem.send_keys("selenium") elem.submit() -print driver.title +print(driver.title) driver.quit() diff --git a/parallel_tests/README.md b/parallel_tests/README.md index 22ac72b..302bec2 100644 --- a/parallel_tests/README.md +++ b/parallel_tests/README.md @@ -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 +``` diff --git a/parallel_tests/run_parallel_tests.py b/parallel_tests/run_parallel_tests.py index 8492d00..36a0616 100644 --- a/parallel_tests/run_parallel_tests.py +++ b/parallel_tests/run_parallel_tests.py @@ -1,7 +1,11 @@ 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()) @@ -9,7 +13,7 @@ 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): diff --git a/parallel_tests/test.py b/parallel_tests/test.py index 765101a..4d91759 100644 --- a/parallel_tests/test.py +++ b/parallel_tests/test.py @@ -3,7 +3,13 @@ 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] @@ -11,8 +17,8 @@ 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 @@ -21,7 +27,8 @@ command_executor='https://%s:%s@hub.browserstack.com/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") diff --git a/screenshot-sample.py b/screenshot-sample.py index 2cbd1d1..5860214 100644 --- a/screenshot-sample.py +++ b/screenshot-sample.py @@ -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 @@ -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:XQWDewaJsUzqYJRv8zhr@hub.browserstack.com/wd/hub', - desired_capabilities = caps) + command_executor="http://%s:%s@hub.browserstack.com/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()