Coder Social home page Coder Social logo

qahive / robotframework-puppeteer Goto Github PK

View Code? Open in Web Editor NEW
56.0 12.0 14.0 534 KB

Puppeteer Web testing library for Robot Framework

License: Apache License 2.0

Python 93.12% CSS 0.43% HTML 6.45%
robotframework python webtesting puppeteer pyppeteer playwright

robotframework-puppeteer's Introduction

Functional Test Gitpod ready-to-code

robotframework-puppeteer

Robot Framework Puppeteer Library powered by Pyppeteer. Improve automated web testing with chrome native functionality from Puppeteer by Google and webkit from Playwright.

More detail please visit Robot Framework Puppeteer Homepage

We aim to provide keywords similar to robotframework-seleniumlibrary and add core puppeteer functionality that will improve test experiences. Example:

  • Handle HTTP Request
  • Handle HTTP Response
  • Intercepter Http
  • Intercepter javascript function

Browser Support

Browser Support Library
Chromium Puppeteer & Playwright
WebKit Playwright
Firefox Playwright

Keyword documentation

See keyword documentation for available keywords and more information about the library in general.

Installation

Please ensure you have Python version >= 3.7 installed.

The recommended installation method is using pip_::

pip install --upgrade robotframework-puppeteerlibrary
python -m playwright install
pyppeteer-install

Or manually install by running following command

pip install -r requirements.txt
python setup.py install
python -m playwright install
pyppeteer-install

Usage

*** Settings ***
Library    PuppeteerLibrary
Test Teardown    Close Browser


*** Test Cases ***
Example login form submit
    ${HEADLESS}     Get variable value    ${HEADLESS}    ${False}
    &{options} =    create dictionary   headless=${HEADLESS}
    Open browser    http://127.0.0.1:7272   options=${options}
    Input text    id:username_field    demo
    Input text    id:password_field    mode
    Click Element    id:login_button
    Wait Until Page Contains    Login succeeded
    # Logout and wait for homepage loaded
    Run Async Keywords
    ...    Click Link    partial link:logout    AND
    ...    Wait For Response Url    http://127.0.0.1:7272/

Please run demo application on your local before execute example test scripts.

Starting demo application

Running tests requires the demo application located under demoapp directory to be running. It can be started either by double clicking demoapp/server.py file in a file manager or by executing it from the command line:

python demoapp/server.py

Full example please recheck Examples

Extended Puppeteer Libraries

Library Description
Percy.io Visual testing library for Robot Framework Puppeteer.

Contributor

robotframework-puppeteer mainly contribute by QAHive Co. Ltd.

Interested to contribute Cool!! please looking at the Contribution guidelines

Credit

robotframework-puppeteer's People

Contributors

atthaboon avatar dependabot-preview[bot] avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

robotframework-puppeteer's Issues

RIDE (Robot IDE) fails to import properly PuppeteerLibrary

When trying to run demo project, on load of PuppeteerLibrary library RIDE (https://github.com/robotframework/RIDE) throws this error (click Tools-View RIDE Log). That's why keyword auto-completion does not work anymore, even though tests can be run. I used many libraries with RIDE, and had no problems. So I think this might be robotframework-puppeteer error, even though RIDE might have a bug also.

20210331 07:49:36.900 [INFO]: Found Robot Framework version 4.0 from d:\py3venv\lib\site-packages\robot.

20210331 07:49:36.900 [INFO]: Started RIDE v2.0b1 using python version 3.8.5 with wx version 4.0.7.post2 in win32.

20210331 07:49:38.053 [WARN]: Importing test library "PuppeteerLibrary" failed

Traceback (most recent call last):
Initializing test library 'PuppeteerLibrary' with no arguments failed: ValueError: signal only works in main thread
Traceback (most recent call last):
File "d:\py3venv\lib\site-packages\robotide\lib\robot\running\testlibraries.py", line 167, in get_instance
return libcode(*self.positional_args, **dict(self.named_args))
File "d:\py3venv\lib\site-packages\PuppeteerLibrary_init
.py", line 119, in init
signal.signal(signal.SIGINT, self.terminal_signal_handler)
File "C:\Python38\lib\signal.py", line 47, in signal
handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
File "d:\py3venv\lib\site-packages\robotide\spec\librarymanager.py", line 82, in _fetch_keywords
return get_import_result(path, library_args)
File "d:\py3venv\lib\site-packages\robotide\spec\libraryfetcher.py", line 21, in get_import_result
lib = robotapi.TestLibrary(path, args)
File "d:\py3venv\lib\site-packages\robotide\lib\robot\running\testlibraries.py", line 54, in TestLibrary
lib.create_handlers()
File "d:\py3venv\lib\site-packages\robotide\lib\robot\running\testlibraries.py", line 100, in create_handlers
self._create_handlers(self.get_instance())
File "d:\py3venv\lib\site-packages\robotide\lib\robot\running\testlibraries.py", line 159, in get_instance
self._libinst = self._get_instance(self._libcode)
File "d:\py3venv\lib\site-packages\robotide\lib\robot\running\testlibraries.py", line 169, in _get_instance
self._raise_creating_instance_failed()
File "d:\py3venv\lib\site-packages\robotide\lib\robot\running\testlibraries.py", line 313, in _raise_creating_instance_failed
raise DataError("Initializing test library '%s' with %s failed: %s\n%s"

Add support wait for network idle

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Wait for Alert to Fully Show only Handle Alert

Is your feature request related to a problem? Please describe.
When I tried to do some sample test cases for some of my company legacy site, for some reason when I triggered one element and tried to sleep for few seconds then Handle Alert to Accept, it seems doesn't delay but proceed directly

Describe the solution you'd like
Wish to have a hold ability can let the alert to fully show up then only handle the button action

Describe alternatives you've considered
Or at least to have some delay function or async to wait the alert animation finish then only handle alert action

Additional context
Add any other context or screenshots about the feature request here.

Input, select Keyword should log input value

Is your feature request related to a problem? Please describe.
Due to when tester recheck robot log file sometimes require to recheck the input value that submit to form.

Input text:
Typing text 'GL623893' into text field 'id=UserName'.

Input password:
INFO | Typing password into text field 'id=Password'.

Click element:
INFO | Clicking element 'css=input.button.orange'.

Mouse Over:
Simulating Mouse Over on element 'css=#mainNavi a[href="/en/home-and-living"'.

robot puppeteer process not stop if force stop task on jenkins

To Reproduce
Steps to reproduce the behavior:

  1. Run any puppeteer robot test on jenkins
  2. force stop
  3. robot process still running and will not allow to rerun until

Expected behavior
Robot process should auto terminate if jenkins job finished or force stop

Request for complex file upload support

Is your feature request related to a problem? Please describe.
Currently we faced some issue for custom made multiple file upload interface where the file input is hidden
image
image
The "Upload File" keyword will not working on this condition (if we try to use external layer it will show Error: Node is not an HTMLInputElement; if we targeting on the file input it will waiting the field to visible until timeout)

Describe the solution you'd like
I think we need to have some sort of complex file upload mechanism (maybe add option on "Upload File" keyword)

Describe alternatives you've considered
Or maybe completely different keyword on this

Additional context
Refer to the screenshot attached above

Add keywords for handle scroll browser

Describe the solution you'd like
Provide the following scroll keywords scenario

  • Add new "Scroll to top"
  • Enhance "Scroll Element Into View" support additional margin value +n / -n

Send command to inactive browser, The keyword will freeze and never timeout

Describe the bug
If browser have a new popup window and we try to send command to non focus window.
The script will freeze due to chrome will not allow to send command if browser under inactive mode.
Workaround is you need to put test timeout for prevent.

To Reproduce
Reproduce new window issue
[Teardown] Close All Browser
${HEADLESS} Get variable value ${HEADLESS} ${False}
&{options} = create dictionary headless=${HEADLESS}
Open browser http://127.0.0.1:7272 options=${options}
Run Async Keywords
... Wait for new window open AND
... Click Element id=readdocs
Sleep 2s
Click Element id=readdocs

Workaround and tag [Timeout] and put the maximum execution limit instead.

Expected behavior
Keyword should fail after timeout 30s

AttributeError: 'PuppeteerLibrary' object has no attribute 'get_current_page'

Robot Framework Puppeteer Library: 3.1.0

Open Browser ${URL} browser=ptchrome
${Location} Get Location
${Title} Get Title

When calling keywords Get Title or Get Location I'm getting the following error:

AttributeError: 'PuppeteerLibrary' object has no attribute 'get_current_page'

Traceback (most recent call last):
File "C:\Python37\lib\site-packages\PuppeteerLibrary_init_.py", line 200, in run_keyword
return DynamicCore.run_keyword(self, name, args, kwargs)
File "C:\Python37\lib\site-packages\PuppeteerLibrary\base\robotlibcore.py", line 88, in run_keyword
return self.keywords[name](*args, **kwargs)
File "C:\Python37\lib\site-packages\PuppeteerLibrary\keywords\browsermanagement.py", line 98, in get_location
return self.ctx.get_current_page().url
File "C:\Python37\lib\site-packages\PuppeteerLibrary\base\robotlibcore.py", line 71, in getattr
.format(type(self).name, name))

i can run in roborframework butit import fail and can not find PuppeteerLibrary under ride.

it so strange, i can run in roborframework butit import fail and can not find PuppeteerLibrary under ride.
i use mac os catalina 10.15.5. python 3.7.7 robotframework==3.2.1 robotframework-ride=v2.0b1

20200729 09:35:52.251 [WARN]: Importing test library "PuppeteerLibrary" failed

Traceback (most recent call last):
Importing test library 'PuppeteerLibrary' failed: There is no current event loop in thread 'Thread-1'.
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/robotide/lib/robot/utils/importer.py", line 153, in _import
return import(name, fromlist=fromlist)
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PuppeteerLibrary/init.py", line 8, in
from PuppeteerLibrary.keywords import (
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PuppeteerLibrary/keywords/init.py", line 1, in
from .alert import AlertKeywords
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PuppeteerLibrary/keywords/alert.py", line 1, in
from PuppeteerLibrary.base.librarycomponent import LibraryComponent
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PuppeteerLibrary/base/librarycomponent.py", line 3, in
from PuppeteerLibrary.base.context import ContextAware
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PuppeteerLibrary/base/context.py", line 3, in
class ContextAware(object):
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PuppeteerLibrary/base/context.py", line 5, in ContextAware
loop = asyncio.get_event_loop()
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/events.py", line 644, in get_event_loop
% threading.current_thread().name)
PYTHONPATH:
/usr/local/bin
/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python37.zip
/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7
/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload
/Users/ming.ni/Library/Python/3.7/lib/python/site-packages
/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages
/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/robotide/spec
/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/robotide/lib
/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/robotide/contrib/testrunner/../../lib
/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/robotide/contrib/testrunner/../../lib
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/robotide/spec/librarymanager.py", line 82, in _fetch_keywords
return get_import_result(path, library_args)
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/robotide/spec/libraryfetcher.py", line 21, in get_import_result
lib = robotapi.TestLibrary(path, args)
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/robotide/lib/robot/running/testlibraries.py", line 50, in TestLibrary
return_source=True)
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/robotide/lib/robot/utils/importer.py", line 72, in import_class_or_module
self._raise_import_failed(name, err)
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/robotide/lib/robot/utils/importer.py", line 109, in _raise_import_failed
raise DataError('\n'.join(msg))

Change Playwright as a default test engine

Change from Puppeteer to Playwright. Due to playwright is python official support and able to run in multiple browsers than puppteer.

Describe the solution you'd like
Change default browser chrome to using playwright.
Add browser option puppeteer-chrome for using puppeteer

Webkit new window cause keyword error

When send click element to the button and web app open new page the script will failed with error element still moving but action has been send.

To Reproduce
Demo form submit
${BROWSER} = Get variable value ${BROWSER} webkit
${HEADLESS} = Get variable value ${HEADLESS} ${False}
&{options} = create dictionary headless=${HEADLESS}
Open browser https://www.w3schools.com/html/html_forms.asp browser=${BROWSER} options=${options}
Wait Until Element Is Visible xpath=//a[@Class="w3schools-logo notranslate"]
${test1} Convert To Integer 123
${test2} Convert To Integer 456
Input Text id=fname 123
Input Text id=lname 123
Click Element xpath=(//input[@value="Submit"])[1]

The script will fail when executing Click Element that causes a new page popup.
image

Desktop (please complete the following information

  • OS: window 10
  • Browser webkit

Expose ignoreHTTPSErrors browser configuration (cert errors, self-signed SSL - Connection is not private)

When testing in local development web pages with self-signed certificates we cannot pass through the browser error/warning dialog (Connection is not private).
We need puppeteer launch configuration option ignoreHTTPSErrors set to True to bypass this.
Unfortunately this is not exposed through the library, but currently I have to manually expand the puppeteer_context.py file to achieve this. Please add this to configuration options. Thanks.

Can't run test directly on Gidpod

Due to Gitpod require option --no-sandbox mode.
But if enable this option will fail on window after call Browser Close keyword.

Solution need to allow user pass option during open browser

Importing PuppeteerLibrary in Robot Framework prevents graceful termination

If you have library import Puppeteer added then the test execution does not terminate gracefully after pressing CTRL+C once when running test case via command line.

Python: 3.7.4
Robot Framework: 4.1.2
RobotFramework-PuppeteerLibrary: 3.1.0

This seems to behave similar to bug reported in robotframework/robotframework#3798

For example:

*** Settings ***
Library           PuppeteerLibrary

*** Test Cases ***
TestSomething
    FOR    ${i}    IN RANGE    ${30}
        log    ${i}    console=True
        sleep    1s
    END

Open windows command prompt from test case location and run: "robot --outputdir C:/AutomationLogs --test TestSomething ."

Press CTRL+C once after test execution has started.

Observations:
With PuppeteerLibrary import:

==============================================================================
Basic Testing
==============================================================================
Basic Testing.temp Test.
==============================================================================
TestSomething                                                         0
1
2
[ ERROR ] Execution stopped by user.
TestSomething

Without PuppeteerLibrary import:

==============================================================================
Basic Testing
==============================================================================
Basic Testing.temp Test.
==============================================================================
TestSomething                                                         Second signal will force exit.
TestSomething                                                         | FAIL |
Execution terminated by signal
------------------------------------------------------------------------------
Basic Testing.temp Test.                                              | FAIL |
1 test, 0 passed, 1 failed
==============================================================================
Basic Testing                                                         | FAIL |
1 test, 0 passed, 1 failed
==============================================================================
Output:  C:\AutomationLogs\output.xml
Log:     C:\AutomationLogs\log.html
Report:  C:\AutomationLogs\report.html

Enhance keyword to transform data type

Due to keyword not auto convert data into specific data type
example input text keyword if user input the number not string key word will throw exception.

Fix pyee package version issue between Pyppeteer and Playwright

Describe the bug
During install the puppeteer library from pypi got this library dependency error 'pyee<8.0.0,>=7.0.1'

To Reproduce
Steps to reproduce the behavior:

  1. Install Python 3.7 or above
  2. install robotframework-puppeteerlibrary from pip command
  3. found error pyee<8.0.0,>=7.0.1

Expected behavior
Should use pyee 8.0.0 or above

Wait Until Element Finished Animating have an issue with xpath selector

Describe the bug
Wait Until Element Finished Animating have an issue with xpath selector

To Reproduce
Steps to reproduce the behavior:
Wait Until Element Finished Animating xpath=xxxxxx 4s

Error msg:

D:\Program_Files\Python\Python37\Lib\site-packages\robotframework_PuppeteerLibrary-1.2.5-py3.7.egg\PuppeteerLibrary\custom_elements\SPage.py:44: RuntimeWarning: coroutine 'Page.xpath' was never awaited return await self.xpath(selector_value)[0] RuntimeWarning: Enable tracemalloc to get the object allocation traceback  

Expected behavior
Should not throw any page error

Support Playwright for Chrome browser

New feature. Due to for chrome the library still using Puppeteer library.

Add Playwright chrome adapter and recheck compatibility for chrome browser

Target release: 2020 Q4

Switch window using title page throw exception Page.title was never awaited

Describe the bug
Error msg:
RuntimeWarning: coroutine 'Page.title' was never awaited
if page.title() == title:
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

To Reproduce
Run following code:
Run Async Keywords
... Click Element id=opne_shop AND
... Wait For New Window Open
Switch Window title=My shop

`Handle Alert` Enhancement Suggestion

Is your feature request related to a problem? Please describe.
Currently when we do Handle Alert, we can't get the text content inside the Alert like how SeleniumLibrary (https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Handle%20Alert) and Browser Library (https://marketsquare.github.io/robotframework-browser/Browser.html#Wait%20For%20Alert) handle the alert

Describe the solution you'd like
The Handle Alert should have something to get the text message inside(example: https://github.com/robotframework/SeleniumLibrary/blob/9823418feda556d48829a3137eefb962c44b14ff/src/SeleniumLibrary/keywords/alert.py#L144)

Describe alternatives you've considered

Additional context

Puppeteer randomly throw Future exception was never retrieved

Describe the bug
This error message randomly throws from python if the script finished before the await function done.

Future exception was never retrieved
future: <Future finished exception=NetworkError('Protocol error (Target.sendMessageToTarget): No session with given id')>

This error will not affect any testing step/result.

Need prevent or omit this exception type from python.

Mock api during page on load cause all download resource freeze

Describe the bug
run mock api will require page interception in chrome.
await page.setRequestInterception(True)
This will cause all download resource freeze if page still loading the resource

To Reproduce
Steps to reproduce the behavior:

  1. Goto https://angular.io/
  2. run mock api
  3. check network resource found download pending

Expected behavior
mock should not freeze any download

`Press Keys` keywords doesn't work when selector = None

Describe the bug
Press Keys keyword thrown error with "Selector not valid: None" when set the selector as "None"
It seems conflict with the example provided on documentation:
https://qahive.github.io/robotframework-puppeteer/PuppeteerLibrary.html#Press%20Keys

To Reproduce
Steps to reproduce the behavior:

  1. Just type something like Press Keys None A

Expected behavior
By right as per documentation it should work

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser Playright Chromium

Smartphone (please complete the following information):
Not Applicable

Additional context
Add any other context about the problem here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.