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

Fix tests that were failing due to the use of the deprecated assert_equals statements. #64

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d4ff793
Fix failing tests due to the use of deprecated assert_equals.
tisto May 27, 2016
d7fb850
Add a few files that were missing in .gitignore.
tisto May 27, 2016
1ba1491
Run tests against Python 3.5 and allow those to fail on travis (for n…
tisto Jun 10, 2016
c332b5e
Move tests folder into robotpageobjects in order to allow proper impo…
tisto Jun 10, 2016
6fd503e
Use Python 3 compatible Exception as.
tisto Jun 10, 2016
9015ce1
Install py3 compatible version of selenium2library for py3.
tisto Jun 23, 2016
ffbf374
Fix imports and exceptions for Python 3.
tisto Jun 23, 2016
ab513be
Attempt to fix monkey patch of __old_tef_init for py3.
tisto Jun 23, 2016
2f926b6
Fix str check; urllib2 import and exceptions for Python 3.
tisto Jun 23, 2016
fdaf2c3
Add six to requirements.txt.
tisto Jun 23, 2016
4b59b4c
Fix super call for python2.
tisto Jun 23, 2016
bc6916e
Revert "Fix super call for python2."
tisto Jun 23, 2016
e89f8a2
Revert "Add six to requirements.txt."
tisto Jun 23, 2016
466f7d3
Revert "Fix str check; urllib2 import and exceptions for Python 3."
tisto Jun 23, 2016
e6fbde3
Add six to requirements.txt.
tisto Jun 23, 2016
b222227
Use six.string_types for py2/3 compatibility.
tisto Jun 23, 2016
704271b
Fix urllib import for py3; Fix super call in OptionHandler for py3; F…
tisto Jun 23, 2016
98aea34
Fix a few relative imports.
tisto Jun 23, 2016
cee1423
Fix tests module.
tisto Jun 23, 2016
68868a6
Revert "Fix tests module."
tisto Jun 23, 2016
83f26d7
Revert "Fix a few relative imports."
tisto Jun 23, 2016
e830171
Fix tests init file.
tisto Jun 24, 2016
4355a1c
Fix relative imports in scenarios.po.
tisto Jun 24, 2016
bb448aa
Fix relative imports in test_functional.py and test_unit.py.
tisto Jun 24, 2016
3a267c6
Fix relative imports in test_unit.py, resultspage.py, and homepage.py.
tisto Jun 24, 2016
16f58fa
Revert "Fix relative imports in test_unit.py, resultspage.py, and hom…
tisto Jun 24, 2016
963702c
Add Makefile.
tisto Jun 24, 2016
e36e1de
Fix relative imports in test_unit.py.
tisto Jun 24, 2016
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ RELEASE-VERSION
.idea
*.pyc
*.egg-info
*.egg
*.log
report.html
log.html
output.xml
\#*\#
*~
nosetests.xml
po_log.txt
po_log.txt
libdoc.xml

16 changes: 11 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
env:
global:
env:
global:
secure: aStjr7/mZJDdPqJ210HPRZygxXA36SzXyBraK9x6eqaDR+yqZpGJBIYMlRzqV1Fwlh1BUFbOYNczmLEQs+Sf3uPxyEWhFc5L0qKlvUE98fsf6IJuFJdwfwBG1/vrJTNm0JviBI/6lPlB2/EYtJJBWmYQGsrXXoP5Cc38T+z/a0s=
language: python
python:
- "2.7"
- 2.7
- 3.5
matrix:
allow_failures:
- python: 3.5
install:
# for Python 3 we need robotframework-selenium2library 1.8.x
- if [ $TRAVIS_PYTHON_VERSION == 3.5 ]; then pip install -U https://github.com/HelioGuilherme66/robotframework-selenium2library/archive/v1.8.0b3.tar.gz; fi
- pip install .
script:
- nosetests -vs --with-xunit tests/test_unit.py tests/test_functional.py
- nosetests -vs --with-xunit robotpageobjects/tests/test_unit.py robotpageobjects/tests/test_functional.py
deploy:
provider: pypi
user: hellmanj
password:
password:
secure: D5T3Wo8DGHxxU5+7kE+y6uVVrxoOhLfiCZl9q3BEE9OrbnGmzFngRfP1o37ulk78v7PQGNqtn+95nWOWthJcp4897eB6YhKsa1Q8+HSlNynsf/7WW2cgTEgSWppZNaMoUF+my1NW2baKbmcgwRt3Hsxz9HkOvoFfQAR0ZovUy1U=
on:
tags: true
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SHELL := /bin/bash
CURRENT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

all: test

test:
@echo "Run Tests"
nosetests -vs --with-xunit robotpageobjects/tests/test_unit.py robotpageobjects/tests/test_functional.py
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
decorator
mock==1.0.1
requests==2.1.0
robotframework-selenium2library==1.7.2
robotframework-selenium2library
six
uritemplate==0.6
7 changes: 3 additions & 4 deletions robotpageobjects/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from .base import Override, robot_alias, not_keyword
from .page import Page
from .component import Component

from robotpageobjects.base import Override, robot_alias, not_keyword
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for changing these relative imports?

from robotpageobjects.page import Page
from robotpageobjects.component import Component
4 changes: 2 additions & 2 deletions robotpageobjects/abstractedlogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import robot.api.logger
import robot.output.pyloggingconf as robot_logging_conf

from optionhandler import OptionHandler
from context import Context
from robotpageobjects.optionhandler import OptionHandler
from robotpageobjects.context import Context


class Logger(object):
Expand Down
12 changes: 6 additions & 6 deletions robotpageobjects/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from Selenium2Library import Selenium2Library
from Selenium2Library.keywords.keywordgroup import KeywordGroupMetaClass

from . import abstractedlogger
from . import exceptions
from .context import Context
from .optionhandler import OptionHandler
from robotpageobjects.abstractedlogger import Logger
from robotpageobjects import exceptions
from robotpageobjects.context import Context
from robotpageobjects.optionhandler import OptionHandler


class _Keywords(object):
Expand Down Expand Up @@ -537,7 +537,7 @@ class _BaseActions(_S2LWrapper):
Helper class that defines actions for PageObjectLibrary.
"""

_abstracted_logger = abstractedlogger.Logger()
_abstracted_logger = Logger()

def __init__(self, *args, **kwargs):
"""
Expand Down Expand Up @@ -718,7 +718,7 @@ def _element_find(self, locator, *args, **kwargs):


self.driver.implicitly_wait(our_wait)


if locator in self.selectors:
locator = self.resolve_selector(locator)
Expand Down
2 changes: 1 addition & 1 deletion robotpageobjects/component.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .base import _BaseActions, _SelectorsManager, _ComponentsManager, not_keyword
from robotpageobjects.base import _BaseActions, _SelectorsManager, _ComponentsManager, not_keyword
from Selenium2Library.locators.elementfinder import ElementFinder


Expand Down
6 changes: 3 additions & 3 deletions robotpageobjects/context.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from robot.libraries.BuiltIn import BuiltIn
from robot.running.context import EXECUTION_CONTEXTS
from monkeypatches import do_monkeypatches
from robotpageobjects.monkeypatches import do_monkeypatches

do_monkeypatches()

Expand Down Expand Up @@ -39,11 +39,11 @@ def in_robot():
@classmethod
def set_keywords_exposed(cls):
cls._keywords_exposed = True

@classmethod
def set_cache(cls, cache):
cls._cache = cache

@classmethod
def get_cache(cls):
return cls._cache
Expand Down
46 changes: 23 additions & 23 deletions robotpageobjects/monkeypatches.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def _make_phantomjs(self , remote , desired_capabilities , profile_dir):
try:
browser = self._generic_make_browser(webdriver.PhantomJS,
webdriver.DesiredCapabilities.PHANTOMJS, remote, desired_capabilities)
except WebDriverException, e:
print "Couldn't connect to webdriver. WebDriverException was: " + str(e)
except WebDriverException as e:
print("Couldn't connect to webdriver. WebDriverException was: " + str(e))
browser = None
tries += 1
if browser:
Expand All @@ -29,17 +29,17 @@ def _make_phantomjs(self , remote , desired_capabilities , profile_dir):
Selenium2Library._make_phantomjs = _make_phantomjs

### BEGIN QAR-48165 monkey patch
### This adds consistent support for negative indexes in Robot keywords.
__old_tef_init = TableElementFinder.__init__.__func__
### This adds consistent support for negative indexes in Robot keywords.

__old_tef_init = TableElementFinder.__init__
def __new_tef_init(self, *args, **kwargs):
"""
The _locator_suffixes data attribute is used at the end of built-in
The _locator_suffixes data attribute is used at the end of built-in
locator strings used by Selenium2Library.
Monkey patch: added support for negative indexes (QAR-48165). The

Monkey patch: added support for negative indexes (QAR-48165). The
additional locator suffixes are used by the monkey-patched methods
'find_by_row' and 'find_by_col' defined below.
'find_by_row' and 'find_by_col' defined below.
"""
__old_tef_init(self, *args, **kwargs)
self._locator_suffixes[('css', 'last-row')] = [' tr:nth-last-child(%s)']
Expand All @@ -51,12 +51,12 @@ def __new_tef_init(self, *args, **kwargs):
TableElementFinder.__init__ = __new_tef_init

def find_by_row(self, browser, table_locator, row, content):
"""
"""
Selenium2Library locator method used by _TableElementKeywords.table_row_should_contain
This in turn is used by the built-in Robot keyword 'Table Row Should Contain'.

Monkey patch: added support for negative indexes (QAR-48165).
"""
"""
location_method = "row"
if "-" == row[0]:
row = row[1:]
Expand All @@ -68,32 +68,32 @@ def find_by_row(self, browser, table_locator, row, content):
TableElementFinder.find_by_row = find_by_row

def find_by_col(self, browser, table_locator, col, content):
"""
"""
Selenium2Library locator method used by _TableElementKeywords.table_row_should_contain

Monkey patch: added support for negative indexes (QAR-48165).
"""
"""
location_method = "col"
if "-" == col[0]:
col = col[1:]
location_method = "last-col"
locators = self._parse_table_locator(table_locator, location_method)
locators = [locator % str(col) for locator in locators]
return self._search_in_locators(browser, locators, content)

TableElementFinder.find_by_col = find_by_col

def get_table_cell(self, table_locator, row, column, loglevel='INFO'):
"""Returns the content from a table cell.

Row and column number start from 1. Header and footer rows are
included in the count. A negative row or column number can be used
to get rows counting from the end (end: -1) This means that also
cell content from header or footer rows can be obtained with this
to get rows counting from the end (end: -1) This means that also
cell content from header or footer rows can be obtained with this
keyword. To understand how tables are identified, please take a look at
the `introduction`.
Monkey patch: added support for negative indexes (QAR-48165).

Monkey patch: added support for negative indexes (QAR-48165).
get_table_cell is used by the built-in keyword 'Table Cell Should Contain'.
"""
row = int(row)
Expand All @@ -105,13 +105,13 @@ def get_table_cell(self, table_locator, row, column, loglevel='INFO'):
table = self._table_element_finder.find(self._current_browser(), table_locator)
if table is not None:
rows = table.find_elements_by_xpath("./thead/tr")
if row_index >= len(rows) or row_index < 0:
if row_index >= len(rows) or row_index < 0:
rows.extend(table.find_elements_by_xpath("./tbody/tr"))
if row_index >= len(rows) or row_index < 0:
if row_index >= len(rows) or row_index < 0:
rows.extend(table.find_elements_by_xpath("./tfoot/tr"))
if row_index < len(rows):
columns = rows[row_index].find_elements_by_tag_name('th')
if column_index >= len(columns) or column_index < 0:
if column_index >= len(columns) or column_index < 0:
columns.extend(rows[row_index].find_elements_by_tag_name('td'))
if column_index < len(columns):
return columns[column_index].text
Expand Down
14 changes: 9 additions & 5 deletions robotpageobjects/optionhandler.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import re
import os
import imp
import six

from context import Context
import exceptions
from robotpageobjects.context import Context
from robotpageobjects import exceptions


from robot.libraries.BuiltIn import BuiltIn
Expand All @@ -24,7 +25,10 @@ def __new__(cls, *args, **kwargs):

# Singleton pattern...
if cls._instance is None:
cls._instance = super(OptionHandler, cls).__new__(cls, *args, **kwargs)
if six.PY2:
cls._instance = super(OptionHandler, cls).__new__(cls, *args, **kwargs)
else:
cls._instance = super().__new__(cls)
cls._new_called += 1

return cls._instance
Expand Down Expand Up @@ -61,7 +65,7 @@ def _get_opts_from_var_file(self):
try:
vars_mod = imp.load_source("vars", abs_var_file_path)

except (ImportError, IOError), e:
except (ImportError, IOError) as e:
raise exceptions.VarFileImportErrorError(
"Couldn't import variable file: %s. Ensure it exists and is importable." % var_file_path)

Expand All @@ -85,7 +89,7 @@ def _normalize(self, opts):
Convert an option keyname to lower-cased robot format, or convert
all the keys in a dictionary to robot format.
"""
if isinstance(opts, basestring):
if isinstance(opts, six.string_types):
name = opts.lower()
rmatch = re.search("\$\{(.+)\}", name)
return rmatch.group(1) if rmatch else name
Expand Down
20 changes: 12 additions & 8 deletions robotpageobjects/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@
from __future__ import print_function
import inspect
import re
import urllib2
try:
import urllib.request as urllib2
except ImportError:
import urllib2
import six

import decorator
from Selenium2Library import Selenium2Library
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
import uritemplate

from .base import _ComponentsManagerMeta, not_keyword, robot_alias, _BaseActions, _Keywords, Override, _SelectorsManager, _ComponentsManager
from . import exceptions
from .context import Context
from .sig import get_method_sig
from robotpageobjects.base import _ComponentsManagerMeta, not_keyword, robot_alias, _BaseActions, _Keywords, Override, _SelectorsManager, _ComponentsManager
from robotpageobjects import exceptions
from robotpageobjects.context import Context
from robotpageobjects.sig import get_method_sig


# determine if libdoc is running to avoid generating docs for automatically generated aliases
Expand Down Expand Up @@ -241,7 +245,7 @@ def get_keyword_names(self):
def _attempt_screenshot(self):
try:
self.capture_page_screenshot()
except Exception, e:
except Exception as e:
if e.message.find("No browser is open") != -1:
pass

Expand Down Expand Up @@ -435,7 +439,7 @@ def _resolve_url(self, *args):

first_arg = args[0]
if not self._is_robot:
if isinstance(first_arg, basestring):
if isinstance(first_arg, six.string_types):
# In Python, if the first argument is a string and not a dict, it's a url or path.
arg_type = "url"
else:
Expand Down Expand Up @@ -574,7 +578,7 @@ class MyPageObject(PageObject):

try:
self.open_browser(resolved_url, self.browser, remote_url=remote_url, desired_capabilities=caps)
except (urllib2.HTTPError, WebDriverException, ValueError), e:
except (urllib2.HTTPError, WebDriverException, ValueError) as e:
raise exceptions.SauceConnectionError("Unable to run Sauce job.\n%s\n"
"Sauce variables were:\n"
"sauce_platform: %s\n"
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def write_var_file(self, *args, **kwargs):
for i in kwargs:
line = "%s = '%s'\n" % (i, kwargs[i])
f.write(line)
except Exception, e:
except Exception as e:
raise Exception("Problem creating vars file: %s" % e)
finally:
if f:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from robotpageobjects.tests.scenarios.po.basepageobjects.homepage import BaseHomePage
from robotpageobjects.tests.scenarios.po.basepageobjects.resultspage import BaseResultsPage
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from robotpageobjects.tests.scenarios.po.mydbpageobjects.homepage import MyDBHomePage
from robotpageobjects.tests.scenarios.po.mydbpageobjects.resultspage import MyDBResultsPage
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SearchResultPage(Page):
@robot_alias("__name__should_have_results")
def should_have_results(self, expected):
len_results = len(self.find_elements("xpath=id('results')/li", required=False))
asserts.assert_equals(len_results, int(expected), "Unexpected number of results found on %s, got %s, "
asserts.assert_equal(len_results, int(expected), "Unexpected number of results found on %s, got %s, "
"expected %s" %(
self.name, len_results, expected))

Expand Down
Loading