boakley / robotframework-pageobjectlibrary

Lightweight keyword library for implementing the PageObject pattern in Robot Framework
Apache License 2.0
77 stars 57 forks source link

How to do when lots of page objects are in different directories? #8

Open CTHakkas opened 7 years ago

CTHakkas commented 7 years ago

Hi, My product is very complex, it has more than 100 pages, so I don't want to put all the page objects files in the same level's directory. I try to organize the page objects by function as below. The folder structure: demo |-- resources | |-- function1_folder | | |-----func1_subfolder1 | | | |------page1 | | | |------page2 | | |-----func1_subfolder2 | | | |------page3 | | | |------page4 | | |-----page5 | |-- function2_folder | | |-----page6 | | | ----page7 |-- results |-- tests |-- test1.robot |-- test2.robot

I can execute my test cases when all the pages are in the same directory, but when I organize the pages as above, "The current page should be" keyword can't find the module name "page1" , "page2" and so on. Can you tell me how to use this library to test the pages as show above, thank you very much.

boakley commented 7 years ago

Currently, the only solution is to make sure that func1_subfolder`, func1_subfolder1, etc are all in your PYTHONPATH. The page object library uses the core robot mechanism for finding libraries, and it only searches in PYTHONPATH.

One simple solution might be to create a keyword that runs in each suite's setup that adds ${CURDIR} to PYTHONPATH

On Mon, Jul 17, 2017 at 10:51 PM, bajiacun notifications@github.com wrote:

Hi, My product is very complex, it has more than 100 pages, so I don't want to put all the page objects files in the same level's directory. I try to organize the page objects by function as below. The folder structure: demo |-- resources | |-- function1_folder | | |-----func1_subfolder1 | | | |------page1 | | | |------page2 | | |-----func1_subfolder2 | | | |------page3 | | | |------page4 | | |-----page5 | |-- function2_folder | | |-----page6 | | | ----page7 |-- results |-- tests |-- test1.robot |-- test2.robot

I can execute my test cases when all the pages are in the same directory, but when I organize the pages as above, "The current page should be" keyword can't find the module name "page1" , "page2" and so on. Can you tell me how to use this library to test the pages as show above, thank you very much.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/boakley/robotframework-pageobjectlibrary/issues/8, or mute the thread https://github.com/notifications/unsubscribe-auth/ABEmYg4n_Ni1xn2dCgoQfaloRSfKgx4cks5sPCumgaJpZM4Oaz8U .

CTHakkas commented 7 years ago

@boakley , thank you very much for your answer. as you said "add ${CURDIR} to PYTHONPATH", can you give me an example, sorry, I am new for robot framework, in my opinion, ${CURDIR} is the directory of the testsuite, but the pages are not in this directory, so how to get the pages directory and how to add it to the PYTHONPATH, thank you very much.

nashu2k commented 4 years ago

@CTHakkas - if you check this project's robotframework-pageobjectlibrary/demo/tests/demo.robot you can see there

*** Settings ***
# this is the only place where we have to hard-code a path;
# when config.py is loaded it will alter the path to include
# the resources folder.
Variables   ../resources/config.py

Library     PageObjectLibrary
Library     SeleniumLibrary
Library     Process

All you need to change is in config.py the path to your func1_subfolder2 and you should be able to add your own Library into robot