Package com.privalia.qa.specs
Class HookGSpec
- java.lang.Object
-
- com.privalia.qa.specs.BaseGSpec
-
- com.privalia.qa.specs.HookGSpec
-
public class HookGSpec extends BaseGSpec
This class contains functions that are executed before and after each test. For this, it makes use of cucumber hooks- Author:
- Jose Fernandez
- See Also:
- https://cucumber.io/docs/cucumber/api/#hooks
-
-
Field Summary
Fields Modifier and Type Field Description protected org.openqa.selenium.WebDriver
driver
static int
IMPLICITLY_WAIT
static int
PAGE_LOAD_TIMEOUT
static int
SCRIPT_TIMEOUT
-
Fields inherited from class com.privalia.qa.specs.BaseGSpec
commonspec
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activateLogLevel(io.cucumber.java.Scenario scenario)
Changes the logging level of the log4j logger used in the specs package to the given valuevoid
addCapabilitiesFromFile(String filePath, org.openqa.selenium.MutableCapabilities capabilities)
void
AppiumSetup(io.cucumber.java.Scenario scenario)
If the feature has the @mobile annotation, creates a new Appium driver before each scenario.void
deactivateLogLevel()
Returns logging level back to default value (WARN)void
globalSetup(io.cucumber.java.Scenario scenario)
Clean the exception list before each scenario.void
ignoreTag(io.cucumber.java.Scenario scenario)
Skips an scenario/feature if it contains the @ignore tagvoid
runOnEnvTag(io.cucumber.java.Scenario scenario)
Allows conditional scenario execution using @skipOnEnv and @runOnEnv tagsvoid
seleniumSetup(io.cucumber.java.Scenario scenario)
If the feature has the @web annotation, creates a new selenium web driver before each scenario.void
seleniumTeardown(io.cucumber.java.Scenario scenario)
If the feature has the @web or @mobile annotation, closes selenium web driver after each scenario is completed.void
teardown(io.cucumber.java.Scenario scenario)
Checks if the scenario contains any reference to a Jira ticket and will try to update its status based on the result of the scenario execution.-
Methods inherited from class com.privalia.qa.specs.BaseGSpec
getCommonSpec
-
-
-
-
Field Detail
-
PAGE_LOAD_TIMEOUT
public static final int PAGE_LOAD_TIMEOUT
- See Also:
- Constant Field Values
-
IMPLICITLY_WAIT
public static final int IMPLICITLY_WAIT
- See Also:
- Constant Field Values
-
SCRIPT_TIMEOUT
public static final int SCRIPT_TIMEOUT
- See Also:
- Constant Field Values
-
driver
protected org.openqa.selenium.WebDriver driver
-
-
Constructor Detail
-
HookGSpec
public HookGSpec(CommonG spec)
Default constructor.- Parameters:
spec
- commonG object
-
-
Method Detail
-
globalSetup
public void globalSetup(io.cucumber.java.Scenario scenario)
Clean the exception list before each scenario.- Parameters:
scenario
- scenario reference
-
seleniumSetup
public void seleniumSetup(io.cucumber.java.Scenario scenario) throws Exception
If the feature has the @web annotation, creates a new selenium web driver before each scenario. This method allows the configuration of certain capabilities for the initialization of the driver, specifically, the ones used by selenium for browser selection: browserName, platform, version. These variables should be passed as VM arguments (-DbrowserName, -Dplatform, -Dversion). Additionally, then using a selenium grid (-DSELENIUM_GRID), the user can use the VM argument -DCAPABILITIES=/path/to/capabilities.json, to override the default capabilities with the ones from the json file- Parameters:
scenario
- Scenario- Throws:
MalformedURLException
- MalformedURLExceptionException
-
AppiumSetup
public void AppiumSetup(io.cucumber.java.Scenario scenario) throws IOException
If the feature has the @mobile annotation, creates a new Appium driver before each scenario. By default, the system will try to create a set of default capabilities for the driver. However, the user can set any of the general capabilities of Appium (i.e. -Dapp=/path/to/app, -DplatformName=android, etc). The user can use the VM argument -DCAPABILITIES=/path/to/capabilities.json, to override the default capabilities with the ones from the json file- Parameters:
scenario
- Scenario- Throws:
MalformedURLException
- MalformedURLExceptionIOException
-
addCapabilitiesFromFile
public void addCapabilitiesFromFile(String filePath, org.openqa.selenium.MutableCapabilities capabilities) throws IOException
- Throws:
IOException
-
seleniumTeardown
public void seleniumTeardown(io.cucumber.java.Scenario scenario)
If the feature has the @web or @mobile annotation, closes selenium web driver after each scenario is completed.- Parameters:
scenario
- Instance of the scenario just executed
-
teardown
public void teardown(io.cucumber.java.Scenario scenario) throws com.slack.api.methods.SlackApiException, IOException, SQLException
Checks if the scenario contains any reference to a Jira ticket and will try to update its status based on the result of the scenario execution. Checks if there's any reference to a Slack channel and sends a notification to that channel if the scenario failed Closes any remaining SSH connection- Parameters:
scenario
- Scenario- Throws:
com.slack.api.methods.SlackApiException
- SlackApiExceptionIOException
- IOExceptionSQLException
- SQLException
-
activateLogLevel
public void activateLogLevel(io.cucumber.java.Scenario scenario)
Changes the logging level of the log4j logger used in the specs package to the given value- Parameters:
scenario
- Scenario
-
deactivateLogLevel
public void deactivateLogLevel()
Returns logging level back to default value (WARN)
-
ignoreTag
public void ignoreTag(io.cucumber.java.Scenario scenario)
Skips an scenario/feature if it contains the @ignore tag- Parameters:
scenario
- Scenario
-
runOnEnvTag
public void runOnEnvTag(io.cucumber.java.Scenario scenario) throws Exception
Allows conditional scenario execution using @skipOnEnv and @runOnEnv tags\@runOnEnv(param1,param2,param3,..): The scenario will only be executed if ALL the params are defined. \@skipOnEnv(param1,param2,param3,..) The scenario will be omitted if ANY of params are defined.
- Parameters:
scenario
- Scenario- Throws:
Exception
- Exception
-
-