From 49143fce9eb8054de994546d620282057bca6342 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Tue, 1 Feb 2022 22:37:07 -0500 Subject: [PATCH] Update available command-line options --- README.md | 11 ++++++----- examples/raw_parameter_script.py | 4 ++++ help_docs/customizing_test_runs.md | 11 ++++++----- seleniumbase/fixtures/base_case.py | 1 + seleniumbase/fixtures/constants.py | 4 ++++ seleniumbase/plugins/base_plugin.py | 24 +++++++++++++++++++----- seleniumbase/plugins/pytest_plugin.py | 23 ++++++++++++++++++----- 7 files changed, 58 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 8456ab49..21542121 100755 --- a/README.md +++ b/README.md @@ -325,11 +325,12 @@ The code above will leave your browser window open in case there's a failure. (i --cap-file=FILE # (The web browser's desired capabilities to use.) --cap-string=STRING # (The web browser's desired capabilities to use.) --settings-file=FILE # (Override default SeleniumBase settings.) ---env=ENV # (Set a test environment. Use "self.env" to use this in tests.) ---data=DATA # (Extra test data. Access with "self.data" in tests.) ---var1=DATA # (Extra test data. Access with "self.var1" in tests.) ---var2=DATA # (Extra test data. Access with "self.var2" in tests.) ---var3=DATA # (Extra test data. Access with "self.var3" in tests.) +--env=ENV # (Set the test env. Access with "self.env" in tests.) +--account=STR # (Set account. Access with "self.account" in tests.) +--data=STRING # (Extra test data. Access with "self.data" in tests.) +--var1=STRING # (Extra test data. Access with "self.var1" in tests.) +--var2=STRING # (Extra test data. Access with "self.var2" in tests.) +--var3=STRING # (Extra test data. Access with "self.var3" in tests.) --user-data-dir=DIR # (Set the Chrome user data directory to use.) --protocol=PROTOCOL # (The Selenium Grid protocol: http|https.) --server=SERVER # (The Selenium Grid server/IP used for tests.) diff --git a/examples/raw_parameter_script.py b/examples/raw_parameter_script.py index cacac670..c28a13e4 100755 --- a/examples/raw_parameter_script.py +++ b/examples/raw_parameter_script.py @@ -40,6 +40,10 @@ if pure_python: sb.servername = "localhost" sb.port = 4444 sb.data = None + sb.var1 = None + sb.var2 = None + sb.var3 = None + sb.account = None sb.environment = "test" sb.user_agent = None sb.incognito = False diff --git a/help_docs/customizing_test_runs.md b/help_docs/customizing_test_runs.md index a748da70..66b44d59 100755 --- a/help_docs/customizing_test_runs.md +++ b/help_docs/customizing_test_runs.md @@ -109,11 +109,12 @@ SeleniumBase provides additional ``pytest`` command-line options for tests: --cap-file=FILE # (The web browser's desired capabilities to use.) --cap-string=STRING # (The web browser's desired capabilities to use.) --settings-file=FILE # (Override default SeleniumBase settings.) ---env=ENV # (Set a test environment. Use "self.env" to use this in tests.) ---data=DATA # (Extra test data. Access with "self.data" in tests.) ---var1=DATA # (Extra test data. Access with "self.var1" in tests.) ---var2=DATA # (Extra test data. Access with "self.var2" in tests.) ---var3=DATA # (Extra test data. Access with "self.var3" in tests.) +--env=ENV # (Set the test env. Access with "self.env" in tests.) +--account=STR # (Set account. Access with "self.account" in tests.) +--data=STRING # (Extra test data. Access with "self.data" in tests.) +--var1=STRING # (Extra test data. Access with "self.var1" in tests.) +--var2=STRING # (Extra test data. Access with "self.var2" in tests.) +--var3=STRING # (Extra test data. Access with "self.var3" in tests.) --user-data-dir=DIR # (Set the Chrome user data directory to use.) --protocol=PROTOCOL # (The Selenium Grid protocol: http|https.) --server=SERVER # (The Selenium Grid server/IP used for tests.) diff --git a/seleniumbase/fixtures/base_case.py b/seleniumbase/fixtures/base_case.py index d55055be..f7976cd9 100755 --- a/seleniumbase/fixtures/base_case.py +++ b/seleniumbase/fixtures/base_case.py @@ -10937,6 +10937,7 @@ class BaseCase(unittest.TestCase): if hasattr(self, "_using_sb_fixture"): self.test_id = sb_config._test_id self.browser = sb_config.browser + self.account = sb_config.account self.data = sb_config.data self.var1 = sb_config.var1 self.var2 = sb_config.var2 diff --git a/seleniumbase/fixtures/constants.py b/seleniumbase/fixtures/constants.py index a7896a41..1240fbd9 100755 --- a/seleniumbase/fixtures/constants.py +++ b/seleniumbase/fixtures/constants.py @@ -12,7 +12,11 @@ class Environment: DEVELOP = "develop" PRODUCTION = "production" MASTER = "master" + REMOTE = "remote" LOCAL = "local" + ALPHA = "alpha" + BETA = "beta" + MAIN = "main" TEST = "test" diff --git a/seleniumbase/plugins/base_plugin.py b/seleniumbase/plugins/base_plugin.py index a0944d66..45bf7b99 100755 --- a/seleniumbase/plugins/base_plugin.py +++ b/seleniumbase/plugins/base_plugin.py @@ -15,10 +15,11 @@ class Base(Plugin): """ This plugin adds the following command-line options to nosetests: --env=ENV (Set the test env. Access with "self.env" in tests.) - --data=DATA (Extra test data. Access with "self.data" in tests.) - --var1=DATA (Extra test data. Access with "self.var1" in tests.) - --var2=DATA (Extra test data. Access with "self.var2" in tests.) - --var3=DATA (Extra test data. Access with "self.var3" in tests.) + --account=STR (Set account. Access with "self.account" in tests.) + --data=STRING (Extra test data. Access with "self.data" in tests.) + --var1=STRING (Extra test data. Access with "self.var1" in tests.) + --var2=STRING (Extra test data. Access with "self.var2" in tests.) + --var3=STRING (Extra test data. Access with "self.var3" in tests.) --settings-file=FILE (Override default SeleniumBase settings.) --archive-logs (Archive old log files instead of deleting them.) --archive-downloads (Archive old downloads instead of deleting.) @@ -43,11 +44,23 @@ class Base(Plugin): constants.Environment.DEVELOP, constants.Environment.PRODUCTION, constants.Environment.MASTER, + constants.Environment.REMOTE, constants.Environment.LOCAL, + constants.Environment.ALPHA, + constants.Environment.BETA, + constants.Environment.MAIN, constants.Environment.TEST, ), default=constants.Environment.TEST, - help="The environment to run the tests in.", + help="""This option sets a test env from a list of choices. + In tests, use "self.environment" to get the env.""", + ) + parser.add_option( + "--account", + dest="account", + default=None, + help="""This option sets a test account string. + In tests, use "self.account" to get the value.""", ) parser.add_option( "--data", @@ -171,6 +184,7 @@ class Base(Plugin): def beforeTest(self, test): test.test.environment = self.options.environment test.test.env = self.options.environment # Add a shortened version + test.test.account = self.options.account test.test.data = self.options.data test.test.var1 = self.options.var1 test.test.var2 = self.options.var2 diff --git a/seleniumbase/plugins/pytest_plugin.py b/seleniumbase/plugins/pytest_plugin.py index 5f256483..d212db53 100644 --- a/seleniumbase/plugins/pytest_plugin.py +++ b/seleniumbase/plugins/pytest_plugin.py @@ -25,10 +25,11 @@ def pytest_addoption(parser): --safari (Shortcut for "--browser=safari".) --settings-file=FILE (Override default SeleniumBase settings.) --env=ENV (Set the test env. Access with "self.env" in tests.) - --data=DATA (Extra test data. Access with "self.data" in tests.) - --var1=DATA (Extra test data. Access with "self.var1" in tests.) - --var2=DATA (Extra test data. Access with "self.var2" in tests.) - --var3=DATA (Extra test data. Access with "self.var3" in tests.) + --account=STR (Set account. Access with "self.account" in tests.) + --data=STRING (Extra test data. Access with "self.data" in tests.) + --var1=STRING (Extra test data. Access with "self.var1" in tests.) + --var2=STRING (Extra test data. Access with "self.var2" in tests.) + --var3=STRING (Extra test data. Access with "self.var3" in tests.) --user-data-dir=DIR (Set the Chrome user data directory to use.) --protocol=PROTOCOL (The Selenium Grid protocol: http|https.) --server=SERVER (The Selenium Grid server/IP used for tests.) @@ -171,13 +172,24 @@ def pytest_addoption(parser): constants.Environment.DEVELOP, constants.Environment.PRODUCTION, constants.Environment.MASTER, + constants.Environment.REMOTE, constants.Environment.LOCAL, + constants.Environment.ALPHA, + constants.Environment.BETA, + constants.Environment.MAIN, constants.Environment.TEST, ), default=constants.Environment.TEST, - help="""This option is used for setting the test env. + help="""This option sets a test env from a list of choices. In tests, use "self.environment" to get the env.""", ) + parser.addoption( + "--account", + dest="account", + default=None, + help="""This option sets a test account string. + In tests, use "self.account" to get the value.""", + ) parser.addoption( "--data", dest="data", @@ -1047,6 +1059,7 @@ def pytest_configure(config): sb_config.browser = config.getoption("browser") if sb_config._browser_shortcut: sb_config.browser = sb_config._browser_shortcut + sb_config.account = config.getoption("account") sb_config.data = config.getoption("data") sb_config.var1 = config.getoption("var1") sb_config.var2 = config.getoption("var2")