From ed085e909b416b776bdf3528b0a065089bdb5e32 Mon Sep 17 00:00:00 2001 From: Logan Graham Date: Wed, 24 Apr 2024 16:42:27 -0400 Subject: [PATCH 1/5] [Python] Updates / Fixes (#39) Co-authored-by: Logan Graham --- visual-python/src/saucelabs_visual/client.py | 16 +++++----- .../src/saucelabs_visual/frameworks/robot.py | 31 ++++++++++++++++--- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/visual-python/src/saucelabs_visual/client.py b/visual-python/src/saucelabs_visual/client.py index 4d9dd322..f1b439c7 100644 --- a/visual-python/src/saucelabs_visual/client.py +++ b/visual-python/src/saucelabs_visual/client.py @@ -12,21 +12,24 @@ class SauceLabsVisual: - client: Client = None + _client: Client = None build_id: Union[str, None] = None build_url: Union[str, None] = None meta_cache: dict = {} region: Region = None - def __init__(self): - self._create_client() + @property + def client(self): + if self._client is None: + self._client = self._create_client() + return self._client def _create_client(self): username = environ.get("SAUCE_USERNAME") access_key = environ.get("SAUCE_ACCESS_KEY") if username is None or access_key is None: - raise Exception( + raise RuntimeError( 'Sauce Labs credentials not set. Please check that you set correctly your ' '`SAUCE_USERNAME` and `SAUCE_ACCESS_KEY` environment variables.' ) @@ -34,10 +37,7 @@ def _create_client(self): self.region = Region.from_name(environ.get("SAUCE_REGION") or 'us-west-1') region_url = self.region.graphql_endpoint transport = RequestsHTTPTransport(url=region_url, auth=HTTPBasicAuth(username, access_key)) - self.client = Client(transport=transport, execute_timeout=90) - - def get_client(self) -> Client: - return self.client + return Client(transport=transport, execute_timeout=90) def create_build( self, diff --git a/visual-python/src/saucelabs_visual/frameworks/robot.py b/visual-python/src/saucelabs_visual/frameworks/robot.py index 9d730271..fe50d4a5 100644 --- a/visual-python/src/saucelabs_visual/frameworks/robot.py +++ b/visual-python/src/saucelabs_visual/frameworks/robot.py @@ -16,13 +16,36 @@ @library(scope='GLOBAL') class SauceLabsVisual: - client: Client = None + _client: Client = None + selenium_library_key: Union[str, None] = None - def __init__(self): - self.client = Client() + @property + def client(self): + if self._client is None: + self._client = Client() + return self._client def _get_selenium_library(self) -> SeleniumLibrary: - return BuiltIn().get_library_instance('SeleniumLibrary') + all_libraries: dict = BuiltIn().get_library_instance(all=True) + + # SeleniumLibrary may be imported under another name if an alias is provided -- ex: + # + # Library SeleniumLibrary AS slib + # + # Instead of importing by static name, we'll get all imported libraries and iterate over + # them to find the instance of SeleniumLibrary and cache that key. + if self.selenium_library_key is None: + for key, value in all_libraries.items(): + if type(value) is SeleniumLibrary: + self.selenium_library_key = key + break + + if self.selenium_library_key is None: + raise RuntimeError( + 'SeleniumLibrary instance not found in Robot. Is it imported in your project?' + ) + + return BuiltIn().get_library_instance(self.selenium_library_key) def _get_selenium_id(self) -> str: return self._get_selenium_library().get_session_id() From c39512cf7927e9c21e63545af751926dae561216 Mon Sep 17 00:00:00 2001 From: sauce-visual-bot Date: Wed, 24 Apr 2024 20:47:02 +0000 Subject: [PATCH 2/5] =?UTF-8?q?[release]=20python=200.0.8=20=E2=86=92=200.?= =?UTF-8?q?0.9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- visual-python/.bumpversion.toml | 2 +- visual-python/pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/visual-python/.bumpversion.toml b/visual-python/.bumpversion.toml index 26c319d0..fb103cab 100644 --- a/visual-python/.bumpversion.toml +++ b/visual-python/.bumpversion.toml @@ -1,5 +1,5 @@ [tool.bumpversion] -current_version = "0.0.8" +current_version = "0.0.9" parse = "(?P\\d+)\\.(?P\\d+)\\.(?P\\d+)" serialize = ["{major}.{minor}.{patch}"] search = "{current_version}" diff --git a/visual-python/pyproject.toml b/visual-python/pyproject.toml index db108125..6fcf6a33 100644 --- a/visual-python/pyproject.toml +++ b/visual-python/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "saucelabs_visual" -version = "0.0.8" +version = "0.0.9" description = "Python bindings for Sauce Labs Visual" dependencies=[ "requests", From 57fe0c1531abfe97b1fe05bb166947cebb47d94b Mon Sep 17 00:00:00 2001 From: Kerem Date: Thu, 25 Apr 2024 11:24:03 +0000 Subject: [PATCH 3/5] [fix] Env var precedence (#37) --- .../SauceLabs.Visual/BuildFactory.cs | 8 +++---- .../java/com/saucelabs/visual/VisualApi.java | 24 ++++++------------- .../visual/utils/EnvironmentVariables.java | 4 ++++ 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/visual-dotnet/SauceLabs.Visual/BuildFactory.cs b/visual-dotnet/SauceLabs.Visual/BuildFactory.cs index e634e0da..93c7f635 100644 --- a/visual-dotnet/SauceLabs.Visual/BuildFactory.cs +++ b/visual-dotnet/SauceLabs.Visual/BuildFactory.cs @@ -154,10 +154,10 @@ private static async Task Create(VisualApi api, CreateBuildOptions options.CustomId ??= EnvVars.CustomId; var result = (await api.CreateBuild(new CreateBuildIn { - Name = StringUtils.ValueOrDefault(EnvVars.BuildName, options.Name), - Project = StringUtils.ValueOrDefault(EnvVars.Project, options.Project), - Branch = StringUtils.ValueOrDefault(EnvVars.Branch, options.Branch), - DefaultBranch = StringUtils.ValueOrDefault(EnvVars.DefaultBranch, options.DefaultBranch), + Name = StringUtils.ValueOrDefault(options.Name, EnvVars.BuildName), + Project = StringUtils.ValueOrDefault(options.Project, EnvVars.Project), + Branch = StringUtils.ValueOrDefault(options.Branch, EnvVars.Branch), + DefaultBranch = StringUtils.ValueOrDefault(options.DefaultBranch, EnvVars.DefaultBranch), CustomId = options.CustomId, })).EnsureValidResponse(); diff --git a/visual-java/src/main/java/com/saucelabs/visual/VisualApi.java b/visual-java/src/main/java/com/saucelabs/visual/VisualApi.java index ada3e318..2522d08c 100644 --- a/visual-java/src/main/java/com/saucelabs/visual/VisualApi.java +++ b/visual-java/src/main/java/com/saucelabs/visual/VisualApi.java @@ -1,6 +1,7 @@ package com.saucelabs.visual; import static com.saucelabs.visual.utils.EnvironmentVariables.isNotBlank; +import static com.saucelabs.visual.utils.EnvironmentVariables.valueOrDefault; import com.saucelabs.visual.exception.VisualApiException; import com.saucelabs.visual.graphql.*; @@ -230,33 +231,22 @@ public String getName() { if (isNotBlank(EnvironmentVariables.BUILD_NAME_DEPRECATED)) { log.warn( "Sauce Labs Visual: Environment variable \"BUILD_NAME\" is deprecated and will be removed in a future version. Please use \"SAUCE_VISUAL_BUILD_NAME\" instead."); - return EnvironmentVariables.BUILD_NAME_DEPRECATED; } - if (isNotBlank(EnvironmentVariables.BUILD_NAME)) { - return EnvironmentVariables.BUILD_NAME; - } - return name; + return valueOrDefault( + valueOrDefault(name, EnvironmentVariables.BUILD_NAME), + EnvironmentVariables.BUILD_NAME_DEPRECATED); } public String getProject() { - if (isNotBlank(EnvironmentVariables.PROJECT_NAME)) { - return EnvironmentVariables.PROJECT_NAME; - } - return project; + return valueOrDefault(project, EnvironmentVariables.PROJECT_NAME); } public String getBranch() { - if (isNotBlank(EnvironmentVariables.BRANCH_NAME)) { - return EnvironmentVariables.BRANCH_NAME; - } - return branch; + return valueOrDefault(branch, EnvironmentVariables.BRANCH_NAME); } public String getDefaultBranch() { - if (isNotBlank(EnvironmentVariables.DEFAULT_BRANCH_NAME)) { - return EnvironmentVariables.DEFAULT_BRANCH_NAME; - } - return defaultBranch; + return valueOrDefault(defaultBranch, EnvironmentVariables.DEFAULT_BRANCH_NAME); } } diff --git a/visual-java/src/main/java/com/saucelabs/visual/utils/EnvironmentVariables.java b/visual-java/src/main/java/com/saucelabs/visual/utils/EnvironmentVariables.java index 328faed4..f3e53c1d 100644 --- a/visual-java/src/main/java/com/saucelabs/visual/utils/EnvironmentVariables.java +++ b/visual-java/src/main/java/com/saucelabs/visual/utils/EnvironmentVariables.java @@ -16,4 +16,8 @@ private EnvironmentVariables() {} public static boolean isNotBlank(String str) { return str != null && !str.trim().isEmpty(); } + + public static String valueOrDefault(String str, String defaultValue) { + return isNotBlank(str) ? str : defaultValue; + } } From 8c9d56e7466b48ee18933733765b3bef11cc43a7 Mon Sep 17 00:00:00 2001 From: sauce-visual-bot Date: Thu, 25 Apr 2024 12:45:36 +0000 Subject: [PATCH 4/5] [release] java-0.4.0 --- visual-java/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/visual-java/pom.xml b/visual-java/pom.xml index 6819213c..f4ae215b 100644 --- a/visual-java/pom.xml +++ b/visual-java/pom.xml @@ -6,7 +6,7 @@ com.saucelabs.visual java-client - 0.3.387 + 0.4.0 visual-java-client Java library to interact with Sauce Visual From 5f36268af4214b6c3fd7dc67f86f7cd79e578add Mon Sep 17 00:00:00 2001 From: sauce-visual-bot Date: Thu, 25 Apr 2024 12:52:24 +0000 Subject: [PATCH 5/5] [release] dotnet-0.4.0 --- visual-dotnet/SauceLabs.Visual/SauceLabs.Visual.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/visual-dotnet/SauceLabs.Visual/SauceLabs.Visual.csproj b/visual-dotnet/SauceLabs.Visual/SauceLabs.Visual.csproj index f94fc901..6d3d09de 100644 --- a/visual-dotnet/SauceLabs.Visual/SauceLabs.Visual.csproj +++ b/visual-dotnet/SauceLabs.Visual/SauceLabs.Visual.csproj @@ -7,7 +7,7 @@ en-US en SauceLabs.Visual - 0.3.1 + 0.4.0 Sauce Labs Visual Binding saucelabs sauce labs visual testing screenshot capture dom https://github.com/saucelabs/visual-sdks