Skip to content

Commit

Permalink
- Additional method for #19 in StepExecutionTracker. In addition to
Browse files Browse the repository at this point in the history
`getStepCompositer()` which returns `TestStepCompositer` new method
added `getScenario` which will return `TestNGScenario`.

- added constants in application keys for current test related keys.
  • Loading branch information
cjayswal committed Oct 24, 2016
1 parent 2f7c1b3 commit 9022013
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 173 deletions.
6 changes: 2 additions & 4 deletions src/com/qmetry/qaf/automation/core/QAFTestBase.java
Expand Up @@ -44,7 +44,6 @@
import com.qmetry.qaf.automation.keys.ApplicationProperties;
import com.qmetry.qaf.automation.ui.UiDriver;
import com.qmetry.qaf.automation.ui.UiDriverFactory;
import com.qmetry.qaf.automation.ui.WebDriverTestBase;
import com.qmetry.qaf.automation.ui.util.ExpectedCondition;
import com.qmetry.qaf.automation.util.FileUtil;
import com.qmetry.qaf.automation.util.PropertyUtil;
Expand Down Expand Up @@ -193,7 +192,7 @@ public boolean isPrepareForShutdown() {
}

public void setMethod(Method method) {
ConfigurationManager.getBundle().addProperty("current.testcase.name",
ConfigurationManager.getBundle().addProperty(ApplicationProperties.CURRENT_TEST_NAME.key,
method.getName());
}

Expand Down Expand Up @@ -351,8 +350,7 @@ protected boolean isAlwaysCaptureScreenShot() {
}

protected String getTestCaseName() {
return ConfigurationManager.getBundle().getString("current.testcase.name",
"QAFTest");
return ApplicationProperties.CURRENT_TEST_NAME.getStringVal("QAFTest");
}

protected void setScreenShotDir(String screenShotDir) {
Expand Down
33 changes: 33 additions & 0 deletions src/com/qmetry/qaf/automation/keys/ApplicationProperties.java
Expand Up @@ -26,6 +26,8 @@

import org.apache.commons.lang.StringUtils;
import org.testng.IRetryAnalyzer;
import org.testng.ITestContext;
import org.testng.ITestResult;

import com.qmetry.qaf.automation.core.ConfigurationManager;
import com.qmetry.qaf.automation.data.BaseDataBean;
Expand Down Expand Up @@ -79,6 +81,32 @@ public enum ApplicationProperties {
* <b>value</b>: flag to auto shutdown selenium server
*/
SELENIUM_AUTO_SHUTDOWN("selenium.auto.shutdown"),

/**
* <b>key</b>: <code> tng.context </code><br/>
* <b>value</b>: {@link ITestContext} object for current running thread/test-case.
*
*/
CURRENT_TEST_CONTEXT("tng.context"),
/**
* <b>key</b>: <code> current.testcase.name </code><br/>
* <b>value</b>: name of the current running test case.
*
*/
CURRENT_TEST_NAME("current.testcase.name"),
/**
* <b>key</b>: <code> current.testcase.desc </code><br/>
* <b>value</b>: description of the current running test case.
*
*/
CURRENT_TEST_DESCRIPTION("current.testcase.desc"),
/**
* <b>key</b>: <code> current.testcase.result </code><br/>
* <b>value</b>: {@link ITestResult} object for the current running test case.
*
* @since 2.1.9
*/
CURRENT_TEST_RESULT("current.testcase.result"),
/**
* <b>key</b>: <code> driver.name </code><br/>
* <b>value</b>: driver to be used, for instance firefoxDriver or
Expand Down Expand Up @@ -515,4 +543,9 @@ public boolean getBoolenVal(boolean... defaultVal) {
}
return (null != defaultVal) && (defaultVal.length > 0) && defaultVal[0];
}

public Object getObject(Object... defaultVal){
Object objToReturn = ConfigurationManager.getBundle().getObject(key);
return null!=objToReturn? objToReturn:(null != defaultVal) && (defaultVal.length > 0) ?defaultVal[0]:null;
}
}
7 changes: 4 additions & 3 deletions src/com/qmetry/qaf/automation/step/JavaStep.java
Expand Up @@ -45,7 +45,6 @@

import org.apache.commons.lang.text.StrSubstitutor;
import org.json.JSONException;
import org.openqa.selenium.WebElement;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand Down Expand Up @@ -280,7 +279,8 @@ public void getSubSteps() {
private Object getClassInstance()
throws InstantiationException, IllegalAccessException {
Class<?> cls = method.getDeclaringClass();
if (getBundle().getBoolean("step.provider.sharedinstance", false) && isSharableInstance(cls)) {
if (getBundle().getBoolean("step.provider.sharedinstance", false)
&& isSharableInstance(cls)) {
// allow class variable sharing among steps
Object obj = getBundle().getObject(cls.getName());
if (null == obj) {
Expand All @@ -294,7 +294,8 @@ private Object getClassInstance()

private boolean isSharableInstance(Class<?> cls) {

if (TestPage.class.isAssignableFrom(cls) || WebElement.class.isAssignableFrom(cls)) {
if (TestPage.class.isAssignableFrom(cls)
|| QAFWebElement.class.isAssignableFrom(cls)) {
return false;
}
return true;
Expand Down
60 changes: 42 additions & 18 deletions src/com/qmetry/qaf/automation/step/StepExecutionTracker.java
@@ -1,33 +1,42 @@
/*******************************************************************************
* QMetry Automation Framework provides a powerful and versatile platform to author
* Automated Test Cases in Behavior Driven, Keyword Driven or Code Driven approach
*
* QMetry Automation Framework provides a powerful and versatile platform to
* author
* Automated Test Cases in Behavior Driven, Keyword Driven or Code Driven
* approach
* Copyright 2016 Infostretch Corporation
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
* OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
*
* You should have received a copy of the GNU General Public License along with this program in the name of LICENSE.txt in the root folder of the distribution. If not, see https://opensource.org/licenses/gpl-3.0.html
*
* See the NOTICE.TXT file in root folder of this source files distribution
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT
* OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
* You should have received a copy of the GNU General Public License along with
* this program in the name of LICENSE.txt in the root folder of the
* distribution. If not, see https://opensource.org/licenses/gpl-3.0.html
* See the NOTICE.TXT file in root folder of this source files distribution
* for additional information regarding copyright ownership and licenses
* of other open source software / files used by QMetry Automation Framework.
*
* For any inquiry or need additional information, please contact support-qaf@infostretch.com
* For any inquiry or need additional information, please contact
* support-qaf@infostretch.com
*******************************************************************************/


package com.qmetry.qaf.automation.step;

import java.util.HashMap;
import java.util.Map;

import org.testng.ITestResult;

import com.qmetry.qaf.automation.core.ConfigurationManager;
import com.qmetry.qaf.automation.keys.ApplicationProperties;
import com.qmetry.qaf.automation.step.client.TestNGScenario;

/**
* com.qmetry.qaf.automation.step.StepExecutionContext.java
Expand Down Expand Up @@ -174,4 +183,19 @@ public void setVerificationError(String verificationError) {
this.verificationError = verificationError;
}

/**
* This is utility method and will return {@link TestNGScenario} for which
* current step invoked or null if not found reference.
*
* @return
*/
public TestNGScenario getScenario() {
ITestResult result =
(ITestResult) ApplicationProperties.CURRENT_TEST_RESULT.getObject();
if (result != null) {
return ((TestNGScenario) result.getMethod());
}
return null;
}

}
5 changes: 3 additions & 2 deletions src/com/qmetry/qaf/automation/step/client/Scenario.java
Expand Up @@ -39,6 +39,7 @@
import com.qmetry.qaf.automation.core.MessageTypes;
import com.qmetry.qaf.automation.core.QAFTestBase;
import com.qmetry.qaf.automation.core.TestBaseProvider;
import com.qmetry.qaf.automation.keys.ApplicationProperties;
import com.qmetry.qaf.automation.step.StepExecutionTracker;
import com.qmetry.qaf.automation.step.StepNotFoundException;
import com.qmetry.qaf.automation.step.StringTestStep;
Expand Down Expand Up @@ -238,8 +239,8 @@ public boolean isM_enabled() {
protected void beforeScanario() {
status = "NOTRUN";
logger.info("\n\nExecuting scenario: " + scenarioName + " - " + description);
getBundle().setProperty("current.testcase.name", scenarioName);
getBundle().setProperty("current.testcase.desc", description);
getBundle().setProperty(ApplicationProperties.CURRENT_TEST_NAME.key, scenarioName);
getBundle().setProperty(ApplicationProperties.CURRENT_TEST_DESCRIPTION.key, description);
}

public String getSignature() {
Expand Down

0 comments on commit 9022013

Please sign in to comment.