Skip to content

Commit

Permalink
Add unit test for rename prefixed keywords, WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
HelioGuilherme66 committed Dec 20, 2024
1 parent c9db1eb commit a69aff7
Show file tree
Hide file tree
Showing 15 changed files with 193 additions and 0 deletions.
51 changes: 51 additions & 0 deletions utest/controller/test_rename_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,56 @@ def test_rename_suite_setup_kw(self):
assert suite_setup == ['Suite Setup', 'Run Keywords', SUITESETUPKW, 'AND', 'One Keyword']


class TestRenameResourcePrefixedKeywords(unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.project_ctrl = datafilereader.construct_project(
datafilereader.RESOURCE_PREFIXED_KEYWORDS_PATH)
cls.ts1 = datafilereader.get_ctrl_by_name('Suite01',
cls.project_ctrl.datafiles)
cls.ts2 = datafilereader.get_ctrl_by_name('Sub.Suite01',
cls.project_ctrl.datafiles)
cls.ts3 = datafilereader.get_ctrl_by_name('Sub.Suite01',
cls.project_ctrl.datafiles)
# cls.resu = datafilereader.get_ctrl_by_name(
# datafilereader.SIMPLE_TEST_SUITE_RESOURCE_NAME,
# cls.project_ctrl.datafiles)

@classmethod
def tearDownClass(cls):
cls.project_ctrl.close()

def setUp(self):
self.ctrl = self.ts1
self.suites = self.ctrl.suites

def test_rename_suite_setup_kw(self):
kw_list = dir(self.suites) # [0].get_keyword_names()
# settings = self.suites[0].setting_table
# suite_setup = settings.suite_setup.as_list()
print(f"DEBUG: TestRenameResourcePrefixedKeywords test_rename_suite_setup_kw"
f" source= {self.ctrl.source} type ctrl={type(self.ctrl)} suites={self.suites}\n")
print(f"DEBUG: TestRenameResourcePrefixedKeywords test_rename_suite_setup_kw"
f" kw_list= {kw_list}\n")
assert kw_list is not None
# assert suite_setup is not None
"""
assert kw_list == ['First KW', 'Second KW', 'Test Setup Keyword', 'Test Teardown Keyword',
'Keyword Teardown Keyword', SUITESETUPKW, 'Test Teardown in Setting']
assert suite_setup == ['Suite Setup', 'Run Keywords', SUITESETUPKW, 'AND', 'First KW']
observer = NullObserver()
myobject = RenameKeywordOccurrences("First KW", "One Keyword", observer)
myobject.execute(self.suites[0])
kw_list = self.suites[0].get_keyword_names()
settings = self.suites[0].setting_table
suite_setup = settings.suite_setup.as_list()
# print(f"DEBUG: kw.list are: {kw_list} \n suite_setup={suite_setup}")
assert kw_list == ['One Keyword', 'Second KW', 'Test Setup Keyword', 'Test Teardown Keyword',
'Keyword Teardown Keyword', SUITESETUPKW, 'Test Teardown in Setting']
assert suite_setup == ['Suite Setup', 'Run Keywords', SUITESETUPKW, 'AND', 'One Keyword']
"""


if __name__ == "__main__":
unittest.main()
2 changes: 2 additions & 0 deletions utest/resources/datafilereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def _makepath(*elements):

IMPORTS = _makepath('imports')

RESOURCE_PREFIXED_KEYWORDS_PATH = _makepath('TestCases')

PREAMBLE_NO_LANG = _makepath('language', 'preamble_no_lang.robot')
PREAMBLE_UNKNOWN_LANG = _makepath('language', 'preamble_unknown_lang.robot')
DUMMY_LANG = _makepath('language', 'dummy')
Expand Down
6 changes: 6 additions & 0 deletions utest/resources/robotdata/TestCases/Sub/Lib/MyListener.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class MyListener():
def before_navigate_to(self, url, driver):
print("Before navigate to %s" % url)

def after_navigate_to(self, url, driver):
print("After navigate to %s" % url)
8 changes: 8 additions & 0 deletions utest/resources/robotdata/TestCases/Sub/Lib/SubMyListener.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from selenium.webdriver.support.events import AbstractEventListener

class SubMyListener(AbstractEventListener):
def before_navigate_to(self, url, driver):
print("Before navigate to %s" % url)

def after_navigate_to(self, url, driver):
print("After navigate to %s" % url)
2 changes: 2 additions & 0 deletions utest/resources/robotdata/TestCases/Sub/Lib/mykw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def my_kw():
print('kw from sub folder')
2 changes: 2 additions & 0 deletions utest/resources/robotdata/TestCases/Sub/Lib/res2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def res_kw_2():
print('kw from sub res folder')
17 changes: 17 additions & 0 deletions utest/resources/robotdata/TestCases/Sub/Suite01.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*** Settings ***
Library Collections
Resource ../resources/res01.resource
Library ./Lib/SubMyListener.py
Library ../Sub/Lib/mykw.py

*** Test Cases ***
case01
[Setup] res01.keyword3
keyword2 lalala\nlala\nlala

case02
log ${CURDIR}
log ${EXECDIR}
my_kw
kw1 hehe
after navigate to about:blank None
2 changes: 2 additions & 0 deletions utest/resources/robotdata/TestCases/Sub/resources/res.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def res_kw():
print('kw from res folder')
15 changes: 15 additions & 0 deletions utest/resources/robotdata/TestCases/Sub/resources/res02.resource
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*** Settings ***
Library ./res.py

*** Keywords ***
keyword1
[Arguments] ${a}
log ${a}
Run Keyword keyword3

keyword2
[Arguments] ${a}
log ${a}

keyword3
res_kw
12 changes: 12 additions & 0 deletions utest/resources/robotdata/TestCases/Sub/suite02.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*** Settings ***
Resource ./resources/res02.resource
Library ./Lib/mykw.py
Resource ../../resources/external_res.resource

*** Test Cases ***
case01
[Setup] res02.keyword1 Called from Setup in Sub/Suite02/case01
my_kw
res02.keyword3
external_res.keyword2 Called fromSteps on Sub/Suite02/case01
[Teardown] external_res.keyword3
2 changes: 2 additions & 0 deletions utest/resources/robotdata/TestCases/mykw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def my_kw():
print('kw from root folder')
2 changes: 2 additions & 0 deletions utest/resources/robotdata/TestCases/resources/res.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def res_kw():
print('kw from res folder')
29 changes: 29 additions & 0 deletions utest/resources/robotdata/TestCases/resources/res01.resource
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
*** Settings ***
Library res.py
Library Sub/Lib/res2.py # Another comment

*** Keywords ***
kw1
[Arguments] ${a}
log ${a} # teste
# comment test testst
log ${a}

keyword2
[Arguments] ${a}
log ${a}
Log To Console This is the argument \${a} = ${a} !

keyword3
res kw
res2.res kw 2 # Kw from res2 with a space in calling

kw4
Comment res kw
Comment res kw 2
No Operation

kw5
res.kw 2 # teste teste
res.kw
res2.Res Kw 2
23 changes: 23 additions & 0 deletions utest/resources/robotdata/TestCases/suite01.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
*** Settings ***
Suite Setup external_res.keyword2 Called from Suite Setup on Suite01
Resource ./resources/res01.resource
Resource ./Sub/resources/res02.resource
Library ./mykw.py
Resource ../resources/external_res.resource

*** Test Cases ***
case01
res02.keyword2 aaaa\na\na
[Teardown] res02.keyword1 Called from Teardown on case01

case02
[Setup] external_res.keyword1 Called from Setup on case02
log ${CURDIR} console=True
log ${EXECDIR} console=True
my_kw
res02.keyword1 hehe

case03
res02.keyword3
res01.keyword3
Run Keyword external_res.keyword3
20 changes: 20 additions & 0 deletions utest/resources/robotdata/resources/external_res.resource
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
*** Settings ***
Documentation This resource is to be used as external resource from test suite ../TestCases
Resource ../TestCases/Sub/resources/res02.resource

*** Variables ***
${EXT_VARIABLE} external variable # from external resource

*** Keywords ***
keyword1
[Arguments] ${a}
log ${a}

keyword2
[Arguments] ${a}
log ${a}
Log To Console This is the argument \${a} = ${a} !

keyword3
keyword1 Called from external_resource
res02.keyword1 Called from external_resource # Kw from res2 with a space in calling

0 comments on commit a69aff7

Please sign in to comment.