ConsoleUser

Copyright (c) 2010-2023 Skaion Corporarion, www.skaion.com

This project was developed in part by numerous sponsorships from the U.S. Government. The U.S. Government is authorized to reproduce and distribute reprints of Governmental purposes notwithstanding any copyright notation thereon.

All content reflects those of the authors and should not be interpreted as necessarily representing the official policies or endorsements, either expressed or implied, of the U.S. Government or Skaion Corporation.

class WebBrowserImpl.WebBrowserImpl(system, config)

Defines an abstract class that provides a common interface to all web browsers the User knows how to use. Subclasses of this class will implement actual interaction with real browsers.

Parameters:

  • system: a <no title> object which lets us control the remote system

  • config: a <no title> object defining the current user

Find a link on the page with the given text and click on it.

This may require scrolling the screen to find the link.

This method will not return until the new page is done loading or it has been deteremined that the link cannot be found.

Parameters:

  • text: a string that is the text of the link to click

  • wait_for_load: determines whether this function should try

    to wait for the page to load or not

This will find any link that is currently visisble (without scrolling, and without defined behavior for links that are only half visible), then choose one at random and click on it.

close_remember_password()

Given that a dialog (or similar) is open to offer to remember the password for the current site, close it. By default for most browsers this will not have it remember the password.

confirm_leave()

If a prompt to confirm leaving this page is visible, do indeed give that confirmation.

do_helper(helper_id, *args, **kwargs)

Invoke a helper to do its thing.

download_file(path, duration=300, clear_name=True)

After the browser has already gone to the uri to download a file, walk through the rest of the dialogs to save the file to the given path.

Parameters:

  • path: where to save the file

  • duration: the max time to wait for the download, use -1 to not wait

  • clear_name: whether or not to clear the existing name before adding the path

Click a link which will start a download, then save it to the given path.

Parameters:

  • link: the string link text to click to start the download

  • path: the local path to save the file

download_uri(uri, path)

Enter a given URI which will start a download, then save it to the given path.

Parameters:

  • uri: the string URI to enter to start the download

  • path: the local path to save the file

exit2(save=False)

Exit the browser

fill_in_form()

Find and fill in a form on the page.

Return: True if a form was found and filled in, False otherwise

generate_text(text, fg_colors, bg_color=63)

Given a string and sets of colors, create the regions this browser would expect to find.

Parameters:

  • text: the text to be converted to a <no title>

  • fg_colors: a list of foreground colors for the text

  • bg_color: the background color the text is expected to appear on

Return: a list of :doc:`Region`s of the different ways the text

might appear

go_back()

Press the Back button, or some sequence that accomplished the same goal (e.g., pressing backspace will often do it too).

go_forward()

Press the Forward button, or some sequence that accomplished the same goal

go_to_uri(uri, wait_for_load=True)

Navigate to the URI, bringing this window to the fore before trying.

This method will block until the page is finished loading.

Parameters:

  • uri: a string to be typed into the URL bar of the browser

  • wait_for_load: determines whether this function should try

    to wait for the page to load or not

has_confirm_leave()

Some browsers will prompt to confirm leaving a site if there is content that will be lost. This method returns if such a prompt is currently displayed.

has_remember_password()

This will check to see if the browser is currently showing a dialog or similar offering to remember the password for this site.

is_loaded(*args, **kwargs)

Check whether the current activity has finished loading.

Every subclass should override this method.

read()

“Read” the current page, which may include scrolling.

reload(wait_for_load=True)

Reload the current page.

WebBrowserImpl.get_browser_impl(system, config, browser_type=None, unique=False)

This is a Factory function which will instantiate the correct WebBrowserImpl subclass give then config or browser type specified.

Parameters:

  • system: a <no title> object which lets us control the remote system

  • config: a <no title> object defining the current user

  • type: optionally a web browser type which can be passed to the

    WebBrowserImpl factory to get a suitable implementer object back

  • unique: By default, the same instance of the browser will be returned

    across multiple calls, this will get a unique one instead