Parcourir la source

cpr changes

main
kusum il y a 10 mois
Parent
révision
d0a76ee31f
2 fichiers modifiés avec 59 ajouts et 7 suppressions
  1. 15
    7
      GSAutomation/scripts/cpr_labscript1.py
  2. 44
    0
      GSAutomation/scripts/cpr_labscript2.py

GSAutomation/scripts/cpr_labscript.py → GSAutomation/scripts/cpr_labscript1.py Voir le fichier

@@ -5,7 +5,6 @@ from selenium import webdriver
from selenium.webdriver.common.by import By

def search_for_dress(driver, user_id):
driver.maximize_window()
url = f'https://{user_id}.cpr-akashop.com/'
driver.get(url)
time.sleep(1)
@@ -23,6 +22,9 @@ def search_for_dress(driver, user_id):
# Find and click on the Striped Dress search result
striped_dress_link = driver.find_element(By.CSS_SELECTOR, '#post-82 > div > div > div > div.non-grid-content.alternative-layout-content > h2 > a')
# Scroll to the element
driver.execute_script("arguments[0].scrollIntoView(true);", striped_dress_link)
time.sleep(1) # Add a small delay after scrolling
striped_dress_link.click()
time.sleep(3)
@@ -36,16 +38,22 @@ def search_for_dress(driver, user_id):
view_cart_button.click()
time.sleep(3)
# Click on Proceed to Checkout
# Scroll to the Proceed to Checkout button
proceed_to_checkout_button = driver.find_element(By.CSS_SELECTOR, '#content > div > div > div > div.nv-content-wrap.entry-content > div > div.cart-collaterals > div > div > a')
driver.execute_script("arguments[0].scrollIntoView(true);", proceed_to_checkout_button)
time.sleep(1) # Add a small delay after scrolling
# Click on Proceed to Checkout
proceed_to_checkout_button.click()
time.sleep(3)

def main(user_id):
# Chrome
driver = webdriver.Chrome()
search_for_dress(driver, user_id)
driver.quit()

if __name__ == "__main__":
user_id = input("Please enter your user ID: ")
user_id = input("Please enter your user ID: ") # Ask for the user ID only once
# Chrome
driver = webdriver.Chrome()
search_for_dress(driver, user_id)
main(user_id)

+ 44
- 0
GSAutomation/scripts/cpr_labscript2.py Voir le fichier

@@ -0,0 +1,44 @@
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
import time

# Function to prompt user for user ID
def get_user_id():
return input("Please enter your user ID: ")

# Set up Chrome options
chrome_options = Options()
chrome_options.add_argument("--headless") # Run headless Chrome, comment out if you want to see the browser

# Use WebDriverManager to automatically use the system's ChromeDriver
service = ChromeService(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service, options=chrome_options)

# Prompt user for user ID
user_id = get_user_id()

# List of paths to test
paths = ['/', '/shop/', '/product/blue-sweater/', '/product/custom-tee/', '/product-category/clothing/dresses/']

# Base URL
base_url = f'http://{user_id}.cpr-akashop.com'

# Function to measure load time
def measure_load_time(url):
start_time = time.time()
driver.get(url)
# Wait for the page to completely load (adjust as necessary)
time.sleep(5) # Simple wait; use WebDriverWait for more precise control
end_time = time.time()
return end_time - start_time

# Test each path
for path in paths:
full_url = base_url + path
load_time = measure_load_time(full_url)
print(f"Load time for {full_url}: {load_time:.2f} seconds")

# Close the driver
driver.quit()

Chargement…
Annuler
Enregistrer