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

Replaced Pageobjects with more generalized option -M/--modules #55

Merged
merged 1 commit into from
Mar 27, 2016
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
29 changes: 13 additions & 16 deletions rfhub/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self):
try:
self.kwdb.add_library(lib)
except robot.errors.DataError as e:
sys.stderr.write("unable to load library '%s'\n" % lib)
sys.stderr.write("unable to load library '%s': %s\n" %(lib,e))

self._load_keyword_data(self.args.path, self.args.no_installed_keywords)

Expand Down Expand Up @@ -84,8 +84,8 @@ def _parse_args(self):
help="read arguments from the given file")
parser.add_argument("-P", "--pythonpath", action=PythonPathAction,
help="additional locations to search for libraries.")
parser.add_argument("-O", "--pageobjects", action=PageObjectAction,
help="give the name of a module that exports one or more page objects")
parser.add_argument("-M", "--module", action=ModuleAction,
help="give the name of a module that exports one or more classes")
parser.add_argument("-D", "--debug", action="store_true", default=False,
help="turn on debug mode")
parser.add_argument("--no-installed-keywords", action="store_true", default=False,
Expand Down Expand Up @@ -134,35 +134,33 @@ class PythonPathAction(argparse.Action):
def __call__(self, parser, namespace, arg, option_string = None):
sys.path.insert(0, arg)

class PageObjectAction(argparse.Action):
'''Handle the -P / --pageobject option
class ModuleAction(argparse.Action):
'''Handle the -M / --module option

This finds all pages objects in the given module. Since page
objects are libraries, they will be appended to the "library"
This finds all class objects in the given module. Since page
objects are modules of , they will be appended to the "library"
attribute of the namespace and eventually get processed like other
libraries.

Note: page object classes that set the class attribute
Note: classes that set the class attribute
'__show_in_rfhub' to False will not be included.

This works by importing the module given as an argument to the
option, and then looking for all members of the module that
inherit from robotpageobjects.Page.
are classes

For example, if you give the option "pages.MyApp", this will
attempt to import the module "pages.MyApp", and search for classes
that are a subclass of Page. For each class it finds it will
attempt to import the module "pages.MyApp", and search for the classes
that are exported from that module. For each class it finds it will
append "pages.MyApp.<class name>" (eg: pages.MyApp.ExamplePage) to
the list of libraries that will eventually be processed.

'''

def __call__(self, parser, namespace, arg, option_string = None):
from robotpageobjects import Page
try:
module = importlib.import_module(name=arg)
for name, obj in inspect.getmembers(module):
if inspect.isclass(obj) and issubclass(obj, Page):
if inspect.isclass(obj):
# Pay Attention! The attribute we're looking for
# takes advantage of name mangling, meaning that
# the attribute is unique to the class and won't
Expand All @@ -175,5 +173,4 @@ def __call__(self, parser, namespace, arg, option_string = None):
namespace.library.append(libname)

except ImportError as e:
print "unable to import '%s'" % arg
print e
print "unable to import '%s' : %s" % (arg,e)
13 changes: 7 additions & 6 deletions tests/acceptance/doc/search.robot
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@
| | Search for | none shall pass
| | Page should contain | Searching for 'none shall pass' found 1 keywords

| Search summary, multiple results (searching for X found 6 keywords)
| Search summary, multiple results (searching for X found 7 keywords)
| | [Documentation]
| | ... | Objective: visit a bookmarked search page and verify that
| | ... | the right number of search terms was found
| | [Tags] | smoke
| |
| | Go to | ${ROOT}/doc
| | Search for | Fatal
| | Page should contain | Searching for 'fatal' found 6 keywords
| | Page should contain | Searching for 'fatal' found 7 keywords

| Correct number of search results - zero results
| | [Documentation]
Expand Down Expand Up @@ -92,7 +92,7 @@
| | Go to | ${ROOT}/doc
| | Search for | fatal
| | ${count}= | Get matching xpath count | xpath=//table[@id='keyword-table']/tbody/tr
| | Should be equal as integers | ${count} | 6
| | Should be equal as integers | ${count} | 7
| | ... | Expected six rows in the table body, got ${count} instead

| Keyword search URL goes to search page
Expand All @@ -110,15 +110,15 @@
| | ... | Objective: verify the name: prefix works
| | Go to | ${ROOT}/doc
| | Search for | name:screenshot
| | Page should contain | Searching for 'screenshot' found 4 keywords
| | Page should contain | Searching for 'screenshot' found 5 keywords

| Using the in: prefix
| | [Documentation]
| | ... | Objective: verify the in: prefix works
| | Go to | ${ROOT}/doc
| | Search for | screenshot in:Selenium2Library
| | Page should contain | Searching for 'screenshot' found 2 keywords
| | ... | Expected results to include exactly 2 keywords, but it didn't
| | Page should contain | Searching for 'screenshot' found 3 keywords
| | ... | Expected results to include exactly 3 keywords, but it didn't

| Clicking search result link shows keyword
| | [Documentation]
Expand All @@ -132,6 +132,7 @@
| | # N.B. "5" is the expected collection_id of the "Easter" library
| | # Perhaps that's a bad thing to assume, but since this test suite
| | # controls which libraries are loaded, it's a reasonably safe bet.
| | Wait Until Element Is Visible | id=kw-none-shall-pass
| | Location should be | ${ROOT}/doc/keywords/5/None%20Shall%20Pass/

*** Keywords ***
Expand Down
9 changes: 9 additions & 0 deletions tests/acceptance/options.robot
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@
| | ... | --no-installed-keywords
| | ... | do not load some common installed keyword libraries

| Help for option -M/--module
| | [Documentation]
| | ... | Verify that the help message includes help for -M/--module
| |
| | Start the hub with options | --help
| | Output should contain
| | ... | -M MODULE, --module MODULE
| | ... | give the name of a module that exports one or more


*** Keywords ***
| Start the hub with options
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/kwdb.robot
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*** Settings ***
| Documentation | Unit tests for the keyword database library
| Library | Collections
| Library | OperatingSystem
| Resource | ${KEYWORD_DIR}/KWDBKeywords.robot
| Force tags | kwdb
| Suite Setup | Initialize suite variables
Expand Down Expand Up @@ -124,7 +125,7 @@

| Initialize suite variables
| | [Documentation] | Define some global variables used by the tests in this suite
| | ${test dir}= | Evaluate | os.path.dirname("${SUITE SOURCE}") | os
| | ${test dir}= | Evaluate | os.path.dirname(r"${SUITE SOURCE}") | os
| | set suite variable | ${KEYWORD DIR} | ${test dir}/keywords
| | set suite variable | ${DATA_DIR} | ${test dir}/data

Expand Down