Selenium WebDriver Plugin/en: Unterschied zwischen den Versionen

Aus expecco Wiki (Version 2.x)
Zur Navigation springen Zur Suche springen
 
(16 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
[[Selenium_WebDriver_Plugin|Deutsche Version]] | '''English Version'''

=Introduction=
=Introduction=
Use the ''Selenium WebDriver Plugin'' to test or automate interactions of applications running in a web-browser (*). The plugin can be (and usually is) used with the [[Expecco_GUI_Tests_Extension_Reference|GUI Browser]], which helps in the creation of tests. Moreover, the GUI Browser can record UI sessions, which can later be customised or refactored as required.
Use the ''Selenium WebDriver Plugin'' to test or automate interactions of applications running in a web-browser (*). The plugin can be (and usually is) used with the [[Expecco_GUI_Tests_Extension_Reference|GUI Browser]], which helps in the creation of tests. Moreover, the GUI Browser can record UI sessions, which can later be customised or refactored as required.
Zeile 7: Zeile 9:
Read [[#Transferring_Old_Selenium_Tests|this section]] for information how to transfer testsuites using the old plugin.
Read [[#Transferring_Old_Selenium_Tests|this section]] for information how to transfer testsuites using the old plugin.


(*) actually, there exists WebDriver interfaces to control Windows or OS X desktop applications. Thus, this plugin can be used in a number of additional szenarios.
(*) actually, there exists WebDriver interfaces to control Windows or OS X desktop applications. Thus, this plugin can be used in a number of additional scenarios.

=Settings=
This plugin uses the Java bridge and therefore needs a Java installation. You can specify it in the settings under ''Plugins'' -> ''Java Bridge''. The important field is ''Java Installation Path'', where you can set a JDK or JRE. If nothing is set, expecco tries to find java in the PATH.

[[Datei:JDKPfadEinstellungen.png|600px]]

There are settings for the Selenium WebDriver Plugin itself as well. You find them under ''Plugins'' -> ''Webtest (Selenium WebDriver)''. There you can for example set the address of a remote running Selenium server or another Jar file for Selenium. The settings for the different browser types are divided into the two subpages ''Most Popular Browsers'' and ''Other Browsers''. There you can set the path to the browser executable or to the webdriver to use. You can leave all these fields empty and expecco will search for them automatically


=Browser Support=
=Browser Support=
Zeile 15: Zeile 24:
In addition, many other browsers, UIs and devices support the WebDriver protocol, and can thus be automated/tested with expecco.
In addition, many other browsers, UIs and devices support the WebDriver protocol, and can thus be automated/tested with expecco.


==Update WebDriver==
Each browser has a driver ("''WebDriver''") for opening and controlling a browser window.
Each browser has a driver ("''WebDriver''") for opening and controlling a browser window.
Usually, the driver is a separate program which translates WebDriver requests into browser-specific interface calls. However, there are also browsers and programs which have the WebDriver protocol already built in (eg. Safari).
Usually, the driver is a separate program which translates WebDriver requests into browser-specific interface calls. However, there are also browsers and programs which have the WebDriver protocol already built in (eg. Safari).


The expecco installation package includes drivers for common browsers. However, you may have to update a driver, if the browser version changes. The used drivers are located in your expecco installation directory below the installation folder in:
The expecco installation package includes current driver versions for common browsers. However, as the browsers are updated continuously, sometimes even automatically, you sooner or later may have to download a new driver version. In that case put it in the folder inside your expecco installation directory where the other versions are stored as well, at:
<code>packages/exept/expecco/plugin/seleniumWebDriver/lib</code>
<code>packages/exept/expecco/plugin/seleniumWebDriver/lib/XXX</code>
(of course, with "\”s instead of "/"s on Microsoft Windows operating systems).
(of course, with "\”s instead of "/"s on Microsoft Windows operating systems), where "XXX" denotes the operating system (Windows, Linux, OSX etc.).
To use a different driver, check the "Advanced" toggle in the connection dialog and add the driver's path to the settings (see below).
<!--To use a different driver, check the "Advanced" toggle in the connection dialog and add the driver's path to the settings (see below).-->

In the connection dialog, expecco may show a warning, that the driver version is incompatible with the browser version. In some cases this may only be due to the fact, that this version was not known at the time of delivery. Some combinations may work despite the warning, but we cannot guarantee that for each individual case.

Therefore you can always check the "''Do not show this warning again''" toggle, if such a warning is shown, to have expecco remember that combination as "compatible" in your settings, and not warn again. You should only do that, if you are sure that your tests will still be executed correctly. As we sometimes get compatibility problems ourselves and cannot always immediately find the reason, we advice you, to update the driver.


For Chrome and Microsoft Edge, where each new browser version comes with a new driver version, you find a button in the connection dialog, to download matching driver versions by expecco.
In some cases, expecco may show a warning, that the driver version might be incompatible with the browser. This does not mean per se, that the combination does not work; instead, it means that the combination has not been tested by eXept, but may nevertheless work. If such a warning is shown, check the "''Do not show this warning again''" toggle, to have expecco remember that combination as "trusted" in your settings.


You find new driver versions at the following addresses:
You find new driver versions at the following addresses:
{|
{|
|Chrome/Chromium
|Chrome/Chromium
|[https://sites.google.com/a/chromium.org/chromedriver/downloads ChromeDriver]
|[https://sites.google.com/chromium.org/driver/ ChromeDriver]
|-
|-
|Edge
|Edge
Zeile 55: Zeile 69:
If you get an error like <code>"org.openqa.selenium.JavascriptException: Error executing JavaScript"</code>,
If you get an error like <code>"org.openqa.selenium.JavascriptException: Error executing JavaScript"</code>,
make sure that JavaScript is enabled in the browser and that the versions of the browser and the associated driver are compatible.
make sure that JavaScript is enabled in the browser and that the versions of the browser and the associated driver are compatible.

=Additional Uses=
{|
|[https://github.com/appium/appium-for-mac AppiumForMac]
|WebDriver to control OS X apps (i.e. also non-Browsers)
|-
|[https://github.com/microsoft/WinAppDriver WinAppDriver]
|WebDriver to control Windows Desktops
|}

Notice, that these interfaces usually provide a subset of the functionality provided by special plugins, such as Java-GUI or WindowsAutomation plugins. Usually, they are ok to manipulate the top level window or to confirm simple dialogs, but less usable for more complex UI tests.


= Quick Start =
= Quick Start =
Zeile 169: Zeile 194:
#'''Set Screen Scale to Fit Window''': Scale the screenshot to fully fit in the window
#'''Set Screen Scale to Fit Window''': Scale the screenshot to fully fit in the window
#'''Scale''': Changes the scale of the screenshot. Can also be adjusted by scrolling with pressed <kbd>CTRL</kbd> key.
#'''Scale''': Changes the scale of the screenshot. Can also be adjusted by scrolling with pressed <kbd>CTRL</kbd> key.
#'''Notifications''': Shows notifications, e.g. if an action cannot be recorded. The last notification is displayed until it is closed by the button on its right side.<br>'''Window Tabs''': As of expecco 23.1, tabs are displayed above the display for each open window as soon as a connection has more than one browser window. Whether the browser displays this as a tab or in its own window does not matter. You can use the tabs in the recorder to switch the current window and also record this switch.<br>'''Frame context''': As of expecco 23.1, you can see below the display in which frame context you are currently in (see the section [[#Embedded_Content|Embedded Content]]). You can click on the entries to switch to a higher context and record this switch. If you have compound paths enabled, the display will update when you select an embedded item.
#'''Notifications''': Shows notifications, e.g. if an action cannot be recorded. The last notification is displayed until it is closed by the button on its right side.

=Embedded Content=
In HTML it is possible to include content from another page within one page. The most common element to do this is an iframe (inline frame). The content of an iframe can also be accessed with Selenium, but first you have to switch to this context. In the SeleniumWebDriverLibrary there are corresponding blocks to switch to the context of an iframe, to switch to the parent context and to switch back to the default content, i.e. the top context. All element blocks always resolve the applied paths within the current context. In the GUI browser, you will see an additional element for embedded content, which you can expand to see its elements.

==Compound Paths==
Since expecco 23.1 there is the possibility to also use compound paths at the blocks to access the content of an iframe directly from the standard content. For this purpose, simply the path to the iframe and the path within the iframe content are combined into one. It is important here that no elements may be omitted at the transition, i.e. the front part must end with the iframe element and the back part must begin with ''/body''. In between the paths may be shortened and it is of course also possible to access elements nested to any depth in this way. Both techniques can be used on the blocks as desired, the only important thing is that the paths are always resolved in the context in which Selenium is currently located.

If you want to record the combined paths or use them in the GUI Browser, check the box ''Record Compound Paths'' in the ''GUI Browser'' menu under ''Recording''. This will create and display a compound path for embedded elements relative to the current context, instead of only within its own context as before. You can also address these elements directly in the recorder or find them via Follow-Mouse.

=Shadow Elements=
Shadow DOMs allow you to encapsulate parts of a page from the remaining document. They provide a way to attach hidden shadow elements to an element. You can find a more detailed explanation for example here: [https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM Using shadow DOM - Web APIs | MDN].

The SeleniumWebDirverLibrary has the block ''[Web] Get Shadow DOM'', which gives you the topmost elements, which then can be used like other WebElements.

As the elements are hidden, they are not directly displayed in the GUI browser. However, since expecco 23.1 you can check in the context menu of the elements in the GUI browser the option to find shadow elements. They then will be displayed when updating the children of an element, if there are any, but not when updating the whole tree. If the option is checked, the elements are also available in the recorder.

==Compound Paths==
Similar to elements inside a frame, shadow elements can be accessed by compound paths. These paths can be used directly at the library blocks and the block ''[Web] Get Shadow DOM'' is not required. The paths are of the form
<host path>/shadowRoot/<shadow path>
where ''<host path>'' denotes the path to the element that has the shadow DOM attached, and ''<shadow path>'' denotes the path inside the shadow DOM to the desired element. '/shadowRoot' serves as marker where the switch to the shadow DOM is needed.


=Authentication Alerts=
=Authentication Alerts=
Zeile 202: Zeile 247:
*'''Error message <code>Cannot read property 'left' of undefined</code>'''
*'''Error message <code>Cannot read property 'left' of undefined</code>'''
:The error <code>org.openqa.selenium.JavascriptException: javascript error: Cannot read property 'left' of undefined</code> can occur with the Chrome browser. This means that the used element is not visible. See the point above on that. The error is also known in combination with elements in a dropdown list, i.e. when clicking or moving the mouse over a <nowiki><option></nowiki> element within a <nowiki><select></nowiki> element. Such elements are generally not clickable. Instead, use a suitable <code>[Web] Select</code> block with the <nowiki><select></nowiki> element.
:The error <code>org.openqa.selenium.JavascriptException: javascript error: Cannot read property 'left' of undefined</code> can occur with the Chrome browser. This means that the used element is not visible. See the point above on that. The error is also known in combination with elements in a dropdown list, i.e. when clicking or moving the mouse over a <nowiki><option></nowiki> element within a <nowiki><select></nowiki> element. Such elements are generally not clickable. Instead, use a suitable <code>[Web] Select</code> block with the <nowiki><select></nowiki> element.

*'''Error message: <code>Stale Element Reference Exception</code>'''
:The error <code>org.openqa.selenium.StaleElementReferenceException</code> occurs whenever a WebElement is used that is no longer there. If that happens during your test and the element should have been there, try using the locator instead to fetch the element again. Maybe the error occurs because the test is currently in a different frame context as the element. If you are using [[#Compound_Paths|compound paths]], the element should switch by itself to the correct context when it is used.
:In rare cases this error can also occur in expecco itself, if at somewhere in the GUI browser or the recorder such a WebElement is used. You should then be able to abort and try again. Should the error persist, switch to the default content and refresh the tree in the GUI browser.


*'''Block runs successfully, but without effect'''
*'''Block runs successfully, but without effect'''
Zeile 208: Zeile 257:
*'''Executions using Chrome are slower'''
*'''Executions using Chrome are slower'''
:To fix a problem when executing with Chrome, a delay is defined in the plugin settings for Chrome. Check if this value is possibly too high; see [[#Execution_Delay_for_Chrome | Execution Delay for Chrome]].
:To fix a problem when executing with Chrome, a delay is defined in the plugin settings for Chrome. Check if this value is possibly too high; see [[#Execution_Delay_for_Chrome | Execution Delay for Chrome]].

*'''Errors like: "org.openqa.selenium.InvalidArgumentException: Expected "handle" to be a string..."'''
:This occurs if the driver does not match the browser (any more). Please read the above chapter "[[#Update WebDriver|Update WebDriver]]".

*'''Key Chords with Shortcuts are not working'''
:Pressing keys simultaneously can be simulated using Key Chords. They can also be used to send shortcuts. However, not all inputs will work, as they are only sent to the page content, not to the browser itself. Combinations like ''Ctrl + t'' to open a new browser tab probably wont't work, ''Ctrl + a'' and ''Ctrl c'' on the other hand should be effective.

*'''Additional Window Handles for Opera'''
:The Opera browser returns more window handles as there are opened tabs or windows. They represent Opera internal features like ''Speed Dial'' or ''Better Address Bar Experience'' (BABE), which are embedded in the browser window, but not displayed like regular tabs. You can switch to these tabs using an appropriate action block, however not all actions are possible then, which can be used with the normal tabs. For example you cannot close them and they don't provide a screenshot. Therefore it is better to not even switch to their contexts. So be careful when switching to a tab by index, as the Opera tabs are among the others and the index might be a different one than for the other browser types.

Aktuelle Version vom 8. November 2023, 13:46 Uhr

Deutsche Version | English Version

Introduction[Bearbeiten]

Use the Selenium WebDriver Plugin to test or automate interactions of applications running in a web-browser (*). The plugin can be (and usually is) used with the GUI Browser, which helps in the creation of tests. Moreover, the GUI Browser can record UI sessions, which can later be customised or refactored as required.

The Selenium WebDriver Plugin replaces the previous Selenium Web Test Plugin, which was based on the now outdated Selenium RC framework.
The new web driver uses the Selenium WebDriver for automation, and replaces the previous interface. (see https://www.guru99.com/introduction-webdriver-comparison-selenium-rc.html for background information and a description of the differences.) Read this section for information how to transfer testsuites using the old plugin.

(*) actually, there exists WebDriver interfaces to control Windows or OS X desktop applications. Thus, this plugin can be used in a number of additional scenarios.

Settings[Bearbeiten]

This plugin uses the Java bridge and therefore needs a Java installation. You can specify it in the settings under Plugins -> Java Bridge. The important field is Java Installation Path, where you can set a JDK or JRE. If nothing is set, expecco tries to find java in the PATH.

JDKPfadEinstellungen.png

There are settings for the Selenium WebDriver Plugin itself as well. You find them under Plugins -> Webtest (Selenium WebDriver). There you can for example set the address of a remote running Selenium server or another Jar file for Selenium. The settings for the different browser types are divided into the two subpages Most Popular Browsers and Other Browsers. There you can set the path to the browser executable or to the webdriver to use. You can leave all these fields empty and expecco will search for them automatically

Browser Support[Bearbeiten]

This plugin supports (among others) the Chrome/Chromium, Edge, Firefox, Internet Explorer and Opera browsers.
Safari under OSX must be at least version 10, and OSX must be at least El Capitan. The plugin uses the WebDriver interface for communication; therefore, browsers running both on the local or on a remote machine can be tested and/or controlled. In addition, many other browsers, UIs and devices support the WebDriver protocol, and can thus be automated/tested with expecco.

Update WebDriver[Bearbeiten]

Each browser has a driver ("WebDriver") for opening and controlling a browser window. Usually, the driver is a separate program which translates WebDriver requests into browser-specific interface calls. However, there are also browsers and programs which have the WebDriver protocol already built in (eg. Safari).

The expecco installation package includes current driver versions for common browsers. However, as the browsers are updated continuously, sometimes even automatically, you sooner or later may have to download a new driver version. In that case put it in the folder inside your expecco installation directory where the other versions are stored as well, at:

packages/exept/expecco/plugin/seleniumWebDriver/lib/XXX

(of course, with "\”s instead of "/"s on Microsoft Windows operating systems), where "XXX" denotes the operating system (Windows, Linux, OSX etc.).

In the connection dialog, expecco may show a warning, that the driver version is incompatible with the browser version. In some cases this may only be due to the fact, that this version was not known at the time of delivery. Some combinations may work despite the warning, but we cannot guarantee that for each individual case.

Therefore you can always check the "Do not show this warning again" toggle, if such a warning is shown, to have expecco remember that combination as "compatible" in your settings, and not warn again. You should only do that, if you are sure that your tests will still be executed correctly. As we sometimes get compatibility problems ourselves and cannot always immediately find the reason, we advice you, to update the driver.

For Chrome and Microsoft Edge, where each new browser version comes with a new driver version, you find a button in the connection dialog, to download matching driver versions by expecco.

You find new driver versions at the following addresses:

Chrome/Chromium ChromeDriver
Edge Microsoft WebDriver
Firefox GeckoDriver
Internet Explorer IEDriverServer
Opera Opera driver
Safari Safari Support

Download a suitable version and place it at an appropriate location in the above mentioned directory. expecco will then find and use it. Alternatively, you can set the path to a driver either in the connection editor or in the plugin settings.

Bulb.pngPlease verify that the driver's version is compatible with the browser version. If in doubt, consult the version history (e.g. for Chrome: https://chromedriver.storage.googleapis.com/2.25/notes.txt).

Bulb.pngNotice: For Internet Explorer, "Protected Mode" settings must be set to the same value for all zones, to be able to start a connection. (in the Internet Explorer, open "Settings" - "Internet Options" - "Security", and set the value of "protected mode" to the same in all 4 zones; otherwise, you'll get error- and warning dialogs when connecting). See also the required configuration to use InternetExplorerDriver.

Bulb.pngAlso notice: the plugin uses JavaScript for some advanced functions, and those functions require that JavaScript is enabled in the browser. This is especially needed to use the GUI browser and the recorder. Test execution may be possible without JavaScript, as long as no actions are used which rely on JavaScript. If you get an error like "org.openqa.selenium.JavascriptException: Error executing JavaScript", make sure that JavaScript is enabled in the browser and that the versions of the browser and the associated driver are compatible.

Additional Uses[Bearbeiten]

AppiumForMac WebDriver to control OS X apps (i.e. also non-Browsers)
WinAppDriver WebDriver to control Windows Desktops

Notice, that these interfaces usually provide a subset of the functionality provided by special plugins, such as Java-GUI or WindowsAutomation plugins. Usually, they are ok to manipulate the top level window or to confirm simple dialogs, but less usable for more complex UI tests.

Quick Start[Bearbeiten]

Open Browser / Connecting[Bearbeiten]

  • Start expecco
  • Click on "New Testsuite"
  • Click on the GUI-Browser symbol (GUIBrowser.png)
  • A new Tab appears, containing the GUI-Browser
  • Click on "Connect" and choose "Selenium Testing". The Connection Dialog appears (see details below)
  • Choose the type of browser (eg. "firefox" and enter the URL of the tested web site (eg. "http://www.myHost.com") and )
  • Click on "Connect"
  • A browser is started automatically, and the page is shown
  • As soon as the connection is established, the page's elements are shown in the GUIBrowser's left tree view

Start a Recording[Bearbeiten]

  • After a connection has been established, click on the record icon (Recording.png) in the GUIBrowser.

Inspecting Elements[Bearbeiten]

  • Select an element in the browser's element-tree, or move the mouse over it in "follow-mouse mode". If your browser does not support this "follow-mouse" mode, try opening a recorder, and move the mouse there.

The element's attributes are shown in the lower-center attribute/property list.

Manually adding Actions and Checks[Bearbeiten]

  • In addition to recording, actions and checks can also be selected from the upper-centre action list. Select one there and either try it immediately or add it to the recording sequence via the add-action button at the top far right.

Connecting[Bearbeiten]

Connection Editor[Bearbeiten]

The connection editor defines, changes or starts a connection. Open the GUI browser, click on "Connect" and select "Selenium Testing (WebDriver)". You can also create attachments or files containing connection parameters ("connection settings") without actually connecting to/opening a new browser connection via the "Save Connection Settings" menu item.

When opened, the connection editor presents a number of fields and load/save buttons in its toolbar menu:


SeleniumWebDriverConnectDialog.png

  1. Load settings from attachment: Open an attachment containing connection settings from an open project. This settings will be added to the editor. Already entered inputs that are not conflicting will remain unchanged.
  2. Load settings from file: Open a saved settings file (*.csf). Its settings will be added to the editor. Already entered inputs that are not conflicting will remain unchanged.
  3. Save settings as attachment: Save all entered settings as attachment in an open project.
  4. Save settings as JSON attachment: Save all entered settings in JSON format as attachment in an open project.
  5. Save settings to file: Save all entered settings to a file (*.csf).
  6. Version info: Opens a window showing the used versions of the Selenium server, the selected browser and its driver.
  7. Online documentation: Open this online documentation page.
  8. Connection name: Enter the name of the connection used to show it in the GUI browser. (Optional)
  9. Browser type: Choose the type of browser to use. Ensure it is installed and the version of the used driver is compatible with the browser version.
  10. URL: Enter the URL to open at startup. To open an empty browser window, leave this field empty. To open a local file use the "file://" scheme, e.g. "file:///C:/Users/admin/Desktop/index.html".
  11. Advanced view: Toggle the view to enter advanced settings.
  12. Information on the selected browser: Here, the selected browser type is shortly characterized.
  13. Information on the settings: It shows which Selenium, browser and driver version will be used regarding the current settings. If you have set advanced settings, they will also be displayed here.

Advanced Settings[Bearbeiten]

Besides the used browser and the start URL, more settings and possibly "capabilities" may be required. To see click on the "Advanced" toggle. Depending on the selected browser type you get different entry fields.

  • Remote Server: To open a browser on a remote host, start a Selenium server there and set this field to its address. You can also enter a local address if you do not want the Selenium server to start automatically or if it is already running. See the next section Remote Connections on how to start a Selenium server.
  • Headless: to open the browser in "headless" mode, i.e. without a window. Not all browsers/drivers support this mode.
  • Binary: Enter the path to the binary of the selected browser. Use this if the browser cannot be found automatically by Selenium, or if you have another browser version installed or to be tested against.
  • Driver: For each browser, a particular driver is needed for automation. New browser versions often also need a new driver version. If you don't want or cannot use the driver provided by expecco, set its path here.
  • Command Line Options: arguments passed to the browser-command. For example the chrome browser supports a "--disable-extensions" command line argument, firefox supports "--safe-mode" and "--profile". These options are browser- and possibly browser-version specific. Most browsers allow for a "--help" argument, which you may try in a shell window to find out.
  • Firefox Profile: For Firefox, it is possible to set a Firefox Profile, containing specific settings. If no profile is set, each connection will use a new empty one.
  • Capabilities: Selenium connections can use several capabilities to define the connection's behavior. To add specific capabilities, set them in this field. Write "<capability name>: <value>" or "<capability name> = <value>", one entry per line.

    The set of capabilities needed or supported are browser- and driver specific. Please refer to the concrete driver's documentation as found via the driver links above. Common capabilities are: "app" or "application", "url", etc. For drivers which communicate with mobile devices, the capabilities also select which device to use and/or wether an emulator should be started.

    You can also set properties for the Firefox browser - for this, use the same syntax as for capabilities, but add a leading $ to the property name.

    Properties used by expecco internally (such as browser type, url or remote host) are prefixed by a "#"-character.

Remote Connections[Bearbeiten]

To start a browser on a remote computer, copy the Selenium server and the required driver to that computer. You find the files in your expecco installation at "packages\exept\expecco\plugin\seleniumWebDriver\lib". Start the Selenium server (on the remote host) with:

java -jar selenium-server-standalone-3.6.0.jar

By default, the server will listen on port 4444. To use another port, set it with the "-port <nr>" command line argument. To connect to that server, set the "remote server" parameter of the connection to "<Server-Address>:4444/wd/hub".

Check and possibly configure your firewall to allow transmission through the port.

Headless Browsing[Bearbeiten]

"Headless Browsing" means: "without a window", and is useful to test web-pages for reachability, performance and structure. You can either use the HTMLUnit browser type, which simulates a browser, or run against one of the real browsers in headless mode. Notice, that not all browsers support this headless mode - we recommend using "firefox" or "chrome" for this.

Also notice, that in order to verify that a web page's interaction with a browser works correctly, you should test against real browsers. For an introduction on what "headless browsing" means, see for example https://www.guru99.com/selenium-with-htmlunit-driver-phantomjs.html.

Notice: the HTMLUnit driver has been removed from the latest selenium distribution and is also no longer supplied with expecco (it was not a good test tool anyway, as it behaved differently from real browsers).
If required, download from https://github.com/SeleniumHQ/htmlunit-driver.

Connection Blocks[Bearbeiten]

SeleniumWebDriverLibrary offers a number of blocks to start a Selenium connection within a testrun. The connection name identifies the connection during the run, if the test uses multiple connections and switches between them (eg. if multiple browser windows are open simultaneously). To start a connection with predefined settings, save them in the connection dialog (as attachment), and use the "[Connect From File]" action block.

Plugin Settings[Bearbeiten]

To use certain browser installations or drivers as default, for every connection, set them in the settings dialog of the plugin ("Extras" → "Settings" → "Plugins" → "Selenium WebDriver Extension"). Settings for specific browsers can be found under "Most Popular Browsers" or "Other Browsers". The settings there are used as default, unless overwritten by an individual connection configuration.

Execution Delay for Chrome[Bearbeiten]

In some cases it can happen when using the Chrome browser that blocks with element actions, for example a click, run successfully in the test, but the actual action was not executed at all. This is a known bug [1], [2] that needs to be fixed by Selenium or Chromedriver. The error can be prevented by either calling the click via JavaScript – to do this, set invokeDirectly to true at the click block – or wait briefly before the action. Execution via JavaScript has the disadvantage that it is less close to the click of a real user and, for example, clicks on elements work even if they are hidden by other elements. In general, blocks with element actions automatically wait until the corresponding element is available. In the cases described here, however, this is not sufficient. Therefore you will find the setting execution delay in the plugin settings for Chrome. During execution, the system waits accordingly long between each action. If you experience the described error, you can increase its value. Of course, a higher value has an effect on the test run executio times.

Recorder[Bearbeiten]

The following description applies to all GUI technologies which support remote recording in the integrated expecco recorder: the behaviour of the recorder is (apart from small differences due to technology-specific limitations) the same across different connections.

Use of this recorder has some advantages over direct recording in the browser:

  • it can be used with remote machines/connections/mobil devices
    especially for mobile devices, which may be all located in a separate (server-) room
  • it provides precise control over which event is to be recorded.
    For example, for clicks, there are alternative ways to record: as "press-release", as "click", as "move-then-click", as "move-then-press-delay-release". Depending on the page's underlying event handling (typically done in JavaScript), either one may be required.

Once connected to a browser, the integrated recorder can be used to record a test case. Start the recorder by selecting the appropriate connection in the GUI browser's left tree and click the record button. The recorder opens a new window. Each click in the window records an action. More actions are available in the menu. Recorded actions are added to the workspace of the GUI browser to form a sequence of interactions. This sequence can be edited, parametrized or replayed immediately. When finished, it should be saved into the suite as a new "Test Action".

General actions can be found either directly in the menu bar or there in the Browser Tools menu (see below). To record actions on elements, either change the selection of the element tool in the menu bar (see below) and click on the element or select the corresponding action from the context menu by right-clicking on the element. For text input, you can also place the cursor over the element and enter the text. The input dialog for this action opens. It is also possible to record the imputs backspace, return and tab that way.

SeleniumWebDriverRecorder.png

Components of the recorder window

  1. Pause recording: If the control lamp is red, the recorder is in "recording"-mode. Pause the recording by clicking on this lamp. The lamp will turn to grey. In this state you can execute actions with the recorder, but they are not recorded. Click again to resume the recording.
  2. Update: Update the screenshot on the element tree. Necessary if the recorder view does not fit the browser content.
  3. Follow-Mouse: The element under the cursor is selected in the GUI browser.
  4. Element Highlighting: The element under the cursor gets a red frame.
  5. Element Tools: Select which tool to use for recording. You can choose between all actions that use a certain element. The selected action is triggered by each click in the view and the element is determined by the click position. Not selected actions are available by right click.
  6. Browser Tools: Actions not refering to ocertain elements, like scrolling or actions on the current URL or the title, can be triggered here.
  7. Page navigation: Actions for page navigation: Back, Forward and Refresh Page
  8. Alert Handling: Click this button if the browser shows an alert, to be able to select the actions for alert handling.
  9. Online Documentation: Open this online documentation.
  10. View: Shows a screenshot of the browsers. Actions can be triggered by mouse depending on the selected tool. If a new action can be entered, the frame of the window is green, red otherwise. Scrolling is forwarded to the browser, but not recorded.
  11. Resize Window to Screen Size: Change the size of the window to show the whole screenshot.
  12. Set Screen Scale to Fit Window: Scale the screenshot to fully fit in the window
  13. Scale: Changes the scale of the screenshot. Can also be adjusted by scrolling with pressed CTRL key.
  14. Notifications: Shows notifications, e.g. if an action cannot be recorded. The last notification is displayed until it is closed by the button on its right side.
    Window Tabs: As of expecco 23.1, tabs are displayed above the display for each open window as soon as a connection has more than one browser window. Whether the browser displays this as a tab or in its own window does not matter. You can use the tabs in the recorder to switch the current window and also record this switch.
    Frame context: As of expecco 23.1, you can see below the display in which frame context you are currently in (see the section Embedded Content). You can click on the entries to switch to a higher context and record this switch. If you have compound paths enabled, the display will update when you select an embedded item.

Embedded Content[Bearbeiten]

In HTML it is possible to include content from another page within one page. The most common element to do this is an iframe (inline frame). The content of an iframe can also be accessed with Selenium, but first you have to switch to this context. In the SeleniumWebDriverLibrary there are corresponding blocks to switch to the context of an iframe, to switch to the parent context and to switch back to the default content, i.e. the top context. All element blocks always resolve the applied paths within the current context. In the GUI browser, you will see an additional element for embedded content, which you can expand to see its elements.

Compound Paths[Bearbeiten]

Since expecco 23.1 there is the possibility to also use compound paths at the blocks to access the content of an iframe directly from the standard content. For this purpose, simply the path to the iframe and the path within the iframe content are combined into one. It is important here that no elements may be omitted at the transition, i.e. the front part must end with the iframe element and the back part must begin with /body. In between the paths may be shortened and it is of course also possible to access elements nested to any depth in this way. Both techniques can be used on the blocks as desired, the only important thing is that the paths are always resolved in the context in which Selenium is currently located.

If you want to record the combined paths or use them in the GUI Browser, check the box Record Compound Paths in the GUI Browser menu under Recording. This will create and display a compound path for embedded elements relative to the current context, instead of only within its own context as before. You can also address these elements directly in the recorder or find them via Follow-Mouse.

Shadow Elements[Bearbeiten]

Shadow DOMs allow you to encapsulate parts of a page from the remaining document. They provide a way to attach hidden shadow elements to an element. You can find a more detailed explanation for example here: Using shadow DOM - Web APIs | MDN.

The SeleniumWebDirverLibrary has the block [Web] Get Shadow DOM, which gives you the topmost elements, which then can be used like other WebElements.

As the elements are hidden, they are not directly displayed in the GUI browser. However, since expecco 23.1 you can check in the context menu of the elements in the GUI browser the option to find shadow elements. They then will be displayed when updating the children of an element, if there are any, but not when updating the whole tree. If the option is checked, the elements are also available in the recorder.

Compound Paths[Bearbeiten]

Similar to elements inside a frame, shadow elements can be accessed by compound paths. These paths can be used directly at the library blocks and the block [Web] Get Shadow DOM is not required. The paths are of the form

<host path>/shadowRoot/<shadow path>

where <host path> denotes the path to the element that has the shadow DOM attached, and <shadow path> denotes the path inside the shadow DOM to the desired element. '/shadowRoot' serves as marker where the switch to the shadow DOM is needed.

Authentication Alerts[Bearbeiten]

If a Web page uses HTTP authentication with Basic Authentication, an alert window for entering the user name and password opens when the page is loaded. This window cannot be accessed directly with Selenium. In the GUI browser, it is displayed as an alert. An exception to this is Chrome, where the driver does not respond to any request as long as the dialog is open. At this point, the plugin cannot even determine whether an authentication dialog is open or whether the driver is not responding for other reasons.

For local connections under Windows, authentication can be performed using Windows Access. In the SeleniumWebDriverLibrary there are specific authentication blocks for individual browser types as well as the block Authenticate at Alert, which executes the corresponding block depending on the connection. There are different restrictions for the different browser types:

Chrome: The credentials are sent to a chrome window, so it only works if not more than one are open. In this case, the single block has the option to specify the title of the window.
Edge: With Microsoft Edge a login is not supported.
Firefox: Sends the credentials to a Firefox dialog box and therefore only works if there are not multiple ones.
Internet Explorer: With Internet Explorer a login is not supported.

As an additional option, you can also log in using the URL. Instead of the page https://www.example.com call the URL https://user:password@www.example.com. It is important that : and @ do not appear in the user name or password. This method may not be supported by every browser.

With the WindowsAutomation2-Plugin it is also possible to execute such a login with all browser types.

Transferring Old Selenium Tests[Bearbeiten]

This Plugin replaces the previous Selenium Web Test Plugin, which is based on Selenium RC. Selenium RC is no longer supported by their authors and it will also no longer be maintained by exept. The successor is Selenium WebDriver, also referred to as Selenium 2.

Recording of test actions using Selenim IDE is also outdated, as the plugin is not supported by newer browsers. The Selenium WebDriver Plugin uses its own Recorder instead.

Tests which were created with the old Selenium WebTest Plugin using SeleniumLibrary can be executed with the new Selenium WebDriver. For this, go to the plugin settings of "Webtest Legacy (Selenium)" and check "Use WebDriver for execution". Please verify that your tests are still running after this change, as there is no 100% backward compatibility (which is outside the scope of expecco). However, most of the old test actions should run without problems.

FAQ[Bearbeiten]

  • Scrollbars cannot be handled in the recorder
The scrollbar of the browser which is diplayed if a page is larger than the browser window is no controllable web element. Mostly it is useless to scroll by a certain amount in a test where the size of the browser window is not defined. Instead, use the block [Web] Scroll Element into View to scroll a relevant element to the visible region. The default click block used by the recorder already includes this action ([WebElement] Click (Scroll Element into View)). If you scroll on the recorder window, the action will also be applied to the browser, but is not recorded. If you actually want to scroll by a certain amount, there is an appropriate entry in the browser actions, and more blocks in the SeleniumWebDriverLibrary.
  • Block fails if element becomes visible too late
All blocks that use an element path have built in that they wait until a corresponding element appears. However, there are cases where an element is already there, but not yet visible. If you click on the element you will get an error. Possible errors in this context are org.openqa.selenium.ElementNotInteractableException: element not interactable and org.openqa.selenium.JavascriptException: javascript error: Cannot read property 'left' of undefined. In this case, use the [Web] Wait for Visibility of Element block or [Web] Wait for Element to Be Clickable before interacting with the element.
  • Error message Cannot read property 'left' of undefined
The error org.openqa.selenium.JavascriptException: javascript error: Cannot read property 'left' of undefined can occur with the Chrome browser. This means that the used element is not visible. See the point above on that. The error is also known in combination with elements in a dropdown list, i.e. when clicking or moving the mouse over a <option> element within a <select> element. Such elements are generally not clickable. Instead, use a suitable [Web] Select block with the <select> element.
  • Error message: Stale Element Reference Exception
The error org.openqa.selenium.StaleElementReferenceException occurs whenever a WebElement is used that is no longer there. If that happens during your test and the element should have been there, try using the locator instead to fetch the element again. Maybe the error occurs because the test is currently in a different frame context as the element. If you are using compound paths, the element should switch by itself to the correct context when it is used.
In rare cases this error can also occur in expecco itself, if at somewhere in the GUI browser or the recorder such a WebElement is used. You should then be able to abort and try again. Should the error persist, switch to the default content and refresh the tree in the GUI browser.
  • Block runs successfully, but without effect
This case can occur with Chrome. The element is available, the action does not throw an error, but nothing is executed. Usually it helps to wait briefly before the execution, see Execution Delay for Chrome.
  • Executions using Chrome are slower
To fix a problem when executing with Chrome, a delay is defined in the plugin settings for Chrome. Check if this value is possibly too high; see Execution Delay for Chrome.
  • Errors like: "org.openqa.selenium.InvalidArgumentException: Expected "handle" to be a string..."
This occurs if the driver does not match the browser (any more). Please read the above chapter "Update WebDriver".
  • Key Chords with Shortcuts are not working
Pressing keys simultaneously can be simulated using Key Chords. They can also be used to send shortcuts. However, not all inputs will work, as they are only sent to the page content, not to the browser itself. Combinations like Ctrl + t to open a new browser tab probably wont't work, Ctrl + a and Ctrl c on the other hand should be effective.
  • Additional Window Handles for Opera
The Opera browser returns more window handles as there are opened tabs or windows. They represent Opera internal features like Speed Dial or Better Address Bar Experience (BABE), which are embedded in the browser window, but not displayed like regular tabs. You can switch to these tabs using an appropriate action block, however not all actions are possible then, which can be used with the normal tabs. For example you cannot close them and they don't provide a screenshot. Therefore it is better to not even switch to their contexts. So be careful when switching to a tab by index, as the Opera tabs are among the others and the index might be a different one than for the other browser types.



Copyright © 2014-2024 eXept Software AG