-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathveriff.py
111 lines (90 loc) · 3.89 KB
/
veriff.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from typing import Dict
import requests
from pylenium.driver import Pylenium
from pylenium.element import Element
class DocumentType:
PASSPORT = "PASSPORT"
DRIVERS_LICENSE = "DRIVERS_LICENSE"
ID_CARD = "ID_CARD"
RESIDENCE_PERMIT = "RESIDENCE_PERMIT"
class LaunchVia:
IN_CONTEXT = "incontext"
REDIRECT = "redirect"
def create_session(full_name: str, language: str, country: str, doc_type: str) -> str:
payload = {
"full_name": full_name,
"lang": language,
"document_country": country,
"document_type": doc_type,
"additionalData": {"isTest": False},
}
response = requests.post("https://demo.saas-3.veriff.me/", json=payload)
if not response.ok:
raise ValueError(f"Failed to create session. Status Code: {response.status_code}, Error: {response.text}")
return response.json().get("sessionToken")
def get_session_config(session_token: str) -> Dict:
headers = {"Authorization": f"Bearer {session_token}"}
response = requests.get("https://magic.saas-3.veriff.me/api/v2/sessions", headers=headers)
if not response.ok:
raise ValueError(f"Failed to get session config. Status Code: {response.status_code}, Error: {response.text}")
return response.json()
class VeriffUI:
def __init__(self, py: Pylenium):
self.py = py
def visit(self) -> "VeriffUI":
self.py.visit("https://demo.saas-3.veriff.me/")
return self
def enter_full_name(self, full_name: str) -> Element:
fullname_field = self.py.get("[name='name']")
# Clear the full name field
self.py.execute_script("arguments[0].value = ''", fullname_field.webelement)
return fullname_field.type(full_name)
def select_language(self, language: str) -> Element:
"""The dropdown is actually a button element that opens a list under script elements.
Poor UI design and not accessible. RAISE AS ISSUE!
"""
dropdown = self.py.get("[name='language']")
dropdown.click()
language_options = self.py.find("ul[id='downshift-0-menu'] > li")
for option in language_options:
if option.text() == language:
option.click()
break
return dropdown
def select_country(self, country: str) -> Element:
country_field = self.py.get("[name='documentCountry']")
country_field.type(country)
country_options = self.py.find("ul[id='downshift-1-menu'] > li")
country_options[0].click()
return country_field
def select_document_type(self, document_type: str) -> Element:
dropdown = self.py.get("[name='documentType']")
dropdown.click()
document_options = self.py.find("ul[id='downshift-2-menu'] > li")
for option in document_options:
if option.text() == document_type:
option.click()
break
return dropdown
def select_launch_via(self, launch_via: str) -> Element:
launch = launch_via.lower()
if launch in ["incontext", "redirect"]:
return self.py.get(f"[value='{launch}']").check(allow_selected=True)
else:
raise ValueError(f"Invalid launch_via. Must be 'incontext' or 'redirect'")
def launch_veriff(self) -> "VeriffUI":
self.py.get("button[type='submit']").click()
return self
def launch_veriff_with(
self, full_name: str, language: str, country: str, document_type: str, launch_via: str
) -> "VeriffUI":
self.enter_full_name(full_name)
self.select_language(language)
self.select_country(country)
self.select_document_type(document_type)
self.select_launch_via(launch_via)
return self.launch_veriff()
def find_QR_code(self, launch_via: str) -> Element:
if launch_via.lower() == "incontext":
self.py.switch_to.frame("veriffFrame")
return self.py.contains("QR")