danhumphrey / page-modeller

⚙️ Browser DevTools extension for modelling web pages for automation.
MIT License
87 stars 25 forks source link

Robot Framework - Locator variables naming convention enhancement #12

Closed rapidroamer closed 5 years ago

rapidroamer commented 5 years ago

Current code generator sample output:

Variables ${userName} id=login

Keywords Set UserName [Arguments] ${userNameValue} [Documentation] Set UserName INPUT element value Input Text ${userName} ${userNameValue}

Requesting enhancement in generator:

Variables ${userNameLocator} id=login

Set UserName [Arguments] ${userNameValue} [Documentation] Set UserName INPUT element value Input Text ${userNameLocator} ${userNameValue}

Why is the enhancement requested ?

Let us take an example of below robot test suite which uses the above LoginPage.robot: Settings Resources LoginPage.robot Variables ${user_name} user01
Test Cases Web Test Set UserName ${user_name}

Test Outcome Expected: Robot framework to find element by locater id=login and send keys 'user01' Test Outcome Actual: Robot framework is trying to find element by locater user01 instead of id=login and fails in the process.

Possible reason for this behavior Robot framework takes our test variable ${user_name} and considers it as a named argument and overrides ${userName} in the Set UserName keyword definition. But the interesting thing is Set UserName keyword is supposed to accept only one argument ${userNameValue}. This is an issue in robot framework itself. I will raise an issue with robot framework.

Just checking if we can add word Locator to all the Locator variable names generated through the Page modeler , that would can add some context to the variable and also muffle this error in robot framework.

danhumphrey commented 5 years ago

Thanks for raising this issue, I have pushed a fix for this into the following branch:

https://githubcom/danhumphrey/page-modeller/tree/robot-locator-naming

I'm not actively using Robot Framework so would like some help testing this fix before I merge it into master and release a new version.... can you please try it out for me?

You will need to clone the repo and pull the 'robot-locator-naming' branch, then load the extension from your file system :

Navigate to the chrome extensions management page at chrome://extensions and ensure developer mode is on. Click the Load Unpacked button and select the extension directory.

rapidroamer commented 5 years ago

Hi,

Sure. Will do.

On Thu, 2 May 2019 at 11:53 am Dan Humphrey notifications@github.com wrote:

Thanks for raising this issue, I have pushed a fix for this into the following branch:

https://githubcom/danhumphrey/page-modeller/tree/robot-locator-naming

I'm not actively using Robot Framework so would like some help testing this fix before I merge it into master and release a new version.... can you please try it out for me?

You will need to clone the repo and pull the 'robot-locator-naming' branch, then load the extension from your file system :

Navigate to the chrome extensions management page at chrome://extensions and ensure developer mode is on. Click the Load Unpacked button and select the extension directory.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/danhumphrey/page-modeller/issues/12#issuecomment-488532452, or mute the thread https://github.com/notifications/unsubscribe-auth/AFIF5IED4XVX4CPIVGOTCKDPTJCTPANCNFSM4HJAOFBQ .

rapidroamer commented 5 years ago

Hi Dan, Apologies for the delay. I was facing some issue loading the unpacked extension from the src dir. The manifest (Details : http://snippi.com/s/8jrbs92)

I am testing the beta version now (didn't have to worry loading unpacked - as it installs straight from web store) : The change looks nice, just wondering how we should handle spaces if the user gives spaces in the locator name(please check line 3) below:

${emailLocator}                 css=div[class*='login-box'] > input:nth-of-type(1)
${passwordLocator}              css=div[class*='login-box'] > input:nth-of-type(2)
${forgot Your PasswordLocator}  link=Forgot your password?
${loginLocator}                 css=div[class*='login-box'] > button
danhumphrey commented 5 years ago

I'm not sure what issue you're describing and whether it is related to the fix or something separate?

As far as I can tell, Robot framework allows spaces in variables - see here: https://github.com/robotframework/robotframework/blob/master/doc/userguide/src/CreatingTestData/Variables.rst

If not, or you are having an issue can you please clarify - here if it's related to this issue and I'll reopen this, or in a separate issue if it's unrelated.

Please bear in mind that I do not use Robot Framework so you'll have to explain the problem with the current behaviour and the expected behaviour and/or proposed solution.

Thanks, Dan

rapidroamer commented 5 years ago

Hi Dan,

Thanks for looking into this. Current solution is syntactically correct. No issues with that.

I am suggesting that, a) If the user has named the locator in a single word, then we can add 'Locator' to that (current behaviour) b) If the user has named the locator using multiple words, then can add '\Locator' to that (additional behaviour to the current behaviour)

Current: ${passwordLocator} css=div[class='login-box'] > input:nth-of-type(2) ${forgot Your PasswordLocator} link=Forgot your password? Nice to have: ${passwordLocator} css=div[class='login-box'] > input:nth-of-type(2) ${forgot Your Password Locator} link=Forgot your password?

danhumphrey commented 5 years ago

Hi Vijay,

I'm not sure what the rules are for Robot framework, but it's not common (at least in the other supported languages and frameworks) to allow spaces in variable names, so I will add validation to disallow this - I will raise this in a separate issue, so if you are categorically against this as it impacts your use of Robot Framework, please comment in that issue.

Thanks again!!