[Feature] Add global property "BASE_LAUNCH_URL" to avoid each write the navigation base url in test case frequently
ansonliao opened this issue · comments
Add global property "BASE_LAUNCH_URL" to avoid each write the navigation base url in test case frequently
Hi @ansonliao can you please elaborate this feature. I really wanted to commit to this repo, as I liked this one very much and I need your help in understanding the requirement so that I can try to implement
Hi @saicharan2311 , will implement it soon.
Hi @saicharan2311 , actually, you can add this feature by adding your customise listener to implement in your testing project, for example:
- Extends the default listener
SeleniumParallelTestListener.java
public class Your_Test_Listener extends SeleniumParallelTestListener {
@Override
public void beforeInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) {
String browserName = iInvokedMethod.getTestMethod().getXmlTest()
.getParameter(getConfigInstance().testngXmlBrowserParamKey());
Method method =
iInvokedMethod.getTestMethod().getConstructorOrMethod().getMethod();
DriverManager driverManager =
DriverManagerFactory.getManager(browserName);
driverManager.setHeadless(method.isAnnotationPresent(Headless.class));
driverManager.setIncognito(method.isAnnotationPresent(Incognito.class));
setDriver(driverManager.getDriver());
List<String> groups = TestGroupUtils.getMethodTestGroups(method);
if (getConfigInstance().addBrowserGroupToReport()) {
groups.add(browserName);
}
ExtentTestManager.createTest(
method, browserName, AuthorUtils.getMethodAuthors(method),
groups, iTestResult.getParameters());
// check the global property BASE_LAUNCH_URL whether existed or not, if existed, open it
if (Strings.isNotNullOrNotEmpty(SEConfig.getInstance.getString("BASE_LAUNCH_URL"))) {
getDriver(SEConfig.getInstance.getString("BASE_LAUNCH_URL"));
}
}
}
- Then add your customise listener to the configuration file
seleniumextensions.properties
to let it effected. Add your customise listener to the propertytestngListeners
, and replace the default listenercom.github.ansonliao.selenium.parallel.SeleniumParallelTestListener
with your customise listenerThe_Package_Your_Test_Listener
, so the listeners properties of configuration file looks like:
testngListeners=YOUR_PACKAGE_YOUR_TEST_LISTENER,
com.github.ansonliao.selenium.testng.TestResultListener
defaultTestNGListeners=com.github.ansonliao.selenium.testng.TestResultListener,
com.github.ansonliao.selenium.parallel.SeleniumParallelTestListener
- Added property
BASE_LAUNCH_URL
to the configurationseleniumextensions.properties
, and then set the value to the property;
Or even you don't need to add the propertyBASE_LAUNCH_URL
to the configuration file, and passed the propertyBASE_LAUNCH_URL
by the maven command line.
so far you added the global property BASE_LAUNCH_URL
feature to your testing project.