Skip to content

Commit 9c37022

Browse files
committed
initial implementation
1 parent 6912a99 commit 9c37022

File tree

2 files changed

+727
-4
lines changed

2 files changed

+727
-4
lines changed

percy/snapshot.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def fetch_percy_dom():
5858
# Take a DOM snapshot and post it to the snapshot endpoint
5959
def percy_snapshot(driver, name, **kwargs):
6060
session_type = is_percy_enabled()
61-
if session_type is False: return # Since session_type can be None for old CLI version
61+
if session_type is False: return None # Since session_type can be None for old CLI version
6262
if session_type == "automate": raise Exception("Invalid function call - "\
6363
"percy_snapshot(). Please use percy_screenshot() function while using Percy with Automate. "\
6464
"For more information on usage of PercyScreenshot, "\
@@ -79,21 +79,24 @@ def percy_snapshot(driver, name, **kwargs):
7979
'dom_snapshot': dom_snapshot,
8080
'url': driver.current_url,
8181
'name': name
82-
}}, timeout=30)
82+
}}, timeout=600)
8383

8484
# Handle errors
8585
response.raise_for_status()
8686
data = response.json()
8787

8888
if not data['success']: raise Exception(data['error'])
89+
if not data["data"]: return None
90+
return data["data"]
8991
except Exception as e:
9092
print(f'{LABEL} Could not take DOM snapshot "{name}"')
9193
print(f'{LABEL} {e}')
94+
return None
9295

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

119+
if 'sync' not in options:
120+
options['sync'] = False
121+
116122
ignore_region_elements = get_element_ids(
117123
options.get("ignore_region_selenium_elements", [])
118124
)
@@ -134,16 +140,19 @@ def percy_automate_screenshot(driver, name, options = None, **kwargs):
134140
'sessionCapabilites': metadata.session_capabilities,
135141
'snapshotName': name,
136142
'options': options
137-
}}, timeout=60)
143+
}}, timeout=600)
138144

139145
# Handle errors
140146
response.raise_for_status()
141147
data = response.json()
142148

143149
if not data['success']: raise Exception(data['error'])
150+
if not data['data']: return None
151+
return data['data']
144152
except Exception as e:
145153
print(f'{LABEL} Could not take Screenshot "{name}"')
146154
print(f'{LABEL} {e}')
155+
return None
147156

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

0 commit comments

Comments
 (0)