Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync implementation #89

Merged
merged 6 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
restore-keys: v1/${{ runner.os }}/pypi-${matrix.python}/
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 16
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
Expand Down
17 changes: 13 additions & 4 deletions percy/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def fetch_percy_dom():
# Take a DOM snapshot and post it to the snapshot endpoint
def percy_snapshot(driver, name, **kwargs):
session_type = is_percy_enabled()
if session_type is False: return # Since session_type can be None for old CLI version
if session_type is False: return None # Since session_type can be None for old CLI version
if session_type == "automate": raise Exception("Invalid function call - "\
"percy_snapshot(). Please use percy_screenshot() function while using Percy with Automate. "\
"For more information on usage of PercyScreenshot, "\
Expand All @@ -79,21 +79,24 @@ def percy_snapshot(driver, name, **kwargs):
'dom_snapshot': dom_snapshot,
'url': driver.current_url,
'name': name
}}, timeout=30)
}}, timeout=600)

# Handle errors
response.raise_for_status()
data = response.json()

if not data['success']: raise Exception(data['error'])
if not data["data"]: return None
return data["data"]
except Exception as e:
print(f'{LABEL} Could not take DOM snapshot "{name}"')
print(f'{LABEL} {e}')
return None

# Take screenshot on driver
def percy_automate_screenshot(driver, name, options = None, **kwargs):
session_type = is_percy_enabled()
if session_type is False: return # Since session_type can be None for old CLI version
if session_type is False: return None # Since session_type can be None for old CLI version
if session_type == "web": raise Exception("Invalid function call - "\
"percy_screenshot(). Please use percy_snapshot() function for taking screenshot. "\
"percy_screenshot() should be used only while using Percy with Automate. "\
Expand All @@ -113,6 +116,9 @@ def percy_automate_screenshot(driver, name, options = None, **kwargs):
options['consider_region_selenium_elements'] = options['considerRegionSeleniumElements']
options.pop('considerRegionSeleniumElements')

if 'sync' not in options:
options['sync'] = False
chinmay-browserstack marked this conversation as resolved.
Show resolved Hide resolved

ignore_region_elements = get_element_ids(
options.get("ignore_region_selenium_elements", [])
)
Expand All @@ -134,16 +140,19 @@ def percy_automate_screenshot(driver, name, options = None, **kwargs):
'sessionCapabilites': metadata.session_capabilities,
'snapshotName': name,
'options': options
}}, timeout=60)
}}, timeout=600)

# Handle errors
response.raise_for_status()
data = response.json()

if not data['success']: raise Exception(data['error'])
if not data['data']: return None
chinmay-browserstack marked this conversation as resolved.
Show resolved Hide resolved
return data['data']
except Exception as e:
print(f'{LABEL} Could not take Screenshot "{name}"')
print(f'{LABEL} {e}')
return None

def get_element_ids(elements):
return [element.id for element in elements]
Loading
Loading