-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSunFlower.py
More file actions
209 lines (159 loc) · 8.2 KB
/
SunFlower.py
File metadata and controls
209 lines (159 loc) · 8.2 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import random
import string
import time
url = 'https://app.dev.crowncoinscasino.com/'
email = "watchdogstest02+11@sunfltd.com"
password = "123456"
# Waits for an element to meet a condition (like clickable or visible), returns it if found
def wait_for_element(driver, locator, timeout=10, condition=EC.presence_of_element_located):
return WebDriverWait(driver, timeout).until(condition(locator))
# Opens the specified URL in Chrome
def open_url(url):
driver = webdriver.Chrome()
driver.get(url)
return driver
# Logs into the system using email and password
def login(driver, email, password):
login_button = wait_for_element(driver, (By.XPATH, "//button[@data-testid='lobby-login-btn']"), condition=EC.element_to_be_clickable)
time.sleep(1) # Simulate human delay
login_button.click()
email_input = wait_for_element(driver, (By.XPATH, "//input[@data-testid='email-input']"))
password_input = wait_for_element(driver, (By.XPATH, "//input[@data-testid='password-input']"))
time.sleep(1) # Simulate human delay
email_input.send_keys(email)
time.sleep(1) # Simulate typing delay
password_input.send_keys(password)
time.sleep(1) # Simulate typing delay
password_input.send_keys(Keys.RETURN)
time.sleep(2) # Allow the page to load after login
# Updates user profile with a random username and avatar
def update_profile(driver):
# Wait for and close the popup
popup_later_button = wait_for_element(driver, (By.ID, "onesignal-slidedown-cancel-button"), condition=EC.element_to_be_clickable)
time.sleep(1) # Simulate human delay
popup_later_button.click()
menu_button = wait_for_element(driver, (By.XPATH, "//button[@data-testid='menuButton']"), condition=EC.element_to_be_clickable)
time.sleep(1) # Simulate human delay
menu_button.click()
my_account_button = wait_for_element(driver, (By.XPATH, "//button[@class='side-menu__action']"), condition=EC.element_to_be_clickable)
time.sleep(1) # Simulate human delay
my_account_button.click()
edit_button = wait_for_element(driver, (By.XPATH, "//*[contains(@class, '_pen_a31cg_31')]"), condition=EC.element_to_be_clickable)
time.sleep(1) # Simulate human delay
edit_button.click()
# Wait for the username input, clear and update it
username_input = wait_for_element(driver, (By.XPATH, "//input[@data-testid='nicknameInput']"))
time.sleep(1) # Simulate human delay
username_input.click()
time.sleep(0.5) # Simulate human delay
username_input.send_keys(Keys.CONTROL + "a")
time.sleep(0.5) # Simulate human delay
username_input.send_keys(Keys.DELETE)
random_username = ''.join(random.choices(string.ascii_letters + string.digits, k=8)) # Generate a random username with 8 characters containing letters and digits
time.sleep(1) # Simulate human delay
username_input.send_keys(random_username)
random_number = random.randint(0, 19) # Selects a random number between 0 and 19
avatar_button = wait_for_element(driver, (By.XPATH, f"//div[@data-testid='avatar-image-{random_number}']"), condition=EC.element_to_be_clickable)
time.sleep(1) # Simulate human delay
avatar_button.click()
apply_button = wait_for_element(driver, (By.XPATH, "//button[.//div[@class='button__content' and text()='Apply']]"),condition=EC.element_to_be_clickable)
time.sleep(1) # Simulate human delay
apply_button.click()
time.sleep(2) # Allow the changes to apply
return random_username
# Validates the updated username
def validate_user_name(driver, expected_username):
my_profile_button = wait_for_element(driver, (By.XPATH, "//button[@class='button button--light']"), condition=EC.element_to_be_clickable)
time.sleep(1) # Simulate human delay
my_profile_button.click()
displayed_username = wait_for_element(driver, (By.XPATH, "//div[@data-testid='my-profile-nickname']"))
actual_username = displayed_username.text
time.sleep(2) # Simulate human delay
# Validate that the username matches the expected value
if actual_username == expected_username:
print(f"Validation successful: Username has been updated to '{actual_username}'.")
else:
print(f"Validation failed: Expected username '{expected_username}', but found '{actual_username}'.")
my_profile_close_button = wait_for_element(driver, (By.XPATH, "//button[@data-testid='closeButton']"),condition=EC.element_to_be_clickable)
my_profile_close_button.click()
time.sleep(2) # Allow the page to load
# Return to the main screen
body = driver.find_element(By.TAG_NAME, "body")
body.send_keys(Keys.ESCAPE)
time.sleep(2) # Simulate human delay
# Retrieves the coin amounts
def get_coins_amount(driver):
yellow_coin = wait_for_element(driver, (By.XPATH, "//div[@data-testid='lobby-balance-bar']"), condition=EC.element_to_be_clickable)
print(f"Yellow Coins: {yellow_coin.text}")
coin_switcher = wait_for_element(driver, (By.XPATH, "//div[@data-testid='coin-switcher']"), condition=EC.element_to_be_clickable)
coin_switcher.click()
time.sleep(2)
green_coin = wait_for_element(driver, (By.XPATH, "//div[@data-testid='lobby-balance-bar']"),condition=EC.element_to_be_clickable)
print(f"Green Coins: {green_coin.text}")
# Handles live chat in the support popup
def bonus_function(driver):
menu_button = wait_for_element(driver, (By.XPATH, "//button[@data-testid='menuButton']"),condition=EC.element_to_be_clickable)
time.sleep(1) # Simulate human delay
menu_button.click()
my_account_button = wait_for_element(driver, (By.XPATH, "//button[@class='side-menu__action']"),condition=EC.element_to_be_clickable)
time.sleep(1) # Simulate human delay
my_account_button.click()
support_button = wait_for_element(driver, (By.XPATH, "//button[.//div[@class='button__content' and text()='SUPPORT']]"),condition=EC.element_to_be_clickable)
time.sleep(2) # Simulate human delay
support_button.click()
# Locate and switch to the iframe for interacting with the live chat
iframe = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.NAME, "intercom-messenger-frame")))
driver.switch_to.frame(iframe)
print("Switched to iframe.")
help_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='intercom-1cro9wu e4hvvep2']")))
time.sleep(2) # Simulate human delay
help_button.click()
input_field = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//input[@aria-label='Search for help']")))
message = "I would like to work with you :)"
input_field.send_keys(message)
print(f"Typed message: {message}")
input_field.send_keys(Keys.RETURN)
print("Pressed Enter.")
time.sleep(5)
close_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@aria-label='Close' and @role='button']")))
close_button.click()
time.sleep(2) # Simulate human delay
# Switch back to the main DOM after interacting with the iframe
driver.switch_to.default_content()
print("Switched back to main DOM.")
# Return to the main screen
body = driver.find_element(By.TAG_NAME, "body")
body.send_keys(Keys.ESCAPE)
# Checks if the browser is open
def is_browser_open(driver):
try:
driver.current_url
return True
except:
return False
# Main function to execute all steps
def main(url, email, password):
try:
driver = open_url(url)
login(driver, email, password)
new_user_name = update_profile(driver)
validate_user_name(driver,new_user_name)
get_coins_amount(driver)
bonus_function(driver)
print("The browser is open, Close it manually to stop the script")
while is_browser_open(driver):
pass
print("The browser was closed, Stopping the script.")
except Exception as e:
print(f"An error occurred: {e}")
finally:
try:
driver.quit()
except:
pass
main(url, email, password)