Skip to content

Commit

Permalink
Merge pull request #113 from seleniumbase/python-3-compatibility
Browse files Browse the repository at this point in the history
Python 3 Compatibility
  • Loading branch information
mdmintz authored Jul 19, 2017
2 parents 9c5ecaf + 3bb8089 commit 6ef3c87
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 40 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

<b>All-in-One Automated Testing Software</b>

SeleniumBase is everything you need to automate and test any website.
SeleniumBase is everything you need to automate and/or test any website.

[![pypi](https://img.shields.io/pypi/v/seleniumbase.svg)](https://pypi.python.org/pypi/seleniumbase) [![Build Status](https://travis-ci.org/seleniumbase/SeleniumBase.svg?branch=master)](https://travis-ci.org/seleniumbase/SeleniumBase) [![GitHub stars](https://img.shields.io/github/stars/seleniumbase/seleniumbase.svg "GitHub stars")](https://github.com/seleniumbase/SeleniumBase/stargazers) [![Python version](https://img.shields.io/badge/python-2.7-22AADD.svg "Python version")](https://docs.python.org/2/) [![MIT License](http://img.shields.io/badge/license-MIT-22BBCC.svg "MIT License")](https://github.com/seleniumbase/SeleniumBase/blob/master/LICENSE) [![Join the chat at https://gitter.im/seleniumbase/SeleniumBase](https://badges.gitter.im/seleniumbase/SeleniumBase.svg)](https://gitter.im/seleniumbase/SeleniumBase?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![pypi](https://img.shields.io/pypi/v/seleniumbase.svg)](https://pypi.python.org/pypi/seleniumbase) [![Build Status](https://travis-ci.org/seleniumbase/SeleniumBase.svg?branch=master)](https://travis-ci.org/seleniumbase/SeleniumBase) [![GitHub stars](https://img.shields.io/github/stars/seleniumbase/seleniumbase.svg "GitHub stars")](https://github.com/seleniumbase/SeleniumBase/stargazers) [![Python version](https://img.shields.io/badge/python-2.7_or_3.*-22AADD.svg "Python version")](https://docs.python.org/2/) [![MIT License](http://img.shields.io/badge/license-MIT-22BBCC.svg "MIT License")](https://github.com/seleniumbase/SeleniumBase/blob/master/LICENSE) [![Join the chat at https://gitter.im/seleniumbase/SeleniumBase](https://badges.gitter.im/seleniumbase/SeleniumBase.svg)](https://gitter.im/seleniumbase/SeleniumBase?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

### ![http://seleniumbase.com](https://cdn2.hubspot.net/hubfs/100006/images/super_logo_tiny.png "SeleniumBase") Get Started with SeleniumBase

Expand Down Expand Up @@ -80,7 +80,7 @@ SeleniumBase includes an automated/manual hybrid solution called **[MasterQA](ht
*(**Docker users**: See the [Docker ReadMe](https://github.com/seleniumbase/SeleniumBase/blob/master/integrations/docker/ReadMe.md) to setup your Docker machine.)*


#### **Step 0a:** Setup your [![Python version](https://img.shields.io/badge/python-2.7-22AADD.svg "Python version")](https://docs.python.org/2/) Python/pip environment:
#### **Step 0a:** Setup your [![Python version](https://img.shields.io/badge/python-2.7_or_3.*-22AADD.svg "Python version")](https://docs.python.org/2/) Python/pip environment:

* To install ``python``, ``pip``, ``git``, and either ``virtualenv`` or ``virtualenvwrapper``, **[follow these instructions](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/requirements_installation.md)**.

Expand Down Expand Up @@ -149,6 +149,8 @@ pip install -r requirements.txt --upgrade
python setup.py install
```

(NOTE: If you're using Python 3.* instead of Python 2.7, use ``pip3`` in place of ``pip`` and ``python3`` in place of ``python`` in the above commands.)


<a id="seleniumbase_basic_usage"></a>
### ![http://seleniumbase.com](https://cdn2.hubspot.net/hubfs/100006/images/super_logo_tiny.png "SeleniumBase") **Step 4:** Run the Example Script
Expand Down
8 changes: 4 additions & 4 deletions examples/masterqa_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ class MasterQATests(MasterQA):

def test_xkcd(self):
self.open("http://xkcd.com/1512/")
for i in xrange(4):
for i in range(4):
self.click('a[rel="next"]')
for i in xrange(3):
for i in range(3):
self.click('a[rel="prev"]')
self.verify()
self.open("http://xkcd.com/1520/")
for i in xrange(2):
for i in range(2):
self.click('a[rel="next"]')
self.verify("Can you find the moon?")
self.click('a[rel="next"]')
Expand All @@ -20,6 +20,6 @@ def test_xkcd(self):
self.update_text("input#s", "Robots!\n")
self.verify("Does it say 'Hooray robots' on the page?")
self.open("http://xkcd.com/213/")
for i in xrange(5):
for i in range(5):
self.click('a[rel="prev"]')
self.verify("Does the page say 'Abnormal Expressions'?")
2 changes: 1 addition & 1 deletion examples/my_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MyTestSuite(BaseCase):
def test_1(self):
self.open("http://xkcd.com/1663/")
self.find_text("Garden", "div#ctitle", timeout=3)
for p in xrange(4):
for p in range(4):
self.click('a[rel="next"]')
self.find_text("Algorithms", "div#ctitle", timeout=3)

Expand Down
2 changes: 1 addition & 1 deletion examples/rate_limiting_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ def print_item(self, item):

def test_rate_limited_printing(self):
print("\nRunning rate-limited print test:")
for item in xrange(1, 11):
for item in range(1, 11):
self.print_item(item)
10 changes: 5 additions & 5 deletions examples/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[nosetests]

; This is the config file for default values used during nosetest runs

nocapture=1 ; Displays print statements from output. Undo this by using: --nologcapture
logging-level=INFO ; INFO keeps the logs much cleaner than using DEBUG
# This is the config file for default values used during nosetest runs
# nocapture=1 displays print statements from output. Undo this by using: --nologcapture
# logging-level=INFO keeps the logs much cleaner than using DEBUG
nocapture=1
logging-level=INFO
8 changes: 4 additions & 4 deletions help_docs/requirements_installation.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
## Installation instructions for Python, pip, brew, git, virtualenv, and virtualenvwrapper


### [Python 2.7](https://www.python.org/downloads/)
### [Python 2.7 or 3.*](https://www.python.org/downloads/)

If you're a MAC user, that should already come preinstalled on your machine. Although Python 3 exists, you'll want Python 2 instead.
If you're a MAC user, Python should already come preinstalled on your machine. You can use both Python 2.7 or Python 3 with SeleniumBase. If you're on a MAC and have [Homebrew](https://brew.sh/) installed (but not Python 3) you can use: ``brew install python3`` if you wish to use Python 3 instead of Python 2.7. Or you can just get everything from [https://www.python.org/downloads/](https://www.python.org/downloads/).

If you're a WINDOWS user, [download Python 2.7 from here](https://www.python.org/downloads/release/python-2713/).
If you're a WINDOWS user, [download Python 2.7 from here](https://www.python.org/downloads/release/python-2713/) OR [download Python 3.6.2 from here](https://www.python.org/downloads/release/python-362/).


### [Pip](https://en.wikipedia.org/wiki/Pip_%28package_manager%29)
Expand Down Expand Up @@ -37,7 +37,7 @@ When done, make sure pip is on your path. ($PATH on Mac/Linux. System Environmen
Homebrew allows you to install things more easily, such as Git, Chromedriver, and PhantomJS.

```bash
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
```

Expand Down
3 changes: 2 additions & 1 deletion seleniumbase/core/mysql.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
Wrapper for MySQL functions to make life easier
Due to compatibility issues, might only work for Python 2.7 right now
"""

import time
import mysql_conf as conf


class DatabaseManager():
Expand All @@ -16,6 +16,7 @@ def __init__(self, database_env='test', conf_creds=None):
"""
Gets database information from mysql_conf.py and creates a connection.
"""
import mysql_conf as conf # This had problems when using Python 3
import MySQLdb
db_server, db_user, db_pass, db_schema = \
conf.APP_CREDS[conf.Apps.TESTCASE_REPOSITORY][database_env]
Expand Down
10 changes: 6 additions & 4 deletions seleniumbase/core/selenium_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import socket
import urllib
import sys
import time

SELENIUM_JAR = ("http://selenium-release.storage.googleapis.com"
Expand Down Expand Up @@ -32,9 +33,9 @@ def download_selenium():
local_file.close()
remote_file.close()
print('Download Complete!\n')
except Exception, details:
except Exception:
raise Exception("Error while downloading Selenium Server. Details: %s"
% details)
% sys.exc_info()[1])


def is_running_locally(host, port):
Expand Down Expand Up @@ -78,8 +79,9 @@ def stop_selenium_server(selenium_server_process):
try:
selenium_server_process.terminate()
return selenium_server_process.poll() == 143
except Exception, details:
raise Exception("Cannot kill selenium process, details: " + details)
except Exception:
raise Exception(
"Cannot kill selenium process. Details: " + sys.exc_info()[1])


class StartSeleniumException(Exception):
Expand Down
6 changes: 3 additions & 3 deletions seleniumbase/fixtures/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def activate_jquery(self):
'''script.src = "http://code.jquery.com/jquery-3.1.0.min.js"; '''
'''document.getElementsByTagName("head")[0]'''
'''.appendChild(script);''')
for x in xrange(30):
for x in range(30):
# jQuery needs a small amount of time to activate. (At most 3s)
try:
self.execute_script("jQuery('html')")
Expand Down Expand Up @@ -557,7 +557,7 @@ def highlight(self, selector, by=By.CSS_SELECTOR,
if self.highlights:
loops = self.highlights
loops = int(loops)
for n in xrange(loops):
for n in range(loops):
script = """jQuery('%s').css('box-shadow',
'0px 0px 6px 6px rgba(255, 0, 0, 1)');""" % selector
self.execute_script(script)
Expand Down Expand Up @@ -1273,7 +1273,7 @@ def _slow_scroll_to_element(self, element):
total_steps = int(abs(distance) / 50.0) + 2.0
step_value = float(distance) / total_steps
new_position = scroll_position
for y in xrange(int(total_steps)):
for y in range(int(total_steps)):
time.sleep(0.0114)
new_position += step_value
scroll_script = "window.scrollTo(0, %s);" % new_position
Expand Down
4 changes: 4 additions & 0 deletions seleniumbase/fixtures/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class Files:
ARCHIVED_DOWNLOADS_FOLDER = "archived_files"


class ValidBrowsers:
valid_browsers = ["firefox", "ie", "edge", "safari", "chrome", "phantomjs"]


class Browser:
FIREFOX = "firefox"
INTERNET_EXPLORER = "ie"
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/fixtures/page_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def jq_format(code):
code = code.replace('\\', '\\\\').replace('\t', '\\t').replace('\n', '\\n')
code = code.replace('\"', '\\\"').replace('\'', '\\\'')
code = code.replace('\v', '\\v').replace('\a', '\\a').replace('\f', '\\f')
code = code.replace('\b', '\\b').replace('\u', '\\u').replace('\r', '\\r')
code = code.replace('\b', '\\b').replace(r'\u', '\\u').replace('\r', '\\r')
return code


Expand Down
13 changes: 7 additions & 6 deletions seleniumbase/masterqa/master_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,19 @@ def add_results_page(self, html):
def process_manual_check_results(self, auto_close_results_page=False):
perfection = True
failures_count = self.manual_check_count - self.manual_check_successes
print "\n\n*** Test Result: ***"
print("\n\n*** Test Result: ***")
if self.manual_check_successes == self.manual_check_count:
pass
else:
print "WARNING!!! There were page issues detected!"
print("WARNING!!! There were page issues detected!")
perfection = False

if self.incomplete_runs > 0:
print "WARNING!!! Not all tests finished running!"
print("WARNING!!! Not all tests finished running!")
perfection = False

if perfection:
print "SUCCESS!!! Everything checks out OKAY!"
print("SUCCESS!!! Everything checks out OKAY!")
else:
pass
self.add_bad_page_log_file() # Includes successful results
Expand Down Expand Up @@ -284,7 +284,8 @@ def process_manual_check_results(self, auto_close_results_page=False):
results_file = self.add_results_page(report_html)
archived_results_file = log_path + '/' + RESULTS_PAGE
shutil.copyfile(results_file, archived_results_file)
print "\n*** The results html page is located at: ***\n" + results_file
print(
"\n*** The results html page is located at: ***\n" + results_file)
self.open("file://%s" % archived_results_file)
if auto_close_results_page:
# Long enough to notice the results before closing the page
Expand All @@ -294,7 +295,7 @@ def process_manual_check_results(self, auto_close_results_page=False):
time.sleep(wait_time_before_verify)
else:
# The user can decide when to close the results page
print "\n*** Close the html report window to continue ***"
print("\n*** Close the html report window to continue ***")
while len(self.driver.window_handles):
time.sleep(0.1)

Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/plugins/selenium_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def options(self, parser, env):
parser.add_option(
'--browser', action='store',
dest='browser',
choices=constants.Browser.VERSION.keys(),
choices=constants.ValidBrowsers.valid_browsers,
default=constants.Browser.GOOGLE_CHROME,
help="""Specifies the web browser to use. Default: Chrome.
If you want to use Firefox, explicitly indicate that.
Expand Down
2 changes: 1 addition & 1 deletion server_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='seleniumbase',
version='1.3.27',
version='1.4.0',
description='Test Automation Framework - http://seleniumbase.com',
long_description='Automation Framework for Simple & Reliable Web Testing',
platforms='Mac * Windows * Linux * Docker',
Expand Down
10 changes: 6 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[nosetests]
# This is the config file for default values used during nosetest runs
nocapture=1 ; Displays print statements from output. Undo this by using: --nologcapture
logging-level=INFO ; INFO keeps the logs much cleaner than using DEBUG
# nocapture=1 displays print statements from output. Undo this by using: --nologcapture
# logging-level=INFO keeps the logs much cleaner than using DEBUG
nocapture=1
logging-level=INFO

[bdist_wheel]
# SeleniumBase is for Python 2.7 (right now)
universal=0
# SeleniumBase works for both Python 2.7 and Python 3
universal=1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='seleniumbase',
version='1.3.27',
version='1.4.0',
description='Test Automation Framework - http://seleniumbase.com',
long_description='Automation Framework for Simple & Reliable Web Testing',
platforms='Mac * Windows * Linux * Docker',
Expand Down

0 comments on commit 6ef3c87

Please sign in to comment.