Skip to content

Commit

Permalink
Merge branch 'main' into migrate-js-clients
Browse files Browse the repository at this point in the history
  • Loading branch information
kb-kerem committed Apr 25, 2024
2 parents b59b67a + 5f36268 commit ec9011a
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 37 deletions.
8 changes: 4 additions & 4 deletions visual-dotnet/SauceLabs.Visual/BuildFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ private static async Task<VisualBuild> 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();

Expand Down
2 changes: 1 addition & 1 deletion visual-dotnet/SauceLabs.Visual/SauceLabs.Visual.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<language>en-US</language>
<NeutralLanguage>en</NeutralLanguage>
<PackageId>SauceLabs.Visual</PackageId>
<Version>0.3.1</Version>
<Version>0.4.0</Version>
<Title>Sauce Labs Visual Binding</Title>
<PackageTags>saucelabs sauce labs visual testing screenshot capture dom</PackageTags>
<RepositoryUrl>https://github.com/saucelabs/visual-sdks</RepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion visual-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.saucelabs.visual</groupId>
<artifactId>java-client</artifactId>
<version>0.3.387</version>
<version>0.4.0</version>
<name>visual-java-client</name>
<description>Java library to interact with Sauce Visual</description>

Expand Down
24 changes: 7 additions & 17 deletions visual-java/src/main/java/com/saucelabs/visual/VisualApi.java
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion visual-python/.bumpversion.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.bumpversion]
current_version = "0.0.8"
current_version = "0.0.9"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
serialize = ["{major}.{minor}.{patch}"]
search = "{current_version}"
Expand Down
2 changes: 1 addition & 1 deletion visual-python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
16 changes: 8 additions & 8 deletions visual-python/src/saucelabs_visual/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,32 @@


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.'
)

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,
Expand Down
31 changes: 27 additions & 4 deletions visual-python/src/saucelabs_visual/frameworks/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit ec9011a

Please sign in to comment.