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

Improve Create Webdriver keyword documentation #529

Closed
aaltat opened this issue Nov 5, 2015 · 22 comments
Closed

Improve Create Webdriver keyword documentation #529

aaltat opened this issue Nov 5, 2015 · 22 comments

Comments

@aaltat
Copy link
Contributor

aaltat commented Nov 5, 2015

From user group, send by: Wagner Wladislaw

| Open URL in Google Chrome | [Arguments] | ${url}
| | [Documentation] | Starts the Google Chrome browser.
| | ${options}= | Evaluate | sys.modules['selenium.webdriver'].ChromeOptions() | sys
| | Call Method | ${options} | add_argument | --lang\=de
| | Create WebDriver | Chrome | chrome_options=${options}
| | Go To | ${url}

I think it's a good addition to the keyword documentation.

@emanlove
Copy link
Member

emanlove commented Nov 5, 2015

I didn't follow the user group discussion closely but there might also be some discussion/words in the conversation that would provide context for the code above as well as more information.

@aaltat
Copy link
Contributor Author

aaltat commented Nov 5, 2015

Good point, here is the original discussion: https://groups.google.com/d/msg/robotframework-users/r3rxgSv1Cs0/rzzc1fmwEQAJ

@Tset-Noitamotua
Copy link

Another example. Same as above but for REMOTE usage of chrome webdriver with selenium server standalone:

https://groups.google.com/forum/#!topic/robotframework-users/gPsiVaMo19A

@janihur
Copy link

janihur commented Nov 28, 2015

I'd like to see also an example (for all supported browsers) how to set Accept-Language HTTP header (see Setting language preferences in a browser).

AFAIK Python/Firefox is:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("intl.accept_languages", "no,en-US,en");
WebDriver driver = new FirefoxDriver(profile);

But this needs to be translated to Robot (for dummies).

@emanlove
Copy link
Member

emanlove commented Dec 2, 2015

We should think about extending some of the introductory paragraphs to give details on using Create WebDriver as well as the parameters for Open Browser.

@aaltat
Copy link
Contributor Author

aaltat commented Dec 2, 2015

Good point, the keyword documentation is coming quite long and putting that to separate chapter is a good idea. Also with the same context, thinking what to do with #532, could be useful.

@Tset-Noitamotua
Copy link

One more goody for all´y´all my robot-friends ;-)

How To: Change the language of Firefox browser

Find below pure Selenium (Python bindings) & Robot Framework syntax to start Firefox Webdriver browser with specified locale / language.

Selenium Python bindings code (which you can try directly in Python interactive shell):

from selenium import webdriver
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("intl.accept_languages", "ru")
browser = webdriver.Firefox(firefox_profile)
browser.get("http://www.youtube.com")

This should serve you youtube with a Russian UI (navigation). Change "ru" to "en" to get youtube with English navigation.

Robot Framework (selenium2library) code:

# keyword definition
*** Keywords ***
| Open URL in Firefox GERMAN |
| | [Arguments] | ${url}
| | [Documentation] | Starts a Firefox browser with specified locale.
| | ${profile}= | Evaluate | sys.modules['selenium.webdriver'].FirefoxProfile() | sys
| | Call Method | ${profile} | set_preference | intl.accept_languages | de
| | Create WebDriver | Firefox | firefox_profile=${profile}
| | Go To | ${url}

# keyword call
*** Test Cases ***
| Open Youtube with German UI
| |  Open URL in Firefox GERMAN | http://www.youtube.com

Pass locale as argument:

*** Keywords ***
| Open URL in Firefox with desired language |
| | [Arguments] | ${url} | ${locale}
| | [Documentation] | Starts a Firefox browser with specified locale.
| | ${profile}= | Evaluate | sys.modules['selenium.webdriver'].FirefoxProfile() | sys
| | Call Method | ${profile} | set_preference | intl.accept_languages | ${locale}
| | Create WebDriver | Firefox | firefox_profile=${profile}
| | Go To | ${url}

*** Test Cases ***
| Open Youtube with Russian UI
| |  Open URL in Firefox with desired language | http://www.youtube.com | ru

Other langues

German: "de"
German/Germany: "de-de"
Spanish: "es"
Spanish/Spain: "es-es"
French: "fr"
French/Belgium: "fr-be"
French/Canada: "fr-ca"
French/France: "fr-fr"
Russian: "ru"
...

For more look up in Firefox´s preferences / content / Languages

Final notes

Note that with above approach youtube.com will still serve you content appropriate for your country regardless of locale settings, e.g. in Germany I will see German content even if I start Firefox with Russian locale "ru" - only the navigation of the site is in Russian. Also if I use "es-es" as locale I get German content and only UI is in Spanish. I guess the served content depends on the settings of the operating system (OS) or even on the internet network access point. So I think to test a scenario of switching content one will have to switch the OS which is starting the browser (if it depends on the OS) or to use a foreign proxy (if it depends on the network).

@ombre42
Copy link
Contributor

ombre42 commented Jan 15, 2016

@Tset-Noitamotua Thank you for sharing. Looking at more examples makes me think the Evaluate | sys.modules['selenium.webdriver'].... hack should be explained as well. It is just a workaround for import limitations in Evaluate, but the why and how of it is probably not apparent to anyone wishing to use Create Webdriver.

@Tset-Noitamotua
Copy link

@ombre42
A good starting point is the keyword documentation of BuildIn (standard library). Especially the section Evaluating Expressions and the Evaluate keyword.
Then some things which are not (or not fully) supported by Selenium2Library 'out of the box' can be added with the help of Selenium Python API.

@shamaho
Copy link

shamaho commented Jul 21, 2016

Hi all, thanks for the info, I still have some questions though:

It seems to me that the solution is not directly applicable under Jython version of the Library (running Selenium2Library under maven plugin) - or to put it in another way: What's the Jython version equivalent of this solution, in particular the line that goes like:
${profile}= Evaluate sys.modules['selenium.webdriver'].FirefoxProfile() sys,selenium.webdriver

Thanks in advance

@evenicoulddoit
Copy link

Hi all. I think this would be useful. I'm unable to use the Chromedriver due to a virtualbox/Ubuntu graphics driver bug, which I can fix in Chrome by disabled hardware acceleration, but I need to find a way of replicating this within RFW. I'll update with how I get on.

@aaltat
Copy link
Contributor Author

aaltat commented Sep 19, 2016

If you need help, could you show the Python code? In this way it could be easier to help you to solve the problem.

@evenicoulddoit
Copy link

Wasn't using Python, but using the Robot syntax. Applying the following allows me to load Chrome with hardware acceleration disabled:

${options}=  Evaluate  sys.modules['selenium.webdriver'].ChromeOptions()  sys
Call Method  ${options}  add_argument  --disable-gpu\=true
Create webdriver  Chrome  chrome_options=${options}

@aaltat
Copy link
Contributor Author

aaltat commented Sep 19, 2016

Perhaps it would be good idea to write documentation to rst file and create a link to README.rst file and second link to keyword documentation. That way the doc would be in the version same control as the keyword documentation and the keyword documentation would not grow too big. The most difficult thing is to decice the name for the file: CREATE_WEBDRIVER_KEYWORD_EXAMPLES.rst or CREATE_WEBDRIVER_USAGE_EXAMPLES.rst

Would you be interested to make a pull request and gather documentation to a single file?

@evenicoulddoit
Copy link

Hah - I'll try and get some time and submit a PR with one of the above files if I get some time in the next couple of days

@pekkaklarck
Copy link
Member

pekkaklarck commented Sep 20, 2016

I wouldn't be too worried about keyword docs growing too big. Having all docs in one place has its benefits.

That said, it might be a good idea to have larger examples, especially when the example involves multiple keywords, outside the keyword docs. In that case I'd at least initially keep all such examples in one reST file. Different examples could be split into separate sections, table of contents added to the top, etc. If this file would then grow too large to maintain, the reST source code could be split and end result combined into a single document. At that point it would probably be a good idea to start using Sphinx and host docs at Read the Docs. In the beginning just having something like docs/examples.rst and rely on GitHub rendering it as HTML ought to be enough.

@Tattoo
Copy link
Member

Tattoo commented Oct 26, 2016

I'm not sure if this is a bug or a documentation issue so please comment and I'll open a new issue if needed.

The same identifiers for browser that work with Open browser do not work with Create webdriver. For example:

Create webdriver chrome

This produces quite frustrating error: TypeError: 'module' object is not callable

This, however works:

Create webdriver Chrome (notice the capitalisation)

I would appreciate the same kind of table that is in the keyword documentation of Open browser

@aaltat
Copy link
Contributor Author

aaltat commented Oct 26, 2016

@Tattoo it's by design and documented in the Create Webdriver keyword. It must match to objects defined in the selenium side.

@Tattoo
Copy link
Member

Tattoo commented Oct 26, 2016

Ah, I see. Sorry I missed that

Could that be similar table as with Open browser? :)

@aaltat
Copy link
Contributor Author

aaltat commented Oct 26, 2016

It is possible, but it would required some work to be done, nothing too complex though. Now the code is quite simple on that side:
https://github.com/robotframework/Selenium2Library/blob/master/src/Selenium2Library/keywords/_browsermanagement.py#L174

And if new browsers emerge or new ways to launch existing browsers, it does not require changes from S2L side.

@aaltat
Copy link
Contributor Author

aaltat commented Oct 27, 2016

All the above does not mean that I am against the chance, but in the other hand I don't have a need to make the change either. If you want to change it, cloud you raise a separate issue about it and even better if there is a PR to support the issue.

@aaltat aaltat added task Generic task not listed in release notes bug priority: low and removed Documentation task Generic task not listed in release notes labels Sep 13, 2017
@aaltat aaltat added the RoboCon label Jan 16, 2018
@aaltat aaltat removed the RoboCon label Jan 30, 2018
@aaltat
Copy link
Contributor Author

aaltat commented May 15, 2019

I now thinking that Create WebDriver should be deprecated and Open Browser should be enhanced instead. This is planned in the 4.0 release. Therefore I don't plan to put effort in Create WebDriver keyword and I am closing this issue.

@aaltat aaltat closed this as completed May 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants