Automation-Selenium Test Automation Framework
Automation-Selenium Test Automation Framework
FRAMEWORK(STAF)
SfaTest
Cucumber runs the feature files through JUnit, and needs a dedicated test
runner class to actually run the feature files.
@TestEnvironment(Environment.E2E)
@RunWith(CucumberWithSerenity.class)
@CucumberOptions(features="src/test/resources/features",tags={"@Test"})
public class CukesTest { }
# Options are firefox, chrome, iexplorer
webdriver.driver=firefox
# Below property is to wait for specific amount of time in milli seconds before timing
out
webdriver.timeouts.implicitlywait=10000
# Below property is to define when to take screenshots
# Other Screenshot options are FOR_EACH_ACTION,
BEFORE_AND_AFTER_EACH_STEP, AFTER_EACH_STEP
serenity.take.screenshots=FOR_FAILURES
SfaTools
• These steps implement the “how" behind the “what" of the Given-
When-Then" steps.
• Steps should not be overly complex, and should focus on working
at a single level of abstraction.
• Steps typically orchestrate calls to more technical layers such as
web services, databases, or WebDriver page objects.
• For example, in automated web tests, the step library methods do
not call WebDriver directly, but rather they typically interact
with Page Objects.
• Step libraries often use Page Objects, which are automatically
instantiated
• The @Step annotation indicates a method that will appear as a
step in the test reports.
• The @Step annotation helps taking screenshots according
serenity.property value
• @Step annotation resembles business actions.
17 Confidential / CenturyLink Employees and
Contractors Only
public class AccountSteps extends SfaSteps{
LoginPage loginPage;
CommercialAccountEditPage commercialAccountEditPage;
@Step
public void logs_in_as(String userType) {
loginPage.shouldExist(loginPage);
loginPage.enterCredentials(userType);
loginPage.btn_log_in_to_salesforce.click();
loginPage.WaitForPageToLoad(100);
}
@Step
public void create_commercial_account(String accountName) {
create_commercial_account(get_data_for_page(commercialAccountEditPage)
.getMandatoryFieldsFromAllContainers());
}
@Step
public boolean is_account_created(String accountName) {
boolean isOpen = false;
isOpen = is_account_open(accountName);
return isOpen;
}
}
@FindBy(id = "password")
public WebElementFacade tbx_password;
..continued
• Architecture of framework
• Project SfaTest
• Project SfaTools
• Runner Class/CukesTest.class.
• Feature.
• Step Definition.
• Serenity.property.
• Step library
• Page Objects
CommonData
• commonData Variable
• Values independent on environment
public List<IntContainerField> getFieldsFromAllContainers()
return list of all fields from all containers
public void removeFields(String... fieldNames)
removes multiple fields from container
public void removeFieldsFromAllContainers(String... fieldNames)
removes multiple fields from current and sub container
public void setActualValues()
sets the actual values of the fields
public void setActualValuesForAllContainers()
sets the actual values in current and sub-container
• Name
Name of the container should be same as Page Object Class
Name of the field should have a valid prefix
• Type
Mandatory
Blank
• Value
String
String with prefix
Keyword
There are various serenity methods available , however we will
extensively use the following-
serenity.setSessionVariable(Key).to(value)
It creates a session variable with the key provided as a parameter and also
assigns the value
serenity.sessionVariableCalled(Key)
It returns the value of the session variable with the name provided
serenity.sessionVariableCalled(Key).equals(String)
verifies if the value of the string is equal to the variable value