All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nordstrom.automation.selenium.examples.QuickStart Maven / Gradle / Ivy

Go to download

Selenium Foundation is an automation framework designed to extend and enhance the capabilities provided by Selenium (WebDriver).

There is a newer version: 28.3.1-s4
Show newest version
package com.nordstrom.automation.selenium.examples;

import static org.testng.Assert.assertEquals;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;

import com.github.sbabcoc.logback.testng.ReporterAppender;
import com.nordstrom.automation.selenium.annotations.InitialPage;
import com.nordstrom.automation.selenium.core.DriverManager;
import com.nordstrom.automation.selenium.support.TestNgBase;
import com.nordstrom.automation.testng.ExecutionFlowController;
import com.nordstrom.automation.testng.LinkedListeners;
import com.nordstrom.automation.testng.ListenerChain;
import com.nordstrom.automation.selenium.SeleniumConfig;
import com.nordstrom.automation.selenium.AbstractSeleniumConfig.SeleniumSettings;

/**
 * INTRODUCTION
 * 

* Selenium Foundation is an automation framework designed to extend and enhance the capabilities provided * by Selenium WebDriver. *

* This QuickStart class provides a fully-functional example of a test class built around Selenium * Foundation, TestNG Foundation, and the Settings API. It demonstrates how to set up required * elements and introduces several key features that you're likely to use on a regular basis. *

* REQUIRED ELEMENTS *

    *
  • {@link ListenerChain}:
    * ListenerChain is a TestNG listener that enables you to add other listeners at runtime and guarantees the * order in which they're invoked. This is similar in behavior to a JUnit rule chain.
  • *
  • The {@link LinkedListeners} annotation:
    * To attach listeners to an active ListenerChain, mark your test class with the LinkedListeners * annotation. QuickStart extends {@link TestNgBase}, which is marked with a LinkedListeners * annotation that specifies two listeners that manage several core features of Selenium Foundation:
      *
    • {@link DriverManager}:
      * DriverManager is a TestNG listener that manages driver sessions and local Selenium Grid servers.
    • *
    • {@link ExecutionFlowController}:
      * ExecutionFlowController is a TestNG listener that propagates test context attributes:
      * [before method] → [test method] → [after method]
    *
  • *
*

* DEMONSTRATED FEATURES *

    *
  • {@link InitialPage}:
    * InitialPage is a Java annotation that enables you to specify the initial page class and/or URL that * should be loaded at the start of the test method. This can be applied to each test individually, or it can * be applied at the class level to specify the default page for all test in the class. It can also be applied * to @Before... configuration methods to provide driver sessions opened to the desired page.
  • *
  • {@link SeleniumConfig}:
    * SeleniumConfig declares settings and methods related to Selenium WebDriver and Grid configuration. * This class is built on the Settings API, composed of defaults, stored values, and System properties.
  • *
  • {@link SeleniumSettings}:
    * SeleniumSettings declares the constants, property names, and default values for the settings managed * by SeleniumConfig. Defaults can be overridden via System properties or the settings.propeties * file in your user "home" directory. See ESSENTIAL SETTINGS below for more details.
  • *
  • {@link ReporterAppender}:
    * ReporterAppender is a Logback appender for TestNG Reporter. The Selenium Foundation project * ships with a logback.xml file that attaches this appender. See the complete logback-testng README * page here.
  • *
*

* ESSENTIAL SETTINGS *

* You'll probably find that the defaults assigned to most settings will suffice in most basic scenarios. However, it's * likely that you'll need to override one or more of the following. The Property Name column indicates the name * of the System property associated with the setting. To override a setting, you can either add a line for the setting * to your settings.properties file or define a System property. * *

* * * * * * * * * * * * * * * * * * * * * *
Essential Settings
ConstantProperty NameDefault
{@link SeleniumSettings#BROWSER_NAME BROWSER_NAME}selenium.browser.name(none) *
{@link SeleniumSettings#TARGET_HOST TARGET_HOST}selenium.target.hostlocalhost
{@link SeleniumSettings#TARGET_PATH TARGET_PATH}selenium.target.path/
*

* * NOTE: By default, no target browser is selected. Either {@link SeleniumSettings#BROWSER_NAME BROWSER_NAME} * or {@link SeleniumSettings#BROWSER_CAPS BROWSER_CAPS} must be specified for this test to run. * For details, see Configuring Project * Settings * . *

* OVERRIDING DEFAULTS *

* SeleniumConfig searches a series of locations for a settings.properties file. This file will typically * be stored in your user "home" folder. Any settings declared in this file will override the defaults assigned in the * SeleniumSettings enumeration. Settings that are declared as System properties will override both the defaults * assigned by SeleniumSettings and settings declared in settings.properties. For example: * *

* * * * * * * * * * *
settings.properties
settings.properties
selenium.target.host=my.server.com
selenium.browser.name=chrome
*

* This sample settings.properties file overrides the values of {@link SeleniumSettings#TARGET_HOST TARGET_HOST} * and {@link SeleniumSettings#BROWSER_NAME BROWSER_NAME}. The latter can be overridden by System property declaration: * *

{@code -Dselenium.browser.name=firefox}
*

* The hierarchy of evaluation produces the following results: * *

* BROWSER_NAME = firefox; * TARGET_HOST = my.server.com; * TARGET_PATH = / *
*

* INSTALLING DRIVERS *

* Whichever browser you choose to run your automation on, you need to make sure to install the latest driver for that * browser compatible with your chosen version of Selenium WebDriver, along with a compatible release of the * browser itself. We recommend that you install the drivers and browsers on the file search path to avoid the need to * provide additional configuration details via scenario-specific means. *

* Here are the official homes for several of the major drivers:

* NOTE: GhostDriver and ChromeDriver are simple binary installations, but several system configuration changes * must be applied for IEDriver to work properly. For details, visit the InternetExplorerDriver project Wiki on GitHub * and follow the * Required Configuration procedure. */ @InitialPage(ExamplePage.class) public class QuickStart extends TestNgRoot { private static final String PAGE_TITLE = "Example Page"; private static final Logger LOGGER = LoggerFactory.getLogger(QuickStart.class); @Test public void dummyTest() { SeleniumConfig config = SeleniumConfig.getConfig(); LOGGER.info("The configured browser is: " + config.getCurrentCapabilities().getBrowserName()); ExamplePage examplePage = (ExamplePage) getInitialPage(); assertEquals(examplePage.getTitle(), PAGE_TITLE, "Unexpected page title"); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy