MarketSquare / robotframework-browser

Robot Framework Browser library powered by Playwright.
Apache License 2.0
533 stars 106 forks source link

Direct Python Usage #45

Closed mkorpela closed 4 years ago

mkorpela commented 4 years ago

Is your feature request related to a problem? Please describe. PageObject and related patterns, issues and comments suggest that direct Python use will be a big part of this libraries success.

Describe the solution you'd like I want a simple way to access and use library from python.

We need editor support for keyword completions.

Describe alternatives you've considered Direct Robot Framework side use will severely limit library usability as most automation work will happen in python code. Although tests are written in Robot Framework.

Additional context Hyvää Juhannusta

mkorpela commented 4 years ago

I also think that pytest should be treated as a first class testing interface. We can support both: unit and acceptance test.

yanne commented 4 years ago

One problem for direct usage that I see is that the module name is "somewhat" generic.

Disregarding that, what does "simple" mean to you? Would e.g.

import Browser

chrome = Browser.open_browser()
chrome.go_to()
chrome.get_text()

be simple enough?

I guess the signatures would be the same as with RF, because e.g. with pytest you can just do the assertions yourself.

This would also be really simple to implement, just rip the dynamic core out, and have on glorious class.

aaltat commented 4 years ago

The methods that are keywords are available in the library public API, with PythonLibCore. Meaning, this should work already now:

import Browser

chrome = Browser.open_browser()
chrome.go_to()
chrome.get_text()

The problem is that IDE, example PyCharm, uses some static analysis and can not automatically complete the keywords. The solution that I have been thinking in the SL side is to build python stub files with Mypy.

mkorpela commented 4 years ago

Stub could work.. You could also be In princible a little bit hacky and not expose assertion engine syntax.

Snooz82 commented 4 years ago

Hi,

I HACKED a little bit. And it is really super HACKY. The resulting __init__.pyi is useful.

We should really put all of our Enums into one module, so that all can be imported ad once...

Please don´t judge me! i just wanted to have some completion and work on the SeleniumCompatibility Layer. i know that this can be optimized a lot!!!

generated __init__.pyi

super ugly script

xylix commented 4 years ago

@Snooz82 Just letting you know, I merged the script in #149 along with some other improvements to raw python usage of the library.

mkorpela commented 4 years ago

This is in my opinion now done.