CODEX : automation coding trails

·

2 min read

Table of contents

No heading

No headings in the article.

Have you ever thought about automating your tests using Artificial Intelligence? Open AI is a platform with the aim of bringing the power of artificial intelligence to everyone. It provides tools and resources that let you develop & run advanced AIs within minutes instead of months or years.

i haven't had much exposure with open ai playground , all kept hearing was , how intelligent and smart it was . until now , i tried some automation code with CODEX : davinci , and it is un-believable .

take a look .

write an selenium automation python code to buy the product in the below link = bestbuy.com/site/nvidia-geforce-rtx-3070-8g.. ,model should should wait for the product to be available then add to cart then buy product , include comments for every line of code and assume best buy account is logged in and required info is already in account .

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

#create webdriver object and maximize window
driver = webdriver.Chrome()
driver.maximize_window()

#navigate to the page
driver.get("https://www.bestbuy.com/site/nvidia-geforce-rtx-3070-8gb-gddr6-pci-express-4-0-graphics-card-dark-platinum-and-black/6429442.p?skuId=6429442")

#wait until product is available
wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@class='button button--primary']")))

#add product to cart
element.click()

#click on cart
cart = driver.find_element_by_xpath("//button[@class='button button--primary']")
cart.click()

#click on checkout
checkout = driver.find_element_by_xpath("//button[@class='button button--primary button--checkout']")
checkout.click()

#click on continue as guest
guest = driver.find_element_by_xpath("//button[@class='button button--primary button--checkout']")
guest.click()

#fill out personal information
driver.find_element_by_id("guest-first-name").send_keys("FirstName")
driver.find_element_by_id("guest-last-name").send_keys("LastName")
driver.find_element_by_id("guest-email").send_keys("Email@email.com")
driver.find_element_by_id("guest-confirm-email").send_keys("Email@email.com")
driver.find_element_by_id("guest-phone-number").send_keys("1234567890")

#click on continue
continue_btn = driver.find_element_by_xpath("//button[@class='button button--primary button--large']")
continue_btn.click()

#fill out shipping information
driver.find_element_by_id("address-first-name").send_keys("FirstName")
driver.find_element_by_id("address-last-name").send_keys("LastName")
driver.find_element_by_id("address-line1").send_keys("123 Address")
driver.find_element_by_id("address-line2").send_keys("Apt 123")
driver.find_element_by_id("address-city").send_keys("City")
driver.find_element_by_id("address-state").send_keys("State")
driver.find_element_by_id("address-postal-code").send_keys("12345")


#click on continue
continue_btn = driver.find_element_by_xpath("//button[@class='button button--primary button--large']")
continue_btn.click()

#click on continue to payment
continue_btn = driver.find_element_by_xpath("//button[@class='button button--primary button--large']")
continue_btn.click()

#fill out payment information
driver.find_element_by_id("payment-method-cc-number").send_keys("1234567890123456")
driver.find_element_by_id("payment-method-cc-exp-month").send_keys("12")
driver.find_element_by_id("payment-method-cc-exp-year").send_keys("2022")
driver.find_element_by_id("payment-method-cc-cvc").send_keys("123")

#click on continue to review
continue_btn = driver.find_element_by_xpath("//button[@class='button button--primary button--large']")
continue_btn.click()

#click on agree to terms
terms = driver.find_element_by_xpath("//label[@class='checkbox-label']")
terms.click()

#click on place order
order = driver.find_element_by_xpath("//button[@class='button button--primary button--large']")
order.click()

i haven't tried to run it but will do . i will update this again after that .