Robot Framework as a Python Library

Introduction

Quite a typical situation is when existing robot libraries are added to their own Python libraries

But do not forget that Robot Framework is also a Python library and its keywords can be called from Python code.

In this article you can study examples of such calls

Screenshot

Let's look at how to make robotic screenshots using an example similar to unstable_url from the article about custom Python libraries

It is clear that with the help of Python you can make screenshots in different ways, but we are interested in the screenshot that will be integrated into test results.

The Screenshot library requires the installation of an additional library. In Windows this is usually Pillow.

Supported tools and modules for taking screenshots How screenshots are taken depends on the operating system. On OSX, screenshots are taken using the built-in screen capture utility. On other operating systems, you will need to install one of the following Python tools or modules. You can specify a tool/module to use when importing the library. If no tool or module is specified, the first one found will be used. wxPython :: http://wxpython.org :: General-purpose Python GUI toolkit. PyGTK :: http://pygtk.org :: This module is available by default in most Linux distributions. Pillow :: http://python-pillow.github.io :: Only works on Windows. The original PIL package is also supported. Scrot :: http://en.wikipedia.org/wiki/Scrot :: Not used on Windows. Install with apt-get install scrot or similar.

python -m pip install pillow

Project structure

screenshot_demo/ |-- Libraries | `-- unstable_url.py `-- Tests `-- demo.robot

*** Settings *** Documentation Example that uses external python library Library ../libraries/unstable_url . py *** Test Cases *** Check URL [Tags] title ${url}= Get Unstable Url Should Be Equal As Strings ${url} https://www.aredel.com

from robot . libraries . Screenshot import Screenshot from random import randrange _screenshot = Screenshot() def get_unstable_url() -> str: _screenshot.take_screenshot("my_screen", "900px") if randrange(2) == 1: return "https://www.aredel.com" else: return "https://www.heihei.ru"

ТNow, every time unstable_url() is called, a screenshot will be taken by the robot.

It will be visible in the file log.html

Physically, it will be located in the directory from which the test was called.

By default, the first screenshot is called my_screen_1.jpg . If you do not delete it and run the test again, the second file will appear my_screen_2.jpg and so on.

Изображение баннера

Article author: Andrei Olegovich

Похожие статьи
Robot Framework
Basics
Login Test
Empty Fields
reStructuredText
QuickStart
Robot from Python
Изображение баннера

Поиск по сайту

Подпишитесь на Telegram канал @aofeed чтобы следить за выходом новых статей и обновлением старых

Перейти на канал

@aofeed

Задать вопрос в Телеграм-группе

@aofeedchat

Контакты и сотрудничество:
Рекомендую наш хостинг beget.ru
Пишите на info@urn.su если Вы:
1. Хотите написать статью для нашего сайта или перевести статью на свой родной язык.
2. Хотите разместить на сайте рекламу, подходящую по тематике.
3. Реклама на моём сайте имеет максимальный уровень цензуры. Если Вы увидели рекламный блок недопустимый для просмотра детьми школьного возраста, вызывающий шок или вводящий в заблуждение - пожалуйста свяжитесь с нами по электронной почте
4. Нашли на сайте ошибку, неточности, баг и т.д. ... .......
5. Статьи можно расшарить в соцсетях, нажав на иконку сети: