Skip to content

Commit

Permalink
Updated external parameter/property fetch function.
Browse files Browse the repository at this point in the history
  • Loading branch information
ansonliao committed Nov 30, 2017
1 parent 1152e99 commit 6a7ddf6
Show file tree
Hide file tree
Showing 19 changed files with 177 additions and 65 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Add the below dependencies in your `pom.xml` (Master)
<dependency>
<groupId>com.github.ansonliao</groupId>
<artifactId>Selenium-Extensions</artifactId>
<version>2.3.0-SNAPSHOT</version>
<version>2.3.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.github.ansonliao</groupId>
<artifactId>Selenium-Extensions</artifactId>
<version>2.3.0-SNAPSHOT</version>
<version>2.3.0</version>
<packaging>jar</packaging>

<name>Selenium-Extensions</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.ansonliao.selenium.factory;

import com.github.ansonliao.selenium.utils.SEFilterUtils;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
Expand Down Expand Up @@ -36,7 +37,7 @@ public WebDriver getDriver() {

@Override
public String getExportParameterKey() {
return "webdriver.chrome.driver";
return SEFilterUtils.getChromeDriverExportKey();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.ansonliao.selenium.factory;

import com.github.ansonliao.selenium.utils.SEFilterUtils;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.slf4j.Logger;
Expand All @@ -26,7 +27,7 @@ public WebDriver getDriver() {

@Override
public String getExportParameterKey() {
return "webdriver.edge.driver";
return SEFilterUtils.getEdgeDriverExportKey();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.ansonliao.selenium.factory;

import com.github.ansonliao.selenium.utils.SEFilterUtils;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
Expand Down Expand Up @@ -38,7 +39,7 @@ public WebDriver getDriver() {

@Override
public String getExportParameterKey() {
return "webdriver.gecko.driver";
return SEFilterUtils.getFirefoxDriverExportKey();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.ansonliao.selenium.factory;

import com.github.ansonliao.selenium.utils.SEFilterUtils;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.slf4j.Logger;
Expand All @@ -26,7 +27,7 @@ public WebDriver getDriver() {

@Override
public String getExportParameterKey() {
return "webdriver.ie.driver";
return SEFilterUtils.getIEDriverExportKey();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.ansonliao.selenium.factory;

import com.github.ansonliao.selenium.utils.SEFilterUtils;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.opera.OperaDriver;
import org.slf4j.Logger;
Expand All @@ -26,7 +27,7 @@ public WebDriver getDriver() {

@Override
public String getExportParameterKey() {
return "webdriver.opera.driver";
return SEFilterUtils.getOperaDriverExportKey();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.ansonliao.selenium.factory;

import com.github.ansonliao.selenium.utils.SEFilterUtils;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.slf4j.Logger;
Expand All @@ -26,7 +27,7 @@ public WebDriver getDriver() {

@Override
public String getExportParameterKey() {
return "phantomjs.binary.path";
return SEFilterUtils.getPhantomJsDriverExportKey();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import com.github.ansonliao.selenium.annotations.URL;
import com.github.ansonliao.selenium.factory.DriverManagerFactory;
import com.github.ansonliao.selenium.factory.WDManager;
import com.github.ansonliao.selenium.internal.Constants;
import com.github.ansonliao.selenium.report.factory.ExtentTestManager;
import com.github.ansonliao.selenium.utils.AuthorUtils;
import com.github.ansonliao.selenium.utils.MyFileUtils;
import com.github.ansonliao.selenium.utils.SEConfig;
import com.github.ansonliao.selenium.utils.SEFilterUtils;
import com.github.ansonliao.selenium.utils.TestGroupUtils;
import com.github.ansonliao.selenium.utils.WDMHelper;
import com.google.common.base.Strings;
Expand Down Expand Up @@ -44,7 +43,7 @@ public void beforeInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestRes
iInvokedMethod.getTestMethod().getConstructorOrMethod().getMethod();

List<String> groups = TestGroupUtils.getMethodTestGroups(method);
if (SEConfig.getBoolean("addBrowserGroupToReport")) {
if (SEFilterUtils.addBrowserGroupToReport()) {
groups.add(browserName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
import com.github.ansonliao.selenium.annotations.Description;
import com.google.common.collect.Maps;
import org.testng.Reporter;
import org.testng.annotations.Test;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public class ExtentTestManager {
public static ThreadLocal<ExtentTest> extentTests = new ThreadLocal<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.github.ansonliao.selenium.testng;

import com.github.ansonliao.selenium.internal.Variables;
import com.github.ansonliao.selenium.parallel.ClassFinder;
import com.github.ansonliao.selenium.parallel.MethodFinder;
import com.github.ansonliao.selenium.utils.BrowserUtils;
import com.github.ansonliao.selenium.utils.SEConfig;
import com.google.common.base.Strings;
import com.github.ansonliao.selenium.utils.SEFilterUtils;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
Expand All @@ -16,7 +14,6 @@

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
Expand All @@ -28,11 +25,10 @@ public class TestNGFilter {
private static final Logger logger = LoggerFactory.getLogger(TestNGFilter.class);
private static List<Class<?>> testngClasses = Lists.newArrayList();
private static Multimap<Class<?>, Method> testNGClass2MethodMap = HashMultimap.create();
private static final String EXTERNAL_RUN_BROWSER_KEY = "runByBrowsers";

static {
String[] testingPackageNames = Variables.TESTING_PACKAGE_NAMES.toArray(
new String[Variables.TESTING_PACKAGE_NAMES.size()]);
String[] testingPackageNames = SEFilterUtils.testingPackageNames().toArray(
new String[SEFilterUtils.testingPackageNames().size()]);
testngClasses = ClassFinder.findAllTestNGTestClasses(testingPackageNames);
}

Expand All @@ -45,10 +41,10 @@ public static Map<String, Map<Class<?>, List<Method>>> run() {

// filter testng classes by given testng class list
public static List<Class<?>> filterClassesByTestingClassList() {
if (!Variables.TESTING_TESTNG_CLASSES.isEmpty()) {
if (!SEFilterUtils.testingTestNGClasses().isEmpty()) {
return testngClasses.parallelStream()
.filter(aClass ->
Variables.TESTING_TESTNG_CLASSES
SEFilterUtils.testingTestNGClasses()
.parallelStream()
.map(String::toUpperCase)
.collect(Collectors.toList())
Expand All @@ -66,7 +62,7 @@ public static List<Class<?>> filterClassesByTestingClassList() {
*/
public static Multimap<Class<?>, Method> filterTestNGMethodByTestGroups() {
testNGClass2MethodMap = HashMultimap.create();
if (Strings.isNullOrEmpty(SEConfig.getString("testingTestGroups"))) {
if (SEFilterUtils.testingTestGroups().isEmpty()) {
testngClasses.stream()
.forEach(aClass ->
MethodFinder.findAllAnnotatedTestMethodInClass(aClass).stream()
Expand All @@ -76,12 +72,8 @@ public static Multimap<Class<?>, Method> filterTestNGMethodByTestGroups() {
return testNGClass2MethodMap;
}

Variables.TESTING_TEST_GROUPS =
Arrays.stream(SEConfig.getString("testingTestGroups").split(","))
.map(String::trim).collect(Collectors.toList());

testngClasses.stream().forEach(aClass -> {
List<Method> methodList = Variables.TESTING_TEST_GROUPS
List<Method> methodList = SEFilterUtils.testingTestGroups()
.parallelStream()
.map(group -> MethodFinder.findTestNGMethodInClassByGroup(aClass, group))
.flatMap(Collection::stream)
Expand All @@ -98,12 +90,12 @@ public static Multimap<Class<?>, Method> filterTestNGMethodByTestGroups() {

// filter testng method by given test browser list
public static Multimap<Class<?>, Method> filterTestNGMethodByBrowsers() {
if (!Variables.TESTING_BROWSER_NAMES.isEmpty()) {
if (!SEFilterUtils.testingBrowserNames().isEmpty()) {
testNGClass2MethodMap.keySet().parallelStream().forEach(aClass ->
testNGClass2MethodMap.get(aClass).stream().forEach(method -> {
Sets.SetView result = Sets.intersection(
BrowserUtils.getMethodSupportedBrowsers(method),
Sets.newHashSet(Variables.TESTING_BROWSER_NAMES));
Sets.newHashSet(SEFilterUtils.testingBrowserNames()));
if (result.size() == 0) {
if (testNGClass2MethodMap.get(aClass).contains(method)) {
testNGClass2MethodMap.get(aClass).remove(method);
Expand All @@ -119,12 +111,11 @@ public static Map<String, Map<Class<?>, List<Method>>> getBrowser2TestNGClass2Te
Map<String, Map<Class<?>, List<Method>>> browserTestingMap = new HashMap<>();
Multimap<String, Method> browserTestngMethodMap = HashMultimap.create();

if (!Strings.isNullOrEmpty(SEConfig.getString(EXTERNAL_RUN_BROWSER_KEY))) {
if (!SEFilterUtils.runByBrowsers().isEmpty()) {
// only fetch support browsers
List<String> browsers =
Sets.intersection(
Arrays.stream(SEConfig.getString(EXTERNAL_RUN_BROWSER_KEY).split(","))
.map(String::trim).collect(Collectors.toSet()),
SEFilterUtils.runByBrowsers().stream().collect(Collectors.toSet()),
Sets.newHashSet(BrowserUtils.getSupportedBrowsers()))
.parallelStream().collect(Collectors.toList());

Expand Down Expand Up @@ -185,7 +176,7 @@ public static Map<String, Map<Class<?>, List<Method>>> getBrowser2TestNGClass2Te
}

private static Set<String> addIncludedDefaultBrowser(Method method) {
String DEFAULT_BROWSER_TYPE_NAME = Variables.DEFAULT_BROWSER_TYPE_NAME.trim().toUpperCase();
String DEFAULT_BROWSER_TYPE_NAME = SEFilterUtils.defaultBrowser().toUpperCase();
Set<String> methodSupportedBrowsers = BrowserUtils.getMethodSupportedBrowsers(method);
Set<String> methodBrowsers = BrowserUtils.getMethodBrowsers(method);
Set<String> ignoreBrowsers = BrowserUtils.getMethodIgnoredBrowsers(method);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.ansonliao.selenium.testng;

import com.github.ansonliao.selenium.internal.Constants;
import com.github.ansonliao.selenium.internal.Variables;
import com.github.ansonliao.selenium.utils.SEFilterUtils;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
Expand All @@ -20,13 +20,13 @@ public class XmlTestBuilder {
public static List<XmlTest> build() {
Set<XmlTest> xmlTestList = Sets.newHashSet();
Multimap<String, XmlClass> browserXmlclassMap = XmlClassBuilder.build();
final int DEFAULT_TEST_CLASS_SIZE = Variables.DEFAULT_TEST_CLASS_SIZE_OF_TESTNG_XML;
final int DEFAULT_TEST_CLASS_SIZE = SEFilterUtils.defaultTestClassesSizeOfTestNGXML();

browserXmlclassMap.keySet().forEach(browserName -> {
List<XmlClass> xmlClassList = browserXmlclassMap.get(browserName)
.stream().distinct().collect(Collectors.toList());
ArrayList<XmlClass> tempXmlClass = Lists.newArrayList(xmlClassList);
int xmlClassGroupSize = xmlClassList.size() / Variables.DEFAULT_TEST_CLASS_SIZE_OF_TESTNG_XML + 1;
int xmlClassGroupSize = xmlClassList.size() / SEFilterUtils.defaultTestClassesSizeOfTestNGXML() + 1;
int counter = xmlClassGroupSize;

int startIndex = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@

public class AuthorUtils {
private static final Logger logger = LoggerFactory.getLogger(AuthorUtils.class);
private static JavaProjectBuilder javaProjectBuilder;
private static JavaProjectBuilder javaProjectBuilder = new JavaProjectBuilder();

static {
javaProjectBuilder = new JavaProjectBuilder();
javaProjectBuilder.addSourceTree(new File(
Constants.PROJECT_ROOT_DIR
.concat(Constants.FILE_SEPARATOR)
Expand All @@ -39,7 +38,7 @@ public synchronized static List<String> getMethodAuthors(Method method) {

// get class authors
getClassAuthors(clazz)
.ifPresent(authorList -> classAuthors.addAll(authorList));
.ifPresent(classAuthors::addAll);

// get method authors
javaProjectBuilder.getClassByName(className).getMethods().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public static List<String> getSupportedBrowsers() {
.filter(className ->
className.startsWith(Constants.BROWSER_ANNOTATION_PACKAGE))
.map(ClassFinder::createClass)
.filter(aClass -> aClass.isAnnotation())
//.filter(aClass -> aClass.isAnnotation())
.filter(Class::isAnnotation)
.map(aClass -> aClass.getSimpleName().toUpperCase())
.filter(className ->
!className.startsWith(Constants.BROWSER_IGNORE_ANNOTATION_PREFIX))
Expand All @@ -37,7 +38,8 @@ public static List<String> getSupportedIgnoreBrowsers() {
.filter(className ->
className.startsWith(Constants.BROWSER_ANNOTATION_PACKAGE))
.map(ClassFinder::createClass)
.filter(aClass -> aClass.isAnnotation())
//.filter(aClass -> aClass.isAnnotation())
.filter(Class::isAnnotation)
.map(aClass -> aClass.getSimpleName().toUpperCase())
.filter(className ->
className.startsWith(Constants.BROWSER_IGNORE_ANNOTATION_PREFIX))
Expand Down Expand Up @@ -82,7 +84,9 @@ public static Set<String> getMethodSupportedBrowsers(Class<?> clazz, Method meth
enabledBrowsers = Sets.union(classSupportedBrowsers, enabledBrowsers);
ignoredBrowsers = Sets.union(classIgnoredBrowsers, ignoredBrowsers);

return Sets.difference(enabledBrowsers, Sets.intersection(enabledBrowsers, ignoredBrowsers))
return Sets.difference(
enabledBrowsers,
Sets.intersection(enabledBrowsers, ignoredBrowsers))
.parallelStream().collect(Collectors.toSet());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import com.github.ansonliao.selenium.internal.Constants;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

public class MyFileUtils extends FileUtils {
private static final Logger logger = LoggerFactory.getLogger(MyFileUtils.class);

public static synchronized File createScreenshotFolderForBrowser(
Class clazz, String browserName) {
Expand All @@ -19,6 +22,7 @@ public static synchronized File createScreenshotFolderForBrowser(
return new File(destDir);
}

logger.info("Create screenshot directory: {}", destDir);
new File(destDir).mkdirs();
return new File(destDir);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public static String getString(String key) {
}

}
return value;
return value.contains("\"") || value.contains("'")
? value.replace("\"", "").replace("'", "")
: value;
}

public static int getInt(String key) {
Expand Down
Loading

0 comments on commit 6a7ddf6

Please sign in to comment.