Skip to content

Neodymium context

Bernd Weigel edited this page Jun 10, 2024 · 26 revisions

The Neodymium context is a helper class that gives you handy access to certain useful methods and properties. In general all tests methods will be executed in a thread which has its own context. The context contains all test data as well as the used web driver, localization data and also an instance of NeodymiumConfiguration for this test method. This enables you to access and change settings and test data within a test for exactly that test without interferring other tests.

NOTE: In case you need to clear current thread context use Neodymium.clearThreadContext().

Data

If you need access to your test data you can use:

Neodymium.dataValue("<dataKey>")

Please see Test data provider for information and convenience methods for this topic.

Localization

The Neodymium class offers you access to our Localization feature by calling:

Neodymium.localizedText("<LocalizationKey>")

Configuration

The Neodymium class offers you access to the instantiated version of our NeodymiumConfiguration class. Now you can access every by setting by calling:

Neodymium.configuration().<settingFunctionName>()

WebDriver and browser

In case you need access to the current WebDriver. You can retrieve it by calling:

Neodymium.getDriver()

If you need EventFiringWebDriver instance of current WebDriver, please call the method below, it will make all casts for you

Neodymium.getEventFiringWebdriver()

For the case, when an instance of RemoteWebDriver, which is wrapped in current WebDriver, is needed, please use the method below, it will make all casts for you

Neodymium.getRemoteWebDriver()

If need to take special action because of the used browser profile you can retrieve the browser profile name by calling:

Neodymium.getBrowserProfileName()

If the used browser type requires special interactions you can retrieve the browser name (type) by calling:

Neodymium.getBrowserName()

If an embedded local proxy is used within the test. Its instance can be retrieved via the following method to utilize it for even more scenarios.

Neodymium.getLocalProxy()

The current state and the objects belonging to the current execution of the browser can be retrieved via following method. The retrieved WebDriverStateContainer contains the current WebDriver, the embedded loca BrowserUpProxy if used and a counter that state how often the current execution setup was used.

Neodymium.getWebDriverStateContainer()

Site

The Neodymium class offers a function to check if the current site matches given sites by calling:

Neodymium.isSite(String... sites)

If the current Site is UK this function returns true.

    // check against one site identifier 
    if (Neodymium.isSite("UK"))
    {
      return true;
    }

    // check against multiple site identifiers
    if (Neodymium.isSite("US", "DE", "JP"))
    {
      return true;
    }

Locale

To check the a locale or a list of locale against the currently configured locale, there is a method isLocale() in the Neodymium class, which can be used similar as isSite().

    // check against one locale
    if (Neodymium.isLocale("en_US"))
    {
      return true;
    }

    // check against multiple locale
    if (Neodymium.isLocale("en_US", "de_DE", "jp_JP"))
    {
      return true;
    }

Web site dimension

There are convenience functions that help to determine what's the current device is. Since website's are optimized for different devices categories today they might look different dependent on the device. So there is a need to distinguish the current look of the current site in order to use other or special locators for elements. Typically the browser window width will be used to determine how the web site appears. The following methods can be used within the test case to react on the currents browsers viewport width.

NOTE: These values are default values which can be configured in the file config/neodymium.properties

Function Description
boolean isExtraSmallDevice() true if 0 <= width < 576
boolean isSmallDevice() true if 576 <= width < 768
boolean isMediumDevice() true if 768 <= width < 992
boolean isLargeDevice() true if 992 <= width < 1200
boolean isExtraLargeDevice() true if width >= 1200
boolean isMobile() true if width < 768
boolean isTablet() true if 768 <= width < 992
boolean isDesktop() true if width >= 992

Furthermore you have a direct access to different function that help you to determine the size of the web site directly.

Function Description
Dimension getViewportSize() current viewport width and height packaged as Dimension object
Dimension getPageSize() current page width and height packaged as Dimension object
Dimension getWindowSize() current window width and height packaged as Dimension object

Version

The Neodymium version can be retrieved using the following function:

Neodymium.getNeodymiumVersion()

Fixed random support

Neodymium provides access to the current Random instance of Neodymium. This can be used to have a fixed random setup to repeat runs from CI executions.

Neodymium.getRandom()

Clone this wiki locally