瀏覽代碼

cpr traffic

main
kusum 6 月之前
父節點
當前提交
3cb8234e23
共有 2 個檔案被更改,包括 103 行新增0 行删除
  1. 59
    0
      GSAutomation/scripts/cpr_trafficscript1.py
  2. 44
    0
      GSAutomation/scripts/cpr_trafficscript2.py

+ 59
- 0
GSAutomation/scripts/cpr_trafficscript1.py 查看文件

@@ -0,0 +1,59 @@
#!/usr/bin/env python3

import time
from selenium import webdriver
from selenium.webdriver.common.by import By

def search_for_dress(driver, user_id):
url = f'https://{user_id}.cpr-akashop.com/'
driver.get(url)
time.sleep(1)
# Find and click on the magnifying glass icon
magnifying_glass = driver.find_element(By.CSS_SELECTOR, '#header-grid > nav.header--row.header-main.hide-on-mobile.hide-on-tablet.layout-full-contained.nv-navbar.header--row > div > div > div > div.hfg-slot.right > div > div.item--inner.builder-item--header_search_responsive > div > div > a > svg')
magnifying_glass.click()
time.sleep(1)
# Find the search box and search for "dress"
search_box = driver.find_element(By.CSS_SELECTOR, '#header-grid > nav.header--row.header-main.hide-on-mobile.hide-on-tablet.layout-full-contained.nv-navbar.header--row > div > div > div > div.hfg-slot.right > div > div.item--inner.builder-item--header_search_responsive > div > div > div > div.form-wrap > form > input')
search_box.send_keys('dress')
search_box.submit()
time.sleep(3)
# 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)
# Add the Striped Dress to the cart
add_to_cart_button = driver.find_element(By.CSS_SELECTOR, '#product-82 > div.nv-single-product-top > div.summary.entry-summary > form > button')
add_to_cart_button.click()
time.sleep(3)
# Click on View Cart
view_cart_button = driver.find_element(By.CSS_SELECTOR, '#content > div > div > div > div.woocommerce-notices-wrapper > div > a')
view_cart_button.click()
time.sleep(3)
# 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: ") # Ask for the user ID only once
main(user_id)

+ 44
- 0
GSAutomation/scripts/cpr_trafficscript2.py 查看文件

@@ -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()

Loading…
取消
儲存