robotframework-pageobjectlibrary
robotframework-pageobjectlibrary copied to clipboard
Failed when keyword conflicts in two files
Hi, I follow the guide "https://github.com/boakley/robotframework-pageobjectlibrary/wiki/Tutorial" to learn how to use this library. When keyword doesn't conflict, the case passed. But after adding conflict keyword in two files as following, the case failed, can you help to check where is wrong in my test, thank you very much. In LoginPage.py:
def new_keyword(self):
self.logger.info("In LoginPage")
In SecureAreaPage:
def new_keyword(self):
self.logger.info("In SecureAreaPage")
And change the 'Valid Login' Case as following
[Setup] Go To Page LoginPage
Enter Username tomsmith
Enter password SuperSecretPassword!
new_keyword
Click the login button
The current page should be SecureAreaPage
new_keyword
sleep 5
This time, the case failed, here is the error information
PS D:\demo> robot --outputdir results --pythonpath resources tests
==============================================================================
Tests
==============================================================================
Tests.Login
==============================================================================
Valid Login :: Verify that we can successfully log in to the inte...
trying to go to 'https://the-internet.herokuapp.com/login'
[ ERROR ] Unexpected error: AttributeError: 'tuple' object has no attribute 'split'
Traceback (most recent call last):
File "c:\python27\lib\site-packages\robot\utils\application.py", line 83, in _execute
rc = self.main(arguments, **options)
File "c:\python27\lib\site-packages\robot\run.py", line 445, in main
result = suite.run(settings)
File "c:\python27\lib\site-packages\robot\running\model.py", line 248, in run
self.visit(runner)
File "c:\python27\lib\site-packages\robot\model\testsuite.py", line 161, in visit
visitor.visit_suite(self)
File "c:\python27\lib\site-packages\robot\model\visitor.py", line 86, in visit_suite
suite.suites.visit(self)
File "c:\python27\lib\site-packages\robot\model\itemlist.py", line 76, in visit
item.visit(visitor)
File "c:\python27\lib\site-packages\robot\model\testsuite.py", line 161, in visit
visitor.visit_suite(self)
File "c:\python27\lib\site-packages\robot\model\visitor.py", line 87, in visit_suite
suite.tests.visit(self)
File "c:\python27\lib\site-packages\robot\model\itemlist.py", line 76, in visit
item.visit(visitor)
File "c:\python27\lib\site-packages\robot\model\testcase.py", line 74, in visit
visitor.visit_test(self)
File "c:\python27\lib\site-packages\robot\running\runner.py", line 135, in visit_test
test.template).run_steps(test.keywords.normal)
File "c:\python27\lib\site-packages\robot\running\steprunner.py", line 36, in run_steps
self.run_step(step)
File "c:\python27\lib\site-packages\robot\running\steprunner.py", line 54, in run_step
runner = context.get_runner(name or step.name)
File "c:\python27\lib\site-packages\robot\running\context.py", line 183, in get_runner
return self.namespace.get_runner(name)
File "c:\python27\lib\site-packages\robot\running\namespace.py", line 224, in get_runner
return self._kw_store.get_runner(name)
File "c:\python27\lib\site-packages\robot\running\namespace.py", line 265, in get_runner
runner = self._get_runner(name)
File "c:\python27\lib\site-packages\robot\running\namespace.py", line 288, in _get_runner
runner = self._get_implicit_runner(name)
File "c:\python27\lib\site-packages\robot\running\namespace.py", line 306, in _get_implicit_runner
runner = self._get_runner_from_libraries(name)
File "c:\python27\lib\site-packages\robot\running\namespace.py", line 331, in _get_runner_from_libraries
found = self._get_runner_based_on_search_order(found)
File "c:\python27\lib\site-packages\robot\running\namespace.py", line 341, in _get_runner_based_on_search_order
if eq(libname, runner.libname):
File "c:\python27\lib\site-packages\robot\utils\match.py", line 26, in eq
str1 = normalize(str1, ignore, caseless, spaceless)
File "c:\python27\lib\site-packages\robot\utils\normalizing.py", line 34, in normalize
string = empty.join(string.split())
Valid Login :: Verify that we can successfully log in to the inte... PS D:\demo>
PS D:\demo>
PS D:\demo>
@automationTestStudent - have you tried specifying the namespace for each of the methods/keywords you're trying to use? In other words:
Valid Login
[Setup] Go to page LoginPage
Enter Username tomsmith
Enter password SuperSecretPassword!
LoginPage.new_keyword
Click the login button
The current page should be SecureAreaPage
SecureAreaPage.new_keyword
sleep 5
My advice is to use a different keyword name for each of these page objects. If you need a method that is universal, see Bryan's article on Mixins.
The problem is that you have not provided an implementation for the method _is_current_page
. The default implementation assumes there is a class attribute named PAGE_TITLE
. You haven't defined that variable, and there's a bug in the default implementation of _is_current_page
that throws this error when it can't find the expected page title.
The simple solution is to add a definition for PAGE_TITLE
to your class definition:
class LoginPage(PageObject):
PAGE_TITLE = "The Internet"
...
This is both a bug in the definition of the PageObject
class, but also in my documentation. Thanks for reporting the issue.
@GLMeece it's perfectly fine (and, arguably, very common) to have the same keyword in multiple page objects. While you are correct that using a fully qualified keyword name can work, the page object library was designed so that you shouldn't need to do that.