airgun.session

Session controller which manages UI session

Module Contents

Classes

Session

A session context manager which is a key controller in airgun.

Attributes

LOGGER

airgun.session.LOGGER
class airgun.session.Session(session_name=None, user=None, password=None, session_cookie=None, hostname=None, url=None, login=True)

A session context manager which is a key controller in airgun.

It is responsible for initializing and starting airgun.browser.AirgunBrowser, navigating to satellite, performing post-init browser tweaks, initializing navigator, all available UI entities, and logging in to satellite.

When session is about to close, it saves a screenshot in case of any exception, attempts to log out from satellite and performs all necessary browser closure steps like quitting the browser, sending results to saucelabs, stopping docker container etc.

For tests level it offers direct control over when UI session is started and stopped as well as provides all the entities available without the need to import and initialize them manually.

Usage:

def test_foo():
    with Session('test_foo') as session:
        session.architecture.create({'name': 'bar'})
        [...]

    # steps executed after UI session was closed

You can also pass credentials different from default ones specified in settings like that:

with Session(test_name, user='foo', password='bar'):
    # [...]

Every test may use multiple sessions if needed:

def test_foo():
    with Session('test_foo', 'admin', 'password') as admin_session:
        # UI steps, performed by 'admin' user
        admin_session.user.create({'login': 'user1', 'password: 'pwd'})
        # [...]
    with Session('test_foo', 'user1', 'pwd1') as user1_session:
        # UI steps, performed by 'user1' user
        user1_session.architecture.create({'name': 'bar'})
        # [...]

Nested sessions are supported as well, just don’t forget to use different variables for sessions:

def test_foo():
    with Session('test_foo', 'admin', 'password') as admin_session:
        # UI steps, performed by 'admin' user only
        admin_session.user.create({'login': 'user1', 'password: 'pwd'})
        # [...]
        with Session('test_foo', 'user1', 'pwd1') as user1_session:
            # UI steps, performed by 'user1' user OR 'admin' in
            # different browser instances
            user1_session.architecture.create({'name': 'bar'})
            admin_session.architecture.search('bar')
            # [...]
        # UI steps, performed by 'admin' user only
        admin_session.user.delete({'login': 'user1'})
__call__(user=None, password=None, session_cookie=None, url=None, login=None)

Stores provided values. This allows tests to provide additional value when Session object is returned from fixture and used as context manager. Arguments are the same as when initializing Session object, except session_name.

__enter__()

Just a shim to make it compatible with context manager protocol. The real work is done by _open the first time any entity is requested.

__exit__(exc_type, exc_value, traceback)

Attempts to log out, saves the screenshot and performs all required session closure activities.

NOTE: exceptions during logout or saving screenshot are just logged and

not risen not to shadow real session result.

_open(entity)

Initializes requested entity. If this is first time session requests an entity, also initialize and prepare browser.

_prepare_browser(url)

Starts the browser, navigates to satellite, performs post-init browser tweaks, initializes navigator and UI entities, and logs in to satellite.

take_screenshot()

Take screen shot from the current browser window.

The screenshot named f’{self.name}-screenshot-YYYY-mm-dd_HH_MM_SS.png’ will be stored in the path f’{settings.screenshots_path}/YYYY-mm-dd/’.

All directories will be created if they don’t exist. Make sure that the user running Robottelo has the right permissions to create files and directories.

This method is called automatically in case any exception during UI session happens.

activationkey()

Instance of Activation Key entity.

ansibleroles()

Instance of Ansible Roles entity.

ansiblevariables()

Instance of Ansible Variables entity.

architecture()

Instance of Architecture entity.

audit()

Instance of Audit entity.

bookmark()

Instance of Bookmark entity.

cloudinventory()

Instance of RH Cloud Inventory Upload entity.

cloudinsights()

Instance of RH Cloud Insights entity.

computeprofile()

Instance of Compute Profile entity.

configgroup()

Instance of Config Group entity.

containerimagetag()

Instance of Container Image Tags entity.

contentcredential()

Instance of Content Credential entity.

contenthost()

Instance of Content Host entity.

computeresource()

Instance of ComputeResource entity.

contentview()

Instance of Content View entity.

contentview_new()

Instance of the New Content View entity.

contentviewfilter()

Instance of Content View Filter entity.

dashboard()

Instance of Dashboard entity.

discoveredhosts()
discoveryrule()

Instance of Discovery Rule entity.

domain()

Instance of domain entity.

errata()

Instance of Errata entity.

filter()

Instance of Filter entity.

hardwaremodel()

Instance of Hardware Model entity.

host()

Instance of Host entity.

host_new()

Instance of Host entity.

hostcollection()

Instance of Host Collection entity.

hostgroup()

Instance of Host Group entity.

http_proxy()

Instance of HTTP Proxy entity.

insightsaction()

Instance of RHAI Action entity.

insightsinventory()

Instance of RHAI Inventory entity.

insightsoverview()

Instance of RHAI Overview entity.

insightsplan()

Instance of RHAI Plan entity.

insightsrule()

Instance of RHAI Rule entity.

jobinvocation()

Instance of Job Invocation entity.

insightsmanage()

Instance of RHAI Manage entity.

jobtemplate()

Instance of Job Template entity.

ldapauthentication()

Instance of LDAP Authentication entity.

lifecycleenvironment()

Instance of LCE entity.

location()

Instance of Location entity.

login()

Instance of Login entity.

operatingsystem()

Instance of Operating System entity.

organization()

Instance of Organization entity.

oscapcontent()

Instance of OSCAP Content entity.

oscappolicy()

Instance of OSCAP Policy entity.

oscaptailoringfile()

Instance of OSCAP Tailoring File entity.

package()

Instance of Packge entity.

media()

Instance of Media entity.

modulestream()

Instance of Module Stream entity.

partitiontable()

Instance of Partition Table entity.

puppetclass()

Instance of Puppet Class entity.

puppetenvironment()

Instance of Puppet Environment entity.

product()

Instance of Product entity.

provisioningtemplate()

Instance of Provisioning Template entity.

reporttemplate()

Instance of Report Template entity.

redhatrepository()

Instance of Red Hat Repository entity.

repository()

Instance of Repository entity.

role()

Instance of Role entity.

rhsso_login()

Instance of RHSSOLoginEntity entity.

settings()

Instance of Settings entity.

sc_parameter()

Instance of Smart Class Parameter entity.

subnet()

Instance of Subnet entity.

subscription()

Instance of Subscription entity.

syncplan()

Instance of Sync Plan entity.

sync_status()

Instance of Sync Status entity

sync_template()

Instance of Sync Templates entity

task()

Instance of Task entity.

user()

Instance of User entity.

usergroup()

Instance of User Group entity.

virtwho_configure()

Instance of Virtwho Configure entity.

webhook()

Instance of Webhook entity.