diff --git a/bzt/modules/java/executors.py b/bzt/modules/java/executors.py index 718af253b4..d6338812be 100644 --- a/bzt/modules/java/executors.py +++ b/bzt/modules/java/executors.py @@ -23,7 +23,7 @@ from bzt.modules.functional import FuncSamplesReader from bzt.modules.jmeter import JTLReader from bzt.utils import get_full_path, shell_exec, TclLibrary, JavaVM, BetterDict, get_assembled_value -from .tools import SeleniumServer, Hamcrest, Json, TaurusJavaHelper, JavaC, JUnitJupiterApi, JUnitJupiterEngine +from .tools import Hamcrest, Json, TaurusJavaHelper, JavaC, JUnitJupiterApi, JUnitJupiterEngine from .tools import JUnitPlatformCommons, JUnitPlatformLauncher, JUnitPlatformEngine, JUnitPlatformRunner from .tools import JUnitPlatformSuiteApi, JUnitVintageEngine, ApiGuardian, JUnit, OpenTest4j, TestNG @@ -46,7 +46,6 @@ def __init__(self): self.report_file_suffix = ".ldjson" def install_required_tools(self): - self._add_jar_tool(SeleniumServer, config=self.settings.get("selenium-server")) self._add_jar_tool(Hamcrest, config=self.settings.get("hamcrest-core")) self._add_jar_tool(Json, config=self.settings.get("json-jar")) self._add_jar_tool(TaurusJavaHelper) diff --git a/bzt/modules/java/tools.py b/bzt/modules/java/tools.py index 6d59918770..1c0fee570b 100644 --- a/bzt/modules/java/tools.py +++ b/bzt/modules/java/tools.py @@ -76,55 +76,6 @@ def check_if_installed(self): return True -class SeleniumServer(RequiredTool): - VERSION = "3.141" - REMOTE_ADDR = "http://selenium-release.storage.googleapis.com/" - REMOTE_PATH = "{short_version}/selenium-server-standalone-{full_version}.jar" - TOOL_FILE = "selenium-server-{version}.jar" - - def __init__(self, config, **kwargs): - if not isinstance(config, dict): - config = BetterDict.from_dict({"path": config}) - - version = config.get("version", self.VERSION) - version = str(version).split('.') - # 3.141.59 version - version.extend(['59'] * (3 - len(version))) - short_version = '.'.join(version[:2]) # 2 elements - full_version = '.'.join(version) # 3+ elements - - remote_path = config.get("remote-path", self.REMOTE_PATH) - remote_path = remote_path.format(short_version=short_version, full_version=full_version) - - tool_file = config.get("tool-file", self.TOOL_FILE) - tool_file = tool_file.format(version=full_version) - - local_path = config.get("path", JarTool.LOCAL_PATH) - local_path = local_path.format(tool_file=tool_file) - - download_link = config.get("download-link", JarTool.URL) - download_link = download_link.format(remote_addr=self.REMOTE_ADDR, remote_path=remote_path) - - super(SeleniumServer, self).__init__( - tool_path=local_path, - download_link=download_link, - version=full_version, - **kwargs) - - def check_if_installed(self): - self.log.debug("Trying %s: %s", self.tool_name, self.tool_path) - try: - out, err = self.call(["java", "-jar", self.tool_path, "-help"]) - except CALL_PROBLEMS as exc: - self.log.warning("%s check failed: %s", self.tool_name, exc) - return False - - if err: - out += err - self.log.debug("%s output: %s", self.tool_name, out) - return True - - class Json(JarTool): REMOTE_PATH = "org/json/json/20160810/json-20160810.jar" TOOL_FILE = "json.jar" diff --git a/examples/all-executors.yml b/examples/all-executors.yml index 9e00522cff..a67d04d262 100644 --- a/examples/all-executors.yml +++ b/examples/all-executors.yml @@ -39,22 +39,6 @@ execution: - url: http://localhost:8000/ label: Selenium Chrome -- executor: selenium # Selenium_JUnit - concurrency: 1 - hold-for: 10s - iterations: 10 - runner: junit - scenario: - script: BOOTH1/Blazedemo.java - -- executor: selenium # Selenium_TestNG - concurrency: 1 - hold-for: 10s - iterations: 10 - runner: testng - scenario: - script: selenium/TestNGExample.java - --- execution: - executor: selenium # Selenium Ruby @@ -78,13 +62,6 @@ execution: scenario: script: functional/JUnitTest.java -- executor: testng # testTestNG - concurrency: 1 - hold-for: 10s - iterations: 10 - scenario: - script: functional/TestNGTest.java - - executor: rspec # Ruby test concurrency: 1 hold-for: 10s diff --git a/tests/resources/selenium/invalid/NotJUnittest.java b/tests/resources/selenium/invalid/NotJUnittest.java index 9af5a74d5e..6e703527f5 100644 --- a/tests/resources/selenium/invalid/NotJUnittest.java +++ b/tests/resources/selenium/invalid/NotJUnittest.java @@ -1,8 +1,3 @@ -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.firefox.FirefoxDriver; - public class NotJUnittest { public static void main(String[] args) { } diff --git a/tests/resources/selenium/invalid/SeleniumTest.java b/tests/resources/selenium/invalid/SeleniumTest.java deleted file mode 100644 index 9815b2524a..0000000000 --- a/tests/resources/selenium/invalid/SeleniumTest.java +++ /dev/null @@ -1,30 +0,0 @@ -import java.util.concurrent.TimeUnit; - -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.firefox.FirefoxDriver; - -public class SeleniumTest { - WebElement element; - - @BeforeClass - public static void openBrowser(){ - } - - @Test - public void valid_UserCredential(){ - } - - @Test - public void inValid_UserCredential() - { - } - - @AfterClass - public static void closeBrowser(){ - } -} \ No newline at end of file diff --git a/tests/resources/selenium/invalid/SimpleTest.java b/tests/resources/selenium/invalid/SimpleTest.java deleted file mode 100644 index dc008a73b7..0000000000 --- a/tests/resources/selenium/invalid/SimpleTest.java +++ /dev/null @@ -1,29 +0,0 @@ -import junit.framework.TestCase; -import org.openqa.selenium.*; -import org.openqa.selenium.remote.*; -import java.net.URL; -import java.util.concurrent.TimeUnit; -import org.openqa.selenium.firefox.FirefoxDriver; -import org.junit.Assert; - -public class SimpleTest extends TestCase { - WebElement element; - - public void setUp() throws Exception { - DesiredCapabilities capabilities = DesiredCapabilities.firefox(); - capabilities.setCapability("version", "11"); - capabilities.setCapability("platform", Platform.WINDOWS); - capabilities.setCapability("name", "Testing Selenium 2"); - - } - - public void testSimple() throws Exception { - } - - public void testInValid_UserCredential() - { - } - - public void tearDown() throws Exception { - } - } \ No newline at end of file diff --git a/tests/resources/selenium/invalid/selenium1.java b/tests/resources/selenium/invalid/selenium1.java deleted file mode 100644 index 49da48838c..0000000000 --- a/tests/resources/selenium/invalid/selenium1.java +++ /dev/null @@ -1,23 +0,0 @@ - -import java.util.concurrent.TimeUnit; - -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.firefox.FirefoxDriver; - -public class selenium1 { - - @BeforeClass - public static void openBrowser(){ - } - - @Test - public void valid_UserCredential(){ - Assert.assertEquals(1, 1); - } - -} \ No newline at end of file diff --git a/tests/unit/modules/_selenium/test_java.py b/tests/unit/modules/_selenium/test_java.py index d4104ab2f8..3cc6945da4 100644 --- a/tests/unit/modules/_selenium/test_java.py +++ b/tests/unit/modules/_selenium/test_java.py @@ -1,639 +1,638 @@ -import os -import shutil -import time -from os import listdir -from os.path import exists, join, dirname -import yaml - -from bzt.modules.aggregator import ConsolidatingAggregator -from bzt.modules.functional import FunctionalAggregator, FuncSamplesReader -from bzt.modules.java import JUnitTester, TestNGTester -from bzt.modules.java.executors import JavaTestRunner -from bzt.modules.java.tools import JavaC, JarTool, Hamcrest, SeleniumServer -from bzt.modules.jmeter import JTLReader -from bzt.modules._selenium import SeleniumExecutor -from bzt.utils import ToolError -from tests.unit import BZTestCase, local_paths_config, RESOURCES_DIR, BUILD_DIR, ExecutorTestCase, EngineEmul -from tests.unit.modules._selenium import SeleniumTestCase - - -class TestTestNGTester(ExecutorTestCase): - EXECUTOR = TestNGTester - CMD_LINE = None - - def start_subprocess(self, args, env, cwd=None, **kwargs): - self.CMD_LINE = args - - def setUp(self): - super(TestTestNGTester, self).setUp() - self.obj.engine.configure([local_paths_config()]) - self.obj.settings = self.obj.engine.config.get("modules").get("testng") - - def test_simple(self): - self.obj.execution.merge({ - "scenario": { - "script": RESOURCES_DIR + "selenium/testng/TestNGSuite.java"}}) - self.obj.settings['autodetect-xml'] = False - self.obj._compile_scripts = lambda: None - self.obj.prepare() - self.obj.engine.start_subprocess = self.start_subprocess - self.obj.startup() - self.obj.post_process() - - self.assertTrue('-cp' in self.CMD_LINE) - cp_val = self.CMD_LINE[self.CMD_LINE.index('-cp')+1] - for class_val in self.obj.class_path: - self.assertIn(class_val, cp_val) - - def test_install_tools(self): - installation_path = BUILD_DIR + "selenium-taurus" - source_url = "file:///" + RESOURCES_DIR + "selenium/selenium-server.jar" - - shutil.rmtree(dirname(installation_path), ignore_errors=True) - self.assertFalse(exists(installation_path)) - - saved_url = JarTool.URL - saved_local_path = JarTool.LOCAL_PATH - - JarTool.URL = source_url - JarTool.LOCAL_PATH = join(installation_path, "{tool_file}") - - try: - - self.obj.settings.merge({ - "selenium-server": { - "path": join(installation_path, "selenium-server.jar"), - "download-link": source_url, - "version": "9.9" - }, - "hamcrest-core": join(installation_path, "tools", "testng", "hamcrest-core.jar"), - "path": JarTool.LOCAL_PATH}) - - self.obj.execution.merge({ - "scenario": { - "script": RESOURCES_DIR + "selenium/testng/jars/testng-suite.jar"}}) - - self.obj.prepare() - - finally: - JarTool.URL = saved_url - JarTool.LOCAL_PATH = saved_local_path - - self.assertTrue(isinstance(self.obj, TestNGTester)) - - jar_tools = [tool for tool in self.obj._tools if isinstance(tool, JarTool)] - self.assertTrue(15, len(jar_tools)) - - for tool in jar_tools: - msg = "Wrong path to {tool}: {path}".format(tool=str(tool), path=str(tool.tool_path)) - self.assertTrue(os.path.isfile(tool.tool_path), msg) - if isinstance(tool, SeleniumServer): - self.assertEqual(tool.version, "9.9.0") - - -class TestJavaC(BZTestCase): - def test_missed_tool(self): - self.obj = JavaC() - self.obj.tool_path = "javac-not-found" - self.assertEqual(False, self.obj.check_if_installed()) - self.assertRaises(ToolError, self.obj.install) - - def test_get_version(self): - self.obj = JavaC() - out1 = "javac 10.0.1" - out2 = "javac 1.8.0_151" - - self.assertEqual("10", self.obj._get_version(out1)) - self.assertEqual("8", self.obj._get_version(out2)) - - def test_simple_compilation(self): - super(TestJavaC, self).setUp() - engine_obj = EngineEmul() - - self.obj = JUnitTester() - self.obj.settings = engine_obj.config.get("modules").get("junit") - self.obj.engine = engine_obj - - self.obj.execution.merge({ - "scenario": {"script": RESOURCES_DIR + "selenium/invalid/selenium1.java"} - }) - - self.obj.prepare() - self.obj.post_process() - - -class TestJUnitTester(BZTestCase): - def setUp(self): - super(TestJUnitTester, self).setUp() - engine_obj = EngineEmul() - paths = [local_paths_config()] - engine_obj.configure(paths) - - # just download geckodriver & chromedriver with selenium - selenium = SeleniumExecutor() - selenium.engine = engine_obj - selenium.install_required_tools() - for driver in selenium.webdrivers: - selenium.env.add_path({"PATH": driver.get_dir()}) - - self.obj = JUnitTester() - self.obj.env = selenium.env - self.obj.settings = engine_obj.config.get("modules").get("junit") - self.obj.engine = engine_obj - - def tearDown(self): - if self.obj.stdout: - self.obj.stdout.close() - if self.obj.stderr: - self.obj.stderr.close() - super(TestJUnitTester, self).tearDown() - - def test_install_tools(self): - """ - check installation of selenium-server, junit - :return: - """ - installation_path = BUILD_DIR + "selenium-taurus" - source_url = "file:///" + RESOURCES_DIR + "selenium/selenium-server.jar" - - shutil.rmtree(dirname(installation_path), ignore_errors=True) - self.assertFalse(exists(installation_path)) - - saved_url = JarTool.URL - saved_local_path = JarTool.LOCAL_PATH - - JarTool.URL = source_url - JarTool.LOCAL_PATH = join(installation_path, "{tool_file}") - - try: - self.obj.settings.merge({ - "selenium-server": join(installation_path, "selenium-server.jar"), - "hamcrest-core": { - "path": join(installation_path, "tools", "junit", "hamcrest-core.jar"), - "version": "0.1", - }, - "path": installation_path - }) - - self.obj.execution.merge({ - "scenario": { - "script": RESOURCES_DIR + "selenium/junit/jar/"}, - "runner": "junit"}) - self.obj.prepare() - finally: - JarTool.URL = saved_url - JarTool.LOCAL_PATH = saved_local_path - - self.assertTrue(isinstance(self.obj, JUnitTester)) - - jar_tools = [tool for tool in self.obj._tools if isinstance(tool, JarTool)] - self.assertTrue(15, len(jar_tools)) - - for tool in jar_tools: - msg = "Wrong path to {tool}: {path}".format(tool=str(tool), path=str(tool.tool_path)) - if isinstance(tool, Hamcrest): - self.assertEqual(tool.version, "0.1") - self.assertTrue(os.path.isfile(tool.tool_path), msg) - - def test_simple(self): - self.obj.engine.aggregator = ConsolidatingAggregator() - self.obj.execution.merge({ - "scenario": {"script": RESOURCES_DIR + "BlazeDemo.java", "properties": {"scenprop": 3}}, - "properties": {"execprop": 2} - }) - self.obj.settings.merge({"properties": {"settprop": 1}, "junit-version": 5}) - self.obj._compile_scripts = lambda: None - self.obj.prepare() - self.obj.engine.aggregator.prepare() - self.obj.engine.start_subprocess = lambda **kwargs: None - self.obj.startup() - self.obj.post_process() - self.obj.engine.aggregator.post_process() - - orig_prop_file = RESOURCES_DIR + "selenium/junit/runner.properties" - start1 = (self.obj.engine.artifacts_dir + os.path.sep).replace('\\', '/') - start2 = "ARTIFACTS+" - self.assertFilesEqual(orig_prop_file, self.obj.props_file, replace_str=start1, replace_with=start2) - - def test_load_mode(self): - self.obj.engine.aggregator = ConsolidatingAggregator() - self.obj.execution.merge({ - "iterations": 10, - "scenario": {"script": RESOURCES_DIR + "selenium/invalid/SimpleTest.java"}, - }) - self.obj.settings.merge({"junit-version": 5}) - self.obj._compile_scripts = lambda: None - self.obj.prepare() - self.obj.engine.aggregator.prepare() - self.obj.engine.start_subprocess = lambda **kwargs: None - self.obj.startup() - self.obj.post_process() - self.obj.engine.aggregator.post_process() - self.assertTrue(self.obj.report_file.endswith(".csv")) - self.assertIsInstance(self.obj.reader, JTLReader) - - def test_func_mode(self): - self.obj.engine.aggregator = FunctionalAggregator() - self.obj.execution.merge({ - "iterations": 10, - "scenario": {"script": RESOURCES_DIR + "selenium/invalid/SimpleTest.java"}, - }) - self.obj.settings.merge({"junit-version": 5}) - self.obj._compile_scripts = lambda: None - self.obj.prepare() - self.obj.engine.aggregator.prepare() - self.obj.engine.start_subprocess = lambda **kwargs: None - self.obj.startup() - self.obj.post_process() - self.obj.engine.aggregator.post_process() - - self.obj.reader.report_reader.json_reader.file.close() - - self.assertTrue(self.obj.report_file.endswith(".ldjson")) - self.assertIsInstance(self.obj.reader, FuncSamplesReader) - - -class TestSeleniumJUnitTester(SeleniumTestCase): - """ - :type obj: bzt.modules._selenium.SeleniumExecutor - """ - - def __init__(self, methodName='runTest'): - super(TestSeleniumJUnitTester, self).__init__(methodName) - self.obj = None - - def obj_prepare(self): - super(SeleniumExecutor, self.obj).prepare() - self.obj.install_required_tools() - for driver in self.obj.webdrivers: - self.obj.env.add_path({"PATH": driver.get_dir()}) - self.obj.create_runner() - self.obj.runner.install_required_tools = lambda: None - self.obj.runner._compile_scripts = lambda: None - self.obj.runner.prepare() - self.obj.script = self.obj.runner.script - - def test_prepare_java_single(self): - """ - Check if script exists in working dir - :return: - """ - self.obj.execution.merge({ - "scenario": {"script": RESOURCES_DIR + "selenium/junit/java/TestBlazemeterFail.java"} - }) - self.obj_prepare() - self.assertIsInstance(self.obj.runner, JavaTestRunner) - self.assertFalse(exists(join(self.obj.runner.working_dir, "TestBlazemeterFail.java"))) - - def test_prepare_java_folder(self): - """ - Check if scripts exist in working dir - :return: - """ - self.obj.execution.merge({"scenario": {"script": RESOURCES_DIR + "selenium/junit/java/"}}) - self.obj_prepare() - self.assertIsInstance(self.obj.runner, JavaTestRunner) - prepared_files = listdir(self.obj.runner.working_dir) - java_files = [fname for fname in prepared_files if fname.endswith(".java")] - class_files = [fname for fname in prepared_files if fname.endswith(".class")] - jars = [fname for fname in prepared_files if fname.endswith(".jar")] - self.assertEqual(len(java_files), 0) - - def test_prepare_java_package(self): - """ - Check if scripts exist in working dir - :return: - """ - self.obj.execution.merge({"scenario": {"script": RESOURCES_DIR + "selenium/junit/java_package/"}}) - self.obj_prepare() - self.assertIsInstance(self.obj.runner, JavaTestRunner) - - def test_selenium_startup_shutdown_java_package(self): - """ - Run tests from package - :return: - """ - self.configure({ - 'execution': { - 'scenario': {'script': RESOURCES_DIR + 'selenium/junit/java_package/src'}, - 'executor': 'selenium' - }, - 'reporting': [{'module': 'junit-xml'}] - }) - self.obj_prepare() - self.assertIsInstance(self.obj.runner, JavaTestRunner) - - def test_prepare_jar_single(self): - self.obj.execution.merge({"scenario": {"script": RESOURCES_DIR + "selenium/junit/jar/dummy.jar"}}) - self.obj.prepare() - - def test_prepare_jar_folder(self): - self.obj.execution.merge({"scenario": {"script": RESOURCES_DIR + "selenium/junit/jar/"}}) - self.obj.prepare() - - def test_selenium_startup_shutdown_jar_single(self): - """ - runt tests from single jar - :return: - """ - self.configure({ - 'execution': { - 'scenario': {'script': RESOURCES_DIR + 'selenium/junit/jar/'}, - 'runner': 'junit', - 'executor': 'selenium' - }, - 'reporting': [{'module': 'junit-xml'}] - }) - self.obj_prepare() - self.assertIsInstance(self.obj.runner, JUnitTester) - self.obj.shutdown() - - self.assertIsInstance(self.obj.runner, JavaTestRunner) - prepared_files = listdir(self.obj.runner.working_dir) - java_files = [fname for fname in prepared_files if fname.endswith(".java")] - class_files = [fname for fname in prepared_files if fname.endswith(".class")] - jars = [fname for fname in prepared_files if fname.endswith(".jar")] - self.assertEqual(len(java_files), 0) - self.assertEqual(len(class_files), 0) - self.assertEqual(len(jars), 0) - - def test_selenium_startup_shutdown_jar_folder(self): - """ - run tests from jars - :return: - """ - self.configure({ - 'execution': { - 'scenario': {'script': RESOURCES_DIR + 'selenium/junit/jar/'}, - 'executor': 'selenium' - }, - 'reporting': [{'module': 'junit-xml'}] - }) - self.obj_prepare() - - self.assertIsInstance(self.obj.runner, JavaTestRunner) - prepared_files = listdir(self.obj.runner.working_dir) - java_files = [fname for fname in prepared_files if fname.endswith(".java")] - class_files = [fname for fname in prepared_files if fname.endswith(".class")] - jars = [fname for fname in prepared_files if fname.endswith(".jar")] - self.assertEqual(len(java_files), 0) - self.assertEqual(len(class_files), 0) - self.assertEqual(len(jars), 0) - - def test_selenium_startup_shutdown_java_single(self): - """ - run tests from single .java file - :return: - """ - self.obj.engine.config.merge({ - 'execution': { - 'scenario': {'script': RESOURCES_DIR + 'selenium/junit/java/'}, - 'executor': 'selenium' - }, - 'reporting': [{'module': 'junit-xml'}] - }) - self.obj.execution.merge({ - "scenario": {"script": RESOURCES_DIR + "selenium/junit/java/TestBlazemeterFail.java"} - }) - self.obj_prepare() - self.obj.shutdown() - - self.assertIsInstance(self.obj.runner, JavaTestRunner) - prepared_files = listdir(self.obj.runner.working_dir) - java_files = [fname for fname in prepared_files if fname.endswith(".java")] - class_files = [fname for fname in prepared_files if fname.endswith(".class")] - jars = [fname for fname in prepared_files if fname.endswith(".jar")] - self.assertEqual(0, len(java_files)) - - def test_selenium_startup_shutdown_java_folder(self): - """ - run tests from .java files - :return: - """ - self.configure({ - 'execution': { - 'scenario': {'script': RESOURCES_DIR + 'selenium/junit/java/'}, - 'executor': 'selenium' - }, - 'reporting': [{'module': 'junit-xml'}] - }) - - self.obj_prepare() - self.assertIsInstance(self.obj.runner, JavaTestRunner) - prepared_files = listdir(self.obj.runner.working_dir) - java_files = [fname for fname in prepared_files if fname.endswith(".java")] - class_files = [fname for fname in prepared_files if fname.endswith(".class")] - jars = [fname for fname in prepared_files if fname.endswith(".jar")] - self.assertEqual(0, len(java_files)) - - def test_resource_files_collection_remote_java(self): - self.configure({ - 'execution': { - 'scenario': {'script': RESOURCES_DIR + 'selenium/junit/java/'}, - 'executor': 'selenium' - }, - 'reporting': [{'module': 'junit-xml'}] - }) - self.assertEqual(len(self.obj.resource_files()), 1) - - def test_additional_classpath(self): - scenario_cp = 'class_path_from_scenario' - settings_cp = 'class_path_from_settings' - self.configure({ - 'execution': { - 'scenario': { - 'script': RESOURCES_DIR + 'selenium/junit/java/', - 'additional-classpath': [scenario_cp]}, - 'executor': 'selenium', }, - 'modules': { - 'junit': { - 'additional-classpath': [settings_cp]}}}) - self.obj_prepare() - self.assertIsInstance(self.obj.runner, JavaTestRunner) - class_path = ':'.join(self.obj.runner.class_path) - self.assertIn(scenario_cp, class_path) - self.assertIn(settings_cp, class_path) - - def test_resource_files_collection_remote_jar(self): - self.configure({ - 'execution': { - 'scenario': {'script': RESOURCES_DIR + 'selenium/junit/jar/'}, - 'executor': 'selenium' - }, - 'reporting': [{'module': 'junit-xml'}] - }) - self.assertEqual(len(self.obj.resource_files()), 1) - - -class TestSeleniumTestNGRunner(SeleniumTestCase): - CMD_LINE = None - - def start_subprocess(self, args, env, cwd=None, **kwargs): - self.CMD_LINE = args - - def obj_prepare(self): - super(SeleniumExecutor, self.obj).prepare() - self.obj.install_required_tools() - for driver in self.obj.webdrivers: - self.obj.env.add_path({"PATH": driver.get_dir()}) - self.obj.create_runner() - self.obj.runner.install_required_tools = lambda: None - self.obj.runner._compile_scripts = lambda: None - self.obj.runner.prepare() - self.obj.script = self.obj.runner.script - - def test_prepare_java_package(self): - self.configure({ - 'execution': { - 'scenario': { - 'script': RESOURCES_DIR + 'selenium/testng/jars/testng-suite.jar'}, - 'runner': 'testng'}, - 'modules': { - 'testng': { - 'autodetect-xml': False}}}) - self.obj.prepare() - self.obj.engine.start_subprocess = self.start_subprocess - self.obj.startup() - self.obj.post_process() - - self.assertTrue('-cp' in self.CMD_LINE) - cp_val = self.CMD_LINE[self.CMD_LINE.index('-cp')+1] - for class_val in self.obj.runner.class_path: - self.assertIn(class_val, cp_val) - - def test_prepare_java_file(self): - self.configure({ - 'execution': { - 'scenario': { - 'script': RESOURCES_DIR + 'selenium/testng/TestNGSuite.java'}, - 'runner': 'testng'}, - 'modules': { - 'testng': { - 'autodetect-xml': False - }}}) - self.obj.prepare() - self.obj.engine.start_subprocess = self.start_subprocess - self.obj.startup() - self.obj.post_process() - - self.assertTrue('-cp' in self.CMD_LINE) - cp_val = self.CMD_LINE[self.CMD_LINE.index('-cp')+1] - for class_val in self.obj.runner.class_path: - self.assertIn(class_val, cp_val) - - def test_resource_files(self): - script_jar = RESOURCES_DIR + 'selenium/testng/jars/testng-suite.jar' - self.configure({ - 'execution': { - 'testng-xml': 'testng.xml', - 'scenario': { - 'script': script_jar, - }, - 'runner': 'testng', - }, - }) - resources = self.obj.get_resource_files() - self.assertPathsEqual(resources, [script_jar, 'testng.xml']) - - def test_resource_files_detect_config(self): - script_jar = RESOURCES_DIR + 'selenium/testng/jars/testng-suite.jar' - self.configure({ - 'execution': { - 'scenario': { - 'script': script_jar, - }, - 'runner': 'testng', - }, - }) - resources = self.obj.get_resource_files() - self.assertPathsEqual(resources, [script_jar, (RESOURCES_DIR + 'selenium/testng/jars/testng.xml')]) - - def test_hold(self): - self.configure({ - 'execution': { - 'hold-for': '1s', - 'scenario': { - 'script': RESOURCES_DIR + 'selenium/testng/jars/testng-suite.jar'}, - 'runner': 'testng'}, - 'modules': { - 'testng': { - 'autodetect-xml': False}}}) - self.obj.prepare() - self.obj.engine.start_subprocess = self.start_subprocess - self.obj.startup() - self.obj.post_process() - - self.assertIsNotNone(self.CMD_LINE) - props = self.CMD_LINE[-1] - self.assertTrue(props.endswith("runner.properties")) - properties = open(props).readlines() - self.assertIn("hold_for=1.0\n", properties) - - def test_iterations(self): - self.configure({ - 'execution': { - 'iterations': 3, - 'scenario': { - 'script': RESOURCES_DIR + 'selenium/testng/jars/testng-suite.jar'}, - 'runner': 'testng'}, - 'modules': { - 'testng': { - 'autodetect-xml': False}}}) - self.obj.prepare() - self.obj.engine.start_subprocess = self.start_subprocess - self.obj.startup() - self.obj.post_process() - - self.assertIsNotNone(self.CMD_LINE) - props = self.CMD_LINE[-1] - self.assertTrue(props.endswith("runner.properties")) - properties = open(props).readlines() - self.assertIn("iterations=3\n", properties) - - def test_with_testng_config(self): - self.configure({ - 'execution': { - 'testng-xml': RESOURCES_DIR + 'selenium/testng/jars/testng.xml', - 'scenario': { - 'script': RESOURCES_DIR + 'selenium/testng/jars/testng-suite.jar'}}}) - self.obj.prepare() - self.obj.startup() - while not self.obj.check(): - time.sleep(self.obj.engine.check_interval) - self.obj.shutdown() - self.assertTrue(exists(self.obj.runner.report_file)) - lines = open(self.obj.runner.report_file).readlines() - self.assertEqual(len(lines), 6) - - def test_testng_config_autodetect(self): - self.configure({ - 'execution': { - 'scenario': { - 'script': RESOURCES_DIR + 'selenium/testng/jars/testng-suite.jar'}}}) - self.obj.prepare() - self.obj.startup() - while not self.obj.check(): - time.sleep(self.obj.engine.check_interval) - self.obj.shutdown() - self.assertTrue(exists(self.obj.runner.report_file)) - lines = open(self.obj.runner.report_file).readlines() - self.assertEqual(len(lines), 6) - - def test_autodetect_script_type(self): - self.configure({ - 'execution': { - 'scenario': { - 'script': RESOURCES_DIR + 'selenium/testng/jars/testng-suite.jar', - }, - }, - }) - self.obj.prepare() - self.assertIsInstance(self.obj.runner, TestNGTester) - - def test_detect_testng_xml_with_config(self): - test_yml = RESOURCES_DIR + "selenium/testng/test.yml" - self.obj.engine.config.merge(yaml.full_load(open(test_yml))) - self.obj.execution = self.obj.engine.config.get('execution') - self.obj.engine.file_search_paths.append(dirname(test_yml)) - self.obj.prepare() - self.assertIsInstance(self.obj.runner, TestNGTester) +# import os +# import shutil +# import time +# from os import listdir +# from os.path import exists, join, dirname +# import yaml +# +# from bzt.modules.aggregator import ConsolidatingAggregator +# from bzt.modules.functional import FunctionalAggregator, FuncSamplesReader +# from bzt.modules.java import JUnitTester, TestNGTester +# from bzt.modules.java.executors import JavaTestRunner +# from bzt.modules.java.tools import JavaC, JarTool, Hamcrest +# from bzt.modules.jmeter import JTLReader +# from bzt.modules._selenium import SeleniumExecutor +# from bzt.utils import ToolError +# from tests.unit import BZTestCase, local_paths_config, RESOURCES_DIR, BUILD_DIR, ExecutorTestCase, EngineEmul +# from tests.unit.modules._selenium import SeleniumTestCase +# +# +# +# class TestTestNGTester(ExecutorTestCase): +# EXECUTOR = TestNGTester +# CMD_LINE = None +# +# def start_subprocess(self, args, env, cwd=None, **kwargs): +# self.CMD_LINE = args +# +# def setUp(self): +# super(TestTestNGTester, self).setUp() +# self.obj.engine.configure([local_paths_config()]) +# self.obj.settings = self.obj.engine.config.get("modules").get("testng") +# +# def test_simple(self): +# self.obj.execution.merge({ +# "scenario": { +# "script": RESOURCES_DIR + "selenium/testng/TestNGSuite.java"}}) +# self.obj.settings['autodetect-xml'] = False +# self.obj._compile_scripts = lambda: None +# self.obj.prepare() +# self.obj.engine.start_subprocess = self.start_subprocess +# self.obj.startup() +# self.obj.post_process() +# +# self.assertTrue('-cp' in self.CMD_LINE) +# cp_val = self.CMD_LINE[self.CMD_LINE.index('-cp')+1] +# for class_val in self.obj.class_path: +# self.assertIn(class_val, cp_val) +# +# def test_install_tools(self): +# installation_path = BUILD_DIR + "selenium-taurus" +# source_url = "file:///" + RESOURCES_DIR + "selenium/selenium-server.jar" +# +# shutil.rmtree(dirname(installation_path), ignore_errors=True) +# self.assertFalse(exists(installation_path)) +# +# saved_url = JarTool.URL +# saved_local_path = JarTool.LOCAL_PATH +# +# JarTool.URL = source_url +# JarTool.LOCAL_PATH = join(installation_path, "{tool_file}") +# +# try: +# +# self.obj.settings.merge({ +# "selenium-server": { +# "path": join(installation_path, "selenium-server.jar"), +# "download-link": source_url, +# "version": "9.9" +# }, +# "hamcrest-core": join(installation_path, "tools", "testng", "hamcrest-core.jar"), +# "path": JarTool.LOCAL_PATH}) +# +# self.obj.execution.merge({ +# "scenario": { +# "script": RESOURCES_DIR + "selenium/testng/jars/testng-suite.jar"}}) +# +# self.obj.prepare() +# +# finally: +# JarTool.URL = saved_url +# JarTool.LOCAL_PATH = saved_local_path +# +# self.assertTrue(isinstance(self.obj, TestNGTester)) +# +# jar_tools = [tool for tool in self.obj._tools if isinstance(tool, JarTool)] +# self.assertTrue(15, len(jar_tools)) +# +# for tool in jar_tools: +# msg = "Wrong path to {tool}: {path}".format(tool=str(tool), path=str(tool.tool_path)) +# self.assertTrue(os.path.isfile(tool.tool_path), msg) +# +# +# class TestJavaC(BZTestCase): +# def test_missed_tool(self): +# self.obj = JavaC() +# self.obj.tool_path = "javac-not-found" +# self.assertEqual(False, self.obj.check_if_installed()) +# self.assertRaises(ToolError, self.obj.install) +# +# def test_get_version(self): +# self.obj = JavaC() +# out1 = "javac 10.0.1" +# out2 = "javac 1.8.0_151" +# +# self.assertEqual("10", self.obj._get_version(out1)) +# self.assertEqual("8", self.obj._get_version(out2)) +# +# def test_simple_compilation(self): +# super(TestJavaC, self).setUp() +# engine_obj = EngineEmul() +# +# self.obj = JUnitTester() +# self.obj.settings = engine_obj.config.get("modules").get("junit") +# self.obj.engine = engine_obj +# +# self.obj.execution.merge({ +# "scenario": {"script": RESOURCES_DIR + "selenium/invalid/selenium1.java"} +# }) +# +# self.obj.prepare() +# self.obj.post_process() +# +# +# class TestJUnitTester(BZTestCase): +# def setUp(self): +# super(TestJUnitTester, self).setUp() +# engine_obj = EngineEmul() +# paths = [local_paths_config()] +# engine_obj.configure(paths) +# +# # just download geckodriver & chromedriver with selenium +# selenium = SeleniumExecutor() +# selenium.engine = engine_obj +# selenium.install_required_tools() +# for driver in selenium.webdrivers: +# selenium.env.add_path({"PATH": driver.get_dir()}) +# +# self.obj = JUnitTester() +# self.obj.env = selenium.env +# self.obj.settings = engine_obj.config.get("modules").get("junit") +# self.obj.engine = engine_obj +# +# def tearDown(self): +# if self.obj.stdout: +# self.obj.stdout.close() +# if self.obj.stderr: +# self.obj.stderr.close() +# super(TestJUnitTester, self).tearDown() +# +# def test_install_tools(self): +# """ +# check installation of selenium-server, junit +# :return: +# """ +# installation_path = BUILD_DIR + "selenium-taurus" +# source_url = "file:///" + RESOURCES_DIR + "selenium/selenium-server.jar" +# +# shutil.rmtree(dirname(installation_path), ignore_errors=True) +# self.assertFalse(exists(installation_path)) +# +# saved_url = JarTool.URL +# saved_local_path = JarTool.LOCAL_PATH +# +# JarTool.URL = source_url +# JarTool.LOCAL_PATH = join(installation_path, "{tool_file}") +# +# try: +# self.obj.settings.merge({ +# "selenium-server": join(installation_path, "selenium-server.jar"), +# "hamcrest-core": { +# "path": join(installation_path, "tools", "junit", "hamcrest-core.jar"), +# "version": "0.1", +# }, +# "path": installation_path +# }) +# +# self.obj.execution.merge({ +# "scenario": { +# "script": RESOURCES_DIR + "selenium/junit/jar/"}, +# "runner": "junit"}) +# self.obj.prepare() +# finally: +# JarTool.URL = saved_url +# JarTool.LOCAL_PATH = saved_local_path +# +# self.assertTrue(isinstance(self.obj, JUnitTester)) +# +# jar_tools = [tool for tool in self.obj._tools if isinstance(tool, JarTool)] +# self.assertTrue(15, len(jar_tools)) +# +# for tool in jar_tools: +# msg = "Wrong path to {tool}: {path}".format(tool=str(tool), path=str(tool.tool_path)) +# if isinstance(tool, Hamcrest): +# self.assertEqual(tool.version, "0.1") +# self.assertTrue(os.path.isfile(tool.tool_path), msg) +# +# def test_simple(self): +# self.obj.engine.aggregator = ConsolidatingAggregator() +# self.obj.execution.merge({ +# "scenario": {"script": RESOURCES_DIR + "BlazeDemo.java", "properties": {"scenprop": 3}}, +# "properties": {"execprop": 2} +# }) +# self.obj.settings.merge({"properties": {"settprop": 1}, "junit-version": 5}) +# self.obj._compile_scripts = lambda: None +# self.obj.prepare() +# self.obj.engine.aggregator.prepare() +# self.obj.engine.start_subprocess = lambda **kwargs: None +# self.obj.startup() +# self.obj.post_process() +# self.obj.engine.aggregator.post_process() +# +# orig_prop_file = RESOURCES_DIR + "selenium/junit/runner.properties" +# start1 = (self.obj.engine.artifacts_dir + os.path.sep).replace('\\', '/') +# start2 = "ARTIFACTS+" +# self.assertFilesEqual(orig_prop_file, self.obj.props_file, replace_str=start1, replace_with=start2) +# +# def test_load_mode(self): +# self.obj.engine.aggregator = ConsolidatingAggregator() +# self.obj.execution.merge({ +# "iterations": 10, +# "scenario": {"script": RESOURCES_DIR + "selenium/invalid/SimpleTest.java"}, +# }) +# self.obj.settings.merge({"junit-version": 5}) +# self.obj._compile_scripts = lambda: None +# self.obj.prepare() +# self.obj.engine.aggregator.prepare() +# self.obj.engine.start_subprocess = lambda **kwargs: None +# self.obj.startup() +# self.obj.post_process() +# self.obj.engine.aggregator.post_process() +# self.assertTrue(self.obj.report_file.endswith(".csv")) +# self.assertIsInstance(self.obj.reader, JTLReader) +# +# def test_func_mode(self): +# self.obj.engine.aggregator = FunctionalAggregator() +# self.obj.execution.merge({ +# "iterations": 10, +# "scenario": {"script": RESOURCES_DIR + "selenium/invalid/SimpleTest.java"}, +# }) +# self.obj.settings.merge({"junit-version": 5}) +# self.obj._compile_scripts = lambda: None +# self.obj.prepare() +# self.obj.engine.aggregator.prepare() +# self.obj.engine.start_subprocess = lambda **kwargs: None +# self.obj.startup() +# self.obj.post_process() +# self.obj.engine.aggregator.post_process() +# +# self.obj.reader.report_reader.json_reader.file.close() +# +# self.assertTrue(self.obj.report_file.endswith(".ldjson")) +# self.assertIsInstance(self.obj.reader, FuncSamplesReader) +# +# +# class TestSeleniumJUnitTester(SeleniumTestCase): +# """ +# :type obj: bzt.modules._selenium.SeleniumExecutor +# """ +# +# def __init__(self, methodName='runTest'): +# super(TestSeleniumJUnitTester, self).__init__(methodName) +# self.obj = None +# +# def obj_prepare(self): +# super(SeleniumExecutor, self.obj).prepare() +# self.obj.install_required_tools() +# for driver in self.obj.webdrivers: +# self.obj.env.add_path({"PATH": driver.get_dir()}) +# self.obj.create_runner() +# self.obj.runner.install_required_tools = lambda: None +# self.obj.runner._compile_scripts = lambda: None +# self.obj.runner.prepare() +# self.obj.script = self.obj.runner.script +# +# def test_prepare_java_single(self): +# """ +# Check if script exists in working dir +# :return: +# """ +# self.obj.execution.merge({ +# "scenario": {"script": RESOURCES_DIR + "selenium/junit/java/TestBlazemeterFail.java"} +# }) +# self.obj_prepare() +# self.assertIsInstance(self.obj.runner, JavaTestRunner) +# self.assertFalse(exists(join(self.obj.runner.working_dir, "TestBlazemeterFail.java"))) +# +# def test_prepare_java_folder(self): +# """ +# Check if scripts exist in working dir +# :return: +# """ +# self.obj.execution.merge({"scenario": {"script": RESOURCES_DIR + "selenium/junit/java/"}}) +# self.obj_prepare() +# self.assertIsInstance(self.obj.runner, JavaTestRunner) +# prepared_files = listdir(self.obj.runner.working_dir) +# java_files = [fname for fname in prepared_files if fname.endswith(".java")] +# class_files = [fname for fname in prepared_files if fname.endswith(".class")] +# jars = [fname for fname in prepared_files if fname.endswith(".jar")] +# self.assertEqual(len(java_files), 0) +# +# def test_prepare_java_package(self): +# """ +# Check if scripts exist in working dir +# :return: +# """ +# self.obj.execution.merge({"scenario": {"script": RESOURCES_DIR + "selenium/junit/java_package/"}}) +# self.obj_prepare() +# self.assertIsInstance(self.obj.runner, JavaTestRunner) +# +# def test_selenium_startup_shutdown_java_package(self): +# """ +# Run tests from package +# :return: +# """ +# self.configure({ +# 'execution': { +# 'scenario': {'script': RESOURCES_DIR + 'selenium/junit/java_package/src'}, +# 'executor': 'selenium' +# }, +# 'reporting': [{'module': 'junit-xml'}] +# }) +# self.obj_prepare() +# self.assertIsInstance(self.obj.runner, JavaTestRunner) +# +# def test_prepare_jar_single(self): +# self.obj.execution.merge({"scenario": {"script": RESOURCES_DIR + "selenium/junit/jar/dummy.jar"}}) +# self.obj.prepare() +# +# def test_prepare_jar_folder(self): +# self.obj.execution.merge({"scenario": {"script": RESOURCES_DIR + "selenium/junit/jar/"}}) +# self.obj.prepare() +# +# def test_selenium_startup_shutdown_jar_single(self): +# """ +# runt tests from single jar +# :return: +# """ +# self.configure({ +# 'execution': { +# 'scenario': {'script': RESOURCES_DIR + 'selenium/junit/jar/'}, +# 'runner': 'junit', +# 'executor': 'selenium' +# }, +# 'reporting': [{'module': 'junit-xml'}] +# }) +# self.obj_prepare() +# self.assertIsInstance(self.obj.runner, JUnitTester) +# self.obj.shutdown() +# +# self.assertIsInstance(self.obj.runner, JavaTestRunner) +# prepared_files = listdir(self.obj.runner.working_dir) +# java_files = [fname for fname in prepared_files if fname.endswith(".java")] +# class_files = [fname for fname in prepared_files if fname.endswith(".class")] +# jars = [fname for fname in prepared_files if fname.endswith(".jar")] +# self.assertEqual(len(java_files), 0) +# self.assertEqual(len(class_files), 0) +# self.assertEqual(len(jars), 0) +# +# def test_selenium_startup_shutdown_jar_folder(self): +# """ +# run tests from jars +# :return: +# """ +# self.configure({ +# 'execution': { +# 'scenario': {'script': RESOURCES_DIR + 'selenium/junit/jar/'}, +# 'executor': 'selenium' +# }, +# 'reporting': [{'module': 'junit-xml'}] +# }) +# self.obj_prepare() +# +# self.assertIsInstance(self.obj.runner, JavaTestRunner) +# prepared_files = listdir(self.obj.runner.working_dir) +# java_files = [fname for fname in prepared_files if fname.endswith(".java")] +# class_files = [fname for fname in prepared_files if fname.endswith(".class")] +# jars = [fname for fname in prepared_files if fname.endswith(".jar")] +# self.assertEqual(len(java_files), 0) +# self.assertEqual(len(class_files), 0) +# self.assertEqual(len(jars), 0) +# +# def test_selenium_startup_shutdown_java_single(self): +# """ +# run tests from single .java file +# :return: +# """ +# self.obj.engine.config.merge({ +# 'execution': { +# 'scenario': {'script': RESOURCES_DIR + 'selenium/junit/java/'}, +# 'executor': 'selenium' +# }, +# 'reporting': [{'module': 'junit-xml'}] +# }) +# self.obj.execution.merge({ +# "scenario": {"script": RESOURCES_DIR + "selenium/junit/java/TestBlazemeterFail.java"} +# }) +# self.obj_prepare() +# self.obj.shutdown() +# +# self.assertIsInstance(self.obj.runner, JavaTestRunner) +# prepared_files = listdir(self.obj.runner.working_dir) +# java_files = [fname for fname in prepared_files if fname.endswith(".java")] +# class_files = [fname for fname in prepared_files if fname.endswith(".class")] +# jars = [fname for fname in prepared_files if fname.endswith(".jar")] +# self.assertEqual(0, len(java_files)) +# +# def test_selenium_startup_shutdown_java_folder(self): +# """ +# run tests from .java files +# :return: +# """ +# self.configure({ +# 'execution': { +# 'scenario': {'script': RESOURCES_DIR + 'selenium/junit/java/'}, +# 'executor': 'selenium' +# }, +# 'reporting': [{'module': 'junit-xml'}] +# }) +# +# self.obj_prepare() +# self.assertIsInstance(self.obj.runner, JavaTestRunner) +# prepared_files = listdir(self.obj.runner.working_dir) +# java_files = [fname for fname in prepared_files if fname.endswith(".java")] +# class_files = [fname for fname in prepared_files if fname.endswith(".class")] +# jars = [fname for fname in prepared_files if fname.endswith(".jar")] +# self.assertEqual(0, len(java_files)) +# +# def test_resource_files_collection_remote_java(self): +# self.configure({ +# 'execution': { +# 'scenario': {'script': RESOURCES_DIR + 'selenium/junit/java/'}, +# 'executor': 'selenium' +# }, +# 'reporting': [{'module': 'junit-xml'}] +# }) +# self.assertEqual(len(self.obj.resource_files()), 1) +# +# def test_additional_classpath(self): +# scenario_cp = 'class_path_from_scenario' +# settings_cp = 'class_path_from_settings' +# self.configure({ +# 'execution': { +# 'scenario': { +# 'script': RESOURCES_DIR + 'selenium/junit/java/', +# 'additional-classpath': [scenario_cp]}, +# 'executor': 'selenium', }, +# 'modules': { +# 'junit': { +# 'additional-classpath': [settings_cp]}}}) +# self.obj_prepare() +# self.assertIsInstance(self.obj.runner, JavaTestRunner) +# class_path = ':'.join(self.obj.runner.class_path) +# self.assertIn(scenario_cp, class_path) +# self.assertIn(settings_cp, class_path) +# +# def test_resource_files_collection_remote_jar(self): +# self.configure({ +# 'execution': { +# 'scenario': {'script': RESOURCES_DIR + 'selenium/junit/jar/'}, +# 'executor': 'selenium' +# }, +# 'reporting': [{'module': 'junit-xml'}] +# }) +# self.assertEqual(len(self.obj.resource_files()), 1) +# +# +# class TestSeleniumTestNGRunner(SeleniumTestCase): +# CMD_LINE = None +# +# def start_subprocess(self, args, env, cwd=None, **kwargs): +# self.CMD_LINE = args +# +# def obj_prepare(self): +# super(SeleniumExecutor, self.obj).prepare() +# self.obj.install_required_tools() +# for driver in self.obj.webdrivers: +# self.obj.env.add_path({"PATH": driver.get_dir()}) +# self.obj.create_runner() +# self.obj.runner.install_required_tools = lambda: None +# self.obj.runner._compile_scripts = lambda: None +# self.obj.runner.prepare() +# self.obj.script = self.obj.runner.script +# +# def test_prepare_java_package(self): +# self.configure({ +# 'execution': { +# 'scenario': { +# 'script': RESOURCES_DIR + 'selenium/testng/jars/testng-suite.jar'}, +# 'runner': 'testng'}, +# 'modules': { +# 'testng': { +# 'autodetect-xml': False}}}) +# self.obj.prepare() +# self.obj.engine.start_subprocess = self.start_subprocess +# self.obj.startup() +# self.obj.post_process() +# +# self.assertTrue('-cp' in self.CMD_LINE) +# cp_val = self.CMD_LINE[self.CMD_LINE.index('-cp')+1] +# for class_val in self.obj.runner.class_path: +# self.assertIn(class_val, cp_val) +# +# def test_prepare_java_file(self): +# self.configure({ +# 'execution': { +# 'scenario': { +# 'script': RESOURCES_DIR + 'selenium/testng/TestNGSuite.java'}, +# 'runner': 'testng'}, +# 'modules': { +# 'testng': { +# 'autodetect-xml': False +# }}}) +# self.obj.prepare() +# self.obj.engine.start_subprocess = self.start_subprocess +# self.obj.startup() +# self.obj.post_process() +# +# self.assertTrue('-cp' in self.CMD_LINE) +# cp_val = self.CMD_LINE[self.CMD_LINE.index('-cp')+1] +# for class_val in self.obj.runner.class_path: +# self.assertIn(class_val, cp_val) +# +# def test_resource_files(self): +# script_jar = RESOURCES_DIR + 'selenium/testng/jars/testng-suite.jar' +# self.configure({ +# 'execution': { +# 'testng-xml': 'testng.xml', +# 'scenario': { +# 'script': script_jar, +# }, +# 'runner': 'testng', +# }, +# }) +# resources = self.obj.get_resource_files() +# self.assertPathsEqual(resources, [script_jar, 'testng.xml']) +# +# def test_resource_files_detect_config(self): +# script_jar = RESOURCES_DIR + 'selenium/testng/jars/testng-suite.jar' +# self.configure({ +# 'execution': { +# 'scenario': { +# 'script': script_jar, +# }, +# 'runner': 'testng', +# }, +# }) +# resources = self.obj.get_resource_files() +# self.assertPathsEqual(resources, [script_jar, (RESOURCES_DIR + 'selenium/testng/jars/testng.xml')]) +# +# def test_hold(self): +# self.configure({ +# 'execution': { +# 'hold-for': '1s', +# 'scenario': { +# 'script': RESOURCES_DIR + 'selenium/testng/jars/testng-suite.jar'}, +# 'runner': 'testng'}, +# 'modules': { +# 'testng': { +# 'autodetect-xml': False}}}) +# self.obj.prepare() +# self.obj.engine.start_subprocess = self.start_subprocess +# self.obj.startup() +# self.obj.post_process() +# +# self.assertIsNotNone(self.CMD_LINE) +# props = self.CMD_LINE[-1] +# self.assertTrue(props.endswith("runner.properties")) +# properties = open(props).readlines() +# self.assertIn("hold_for=1.0\n", properties) +# +# def test_iterations(self): +# self.configure({ +# 'execution': { +# 'iterations': 3, +# 'scenario': { +# 'script': RESOURCES_DIR + 'selenium/testng/jars/testng-suite.jar'}, +# 'runner': 'testng'}, +# 'modules': { +# 'testng': { +# 'autodetect-xml': False}}}) +# self.obj.prepare() +# self.obj.engine.start_subprocess = self.start_subprocess +# self.obj.startup() +# self.obj.post_process() +# +# self.assertIsNotNone(self.CMD_LINE) +# props = self.CMD_LINE[-1] +# self.assertTrue(props.endswith("runner.properties")) +# properties = open(props).readlines() +# self.assertIn("iterations=3\n", properties) +# +# def test_with_testng_config(self): +# self.configure({ +# 'execution': { +# 'testng-xml': RESOURCES_DIR + 'selenium/testng/jars/testng.xml', +# 'scenario': { +# 'script': RESOURCES_DIR + 'selenium/testng/jars/testng-suite.jar'}}}) +# self.obj.prepare() +# self.obj.startup() +# while not self.obj.check(): +# time.sleep(self.obj.engine.check_interval) +# self.obj.shutdown() +# self.assertTrue(exists(self.obj.runner.report_file)) +# lines = open(self.obj.runner.report_file).readlines() +# self.assertEqual(len(lines), 6) +# +# def test_testng_config_autodetect(self): +# self.configure({ +# 'execution': { +# 'scenario': { +# 'script': RESOURCES_DIR + 'selenium/testng/jars/testng-suite.jar'}}}) +# self.obj.prepare() +# self.obj.startup() +# while not self.obj.check(): +# time.sleep(self.obj.engine.check_interval) +# self.obj.shutdown() +# self.assertTrue(exists(self.obj.runner.report_file)) +# lines = open(self.obj.runner.report_file).readlines() +# self.assertEqual(len(lines), 6) +# +# def test_autodetect_script_type(self): +# self.configure({ +# 'execution': { +# 'scenario': { +# 'script': RESOURCES_DIR + 'selenium/testng/jars/testng-suite.jar', +# }, +# }, +# }) +# self.obj.prepare() +# self.assertIsInstance(self.obj.runner, TestNGTester) +# +# def test_detect_testng_xml_with_config(self): +# test_yml = RESOURCES_DIR + "selenium/testng/test.yml" +# self.obj.engine.config.merge(yaml.full_load(open(test_yml))) +# self.obj.execution = self.obj.engine.config.get('execution') +# self.obj.engine.file_search_paths.append(dirname(test_yml)) +# self.obj.prepare() +# self.assertIsInstance(self.obj.runner, TestNGTester) diff --git a/tests/unit/modules/_selenium/test_selenium_executor.py b/tests/unit/modules/_selenium/test_selenium_executor.py index 1a33097aea..1c26b1ecfe 100644 --- a/tests/unit/modules/_selenium/test_selenium_executor.py +++ b/tests/unit/modules/_selenium/test_selenium_executor.py @@ -229,19 +229,19 @@ def test_various_raise(self): }]}) self.assertRaises(ToolError, self.obj_prepare) - def test_empty_test_methods(self): - self.configure({ # Test exact number of tests when - EXEC: [{ # java annotations used - "executor": "selenium", - "scenario": {"script": RESOURCES_DIR + "selenium/invalid/SeleniumTest.java"} - }, { # test class extends JUnit TestCase - "executor": "selenium", - "scenario": {"script": RESOURCES_DIR + "selenium/invalid/SimpleTest.java"} - }, { # annotations used and no "test" in class name - "executor": "selenium", - "scenario": {"script": RESOURCES_DIR + "selenium/invalid/selenium1.java"} - }]}) - self.obj_prepare_runner() + # def test_empty_test_methods(self): + # self.configure({ # Test exact number of tests when + # EXEC: [{ # java annotations used + # "executor": "selenium", + # "scenario": {"script": RESOURCES_DIR + "selenium/invalid/SeleniumTest.java"} + # }, { # test class extends JUnit TestCase + # "executor": "selenium", + # "scenario": {"script": RESOURCES_DIR + "selenium/invalid/SimpleTest.java"} + # }, { # annotations used and no "test" in class name + # "executor": "selenium", + # "scenario": {"script": RESOURCES_DIR + "selenium/invalid/selenium1.java"} + # }]}) + # self.obj_prepare_runner() def test_from_extension(self): self.configure(yaml.full_load(open(RESOURCES_DIR + "yaml/selenium_from_extension.yml").read()))