Both of water first figure

Iphone12/13 Snap up automated test scripts

Said in the previous

Core content of this paper

  1. Iphone13 available notify NodeJs script
  2. Python +selenium automated test scripts for iphone13
  3. Python +selenium automated test scripts for iphone12 reservation purchase

The cause of

First of all, this vegetable dog is not a professional evaluation, the cause is just because of the brush news, to see the overwhelming news: 13 how sweet, how good high brush, how tight supply, simply can not grab and so on. As a curious dog, I just want to see if this is true or just a gimmick!

start

  1. Log on to apple’s official website and see the big Apple

It looks good, but the price is touching

2. Go and see if there is any goods, how to pick up the goods from stock, and when will the express arrive

It seems that the supply of goods is really tight, almost until Christmas, and there is no stock, we can only buy online, maybe what the Internet said is true?

3. Find out

I chose to pick up the goods, how brush brush can not come out, the surface looks like there is no goods!

Use the code

In order to solve the problem of not being able to grab or get timely notification of availability, the following solutions are adopted!

1. Notify NodeJs script when iphone13 is available

Send an email notification when it’s available and snap it up by hand

Js code
/*
 * @Author: JavaDog
 * @Date: 2021-09-19 21:22:49
 * @LastEditTime: 2021-10-12 14:55:49
 * @Description: iphone13 pro 银色 256g/512g
 * @FilePath: apple13.js
 */
var https = require("https");
var http = require("http");
var querystring = require("querystring");
var request = require("request");
// Is there a shipping address? Can you replace it with the model you want
let url = [
  "https://www.apple.com.cn/shop/fulfillment-messages?pl=true&mt=compact&parts.0=MLTG3CH/A&searchNearby=true&store=R557"."https://www.apple.com.cn/shop/fulfillment-messages?pl=true&mt=compact&parts.0=MLTC3CH/A&searchNearby=true&store=R557",];// Loop timer
setInterval(() = > {
  url.forEach((item) = > {
    https.get(item, function (response) {
      var body = [];
      response.on("data".function (chunk) {
        body.push(chunk);
      });
      response.on("end".function () {
        body = Buffer.concat(body);
        let json = JSON.parse(body.toString());
        let content = json.body.content;
        let pickupMessage = content.pickupMessage;
        let store = pickupMessage.stores[0];
        let partsAvailability = store.partsAvailability;
        let obj =
          partsAvailability["MLTG3CH/A"] ||
          partsAvailability["MLTC3CH/A"] ||
          partsAvailability["MLTJ3CH/A"] ||
          partsAvailability["MLTE3CH/A"];
        let pickupDisplay = obj.pickupDisplay;
        let storePickupProductTitle = obj.storePickupProductTitle;
        let pickupSearchQuote = obj.pickupSearchQuote;
        // Add important parameters
        let result =
          storePickupProductTitle +
          "" +
          pickupDisplay +
          "" +
          pickupSearchQuote +
          "" +
          new Date(a);if(pickupDisplay ! ="unavailable" || pickupDisplay == "available") {
          / / in stock
          console.log(result);
          // Note here, please change to your own mail sending server, or other notification platform, my own is ali cloud mailbox
          mail(result, storePickupProductTitle);
        } else {
          / / not available
          console.log(result); }}); }); }); },1000);

// Stock email alert
function mail(noSimilarModelsText, storePickupProductTitle) {
  var options = {
    headers: {
      "Content-Type": "application/json"."admin-authorization": "dfaf86e4e45f4906a6ef8d180efba1c0",},url: "https://blog.javadog.net/api/admin/mails/test".method: "POST".json: true.body: {
      to: "[email protected]".subject: storePickupProductTitle,
      content: noSimilarModelsText,
    },
  };

  function callback(error, response, data) {
    console.log("----info------", data);
  }
  request(options, callback);
}

Copy the code
Start the

node apple.js

Js command. The node must be installed. If the node is not installed, see the following figure for details about how to install and configure Node.js. To place the server to start, refer to the PM2 Application Process Manager.

conclusion

After placing the server for 24 hours non-stop test:There is still a small amount of spot every day, but only between 9 and 12 o ‘clock in the morning, the amount of spot every day is about 1-5 or so (Qingdao area test), the second kill time is basically within half a minute, otherwise immediately out of stock

2. Iphone12 Buy Python + Selenium Automated test scripts (Chrome only)

Let the code handle it for us through Python + Selenium automation. Here with iPhone 12 as a process demonstration, because 12 basic need not buy, process can run through 😂 this food dog has not contacted Python before, write garbage please big guy do not spray!

precondition

For more information about Python+Selenium, see Python+Selenium Basics and Practices

Pay attention to

If there is nochromedriver.exePlease follow Google Chrome version matching rules to select! I amGoogle version 94.0.4606.81 32 bitsClick to download my ownchromedriver.exe Bear in mind thatChromedriver.exe depends if not 32 bitsI mightThe following error

WebDriverException:Message:unknown error:cannot find Chrome binary

Python code
from selenium import webdriver
from datetime import datetime
from selenium.webdriver.support.select import Select
import time

# iphone12 Automated testing
print("Iphone12 automated testing begins.")

Access the url definition of the test
url = "https://www.apple.com.cn/shop/buy-iphone/iphone-12"

The variable in Chrome here is the driver address of the ChromeDriver
driver = webdriver.Chrome()

# 2. Jump to apple's official website
driver.get(url)

# 3. Implicit wait Settings prevent network congestion of presales
driver.implicitly_wait(10)

# 4.1 Start to select the size [here I chose -12 mini]
element_sku = driver.find_element_by_name('dimensionScreensize')
driver.implicitly_wait(10)
element_sku.click()

# 4.2 Select color [here I chose - white]
element_color = driver.find_element_by_xpath(
    '//*[@value="white"]')
driver.execute_script("arguments[0].click();", element_color)
driver.implicitly_wait(10)

# 4.3 Select memory
element_memory = driver.find_element_by_xpath(
    '//*[@value="256gb"]')
driver.execute_script("arguments[0].click();", element_memory)
driver.implicitly_wait(10)

# 4.4 Do you have a smartphone to discount [I chose here - no old phone discounts]
element_old = driver.find_element_by_xpath('//*[@id="noTradeIn"]')
driver.execute_script("arguments[0].click();", element_old)
driver.implicitly_wait(10)

# 4.5 Applecare
element_care = driver.find_element_by_id('applecareplus_58_noapplecare_label')
driver.execute_script("arguments[0].click();", element_care)
driver.implicitly_wait(10)

# 4.6 Add to shopping bag
element_car = driver.find_element_by_xpath(
    '//*[@value="add-to-cart"]')
driver.execute_script("arguments[0].click();", element_car)
driver.implicitly_wait(10)

# 5 Jump to the shopping bag
element_check = driver.find_element_by_xpath(
    '//*[@value="proceed"]')
driver.execute_script("arguments[0].click();", element_check)
driver.implicitly_wait(10)

# 6 checkout
element_check_out = driver.find_element_by_xpath(
    '//*[@id="shoppingCart.actions.navCheckout"]')
driver.execute_script("arguments[0].click();", element_check_out)
driver.implicitly_wait(10)

Enter a user name
element_username = driver.find_element_by_id(
    'signIn.customerLogin.appleId')
element_username.send_keys('appleId account')
driver.implicitly_wait(10)

# 7.2 Enter a password
element_password = driver.find_element_by_id(
    'signIn.customerLogin.password')
element_password.send_keys('password')
driver.implicitly_wait(10)

# 7.3 Click Login
element_login = driver.find_element_by_id(
    'signin-submit-button')
element_login.click()
driver.implicitly_wait(10)

# 8.1 How would you like to receive the order?
element_want_order = driver.find_element_by_id(
    'fulfillmentOptionButtonGroup1')
driver.execute_script("arguments[0].click();", element_want_order)
driver.implicitly_wait(10)

Click to display retail stores near here
element_selectdistrict = driver.find_element_by_xpath(
    '//*[@aria-describedby="rs-fulfillment-storelocator-error"]')
driver.execute_script("arguments[0].click();", element_selectdistrict)
driver.implicitly_wait(10)

# 8.3 Click shandong
element_provice = driver.find_element_by_xpath(
    '/ / * [@ value = "shandong"]')
driver.execute_script("arguments[0].click();", element_provice)
driver.implicitly_wait(10)

# 8.4 Click Qingdao
element_city = driver.find_element_by_xpath(
    '/ / * [@ value = "Qingdao"]')
driver.execute_script("arguments[0].click();", element_city)
driver.implicitly_wait(10)

# 8.5 Click south of the city
element_area = driver.find_element_by_xpath(
    '//*[@value=" "]')
driver.execute_script("arguments[0].click();", element_area)
driver.implicitly_wait(20)

# 8.6 Select pick up retail store [here I choose -Apple Mixc Qingdao]
element_pickupTab = driver.find_element_by_id(
    'checkout.fulfillment.pickupTab.pickup.storeLocator-R557')
driver.execute_script("arguments[0].click();", element_pickupTab)
driver.implicitly_wait(20)

# 8.7 Pick up time
element_pickup_time = driver.find_element_by_xpath(
    '//*[@value="11"]')
driver.execute_script("arguments[0].click();", element_pickup_time)
driver.implicitly_wait(10)

# 8.8 Select delivery time [here I select - default first time]
element_time_quantum = driver.find_element_by_xpath(
    '//*[@aria-labelledby="timeWindows_label"]')
Select(element_time_quantum).select_by_index(1)
driver.implicitly_wait(15)

# 8.9 Continue to fill in the pickup details
element_checkout = driver.find_element_by_id(
    'rs-checkout-continue-button-bottom')
driver.implicitly_wait(15)
driver.execute_script("arguments[0].click();", element_checkout)
element_checkout.click()
driver.implicitly_wait(10)

Please enter the recipient's mobile phone number
element_Phone = driver.find_element_by_name('fullDaytimePhone')
element_Phone.send_keys('Mobile phone Number')
driver.implicitly_wait(10)

Please fill in recipient id card
element_nationalId = driver.find_element_by_name('nationalId')
element_nationalId.send_keys(Identity card)
driver.implicitly_wait(10)

Check the order
element_checkoutPay = driver.find_element_by_id(
    'rs-checkout-continue-button-bottom')
driver.execute_script("arguments[0].click();", element_checkoutPay)
driver.implicitly_wait(10)

# 10 Place your order now [here I chose wechat Pay]
element_billingOptions = driver.find_element_by_id(
    'checkout.billing.billingOptions.options.2')
driver.execute_script("arguments[0].click();", element_billingOptions)
driver.implicitly_wait(10)

# 11.1 determine
element_orderPay = driver.find_element_by_id(
    'rs-checkout-continue-button-bottom')
driver.execute_script("arguments[0].click();", element_orderPay)
driver.implicitly_wait(15)

Confirm the order
element_endPay = driver.find_element_by_xpath(
    '//*[@aria-describedby="rs-checkout-continuedisclaimer-bottom"]')
driver.execute_script("arguments[0].click();", element_endPay)
driver.implicitly_wait(15)

Exit the browser
time.sleep(10)
# driver.quit()

print("Automated testing of iphone12 completed.")
Copy the code
Start the

python apple-12.py

Fully automatic operation process GIF

Tip

The account and password need to be replaced with your own, and there will be delays and 403 anomalies on apple’s official website, which is normal.

3. Python +selenium automated test scripts for iphone13 reservation purchase

The preconditions are the same as the iPhone 12
Tips

Because iphone13 is out of stock, a while judgment is added to the code, which repeatedly pulls provinces and cities to reload whether there is stock or not

Python code
from selenium import webdriver
from datetime import datetime
from selenium.webdriver.support.select import Select
import pdb
import time

# iphone13 Automated testing
print("Iphone13 automated testing begins.")

Access the url definition of the test
url = "https://www.apple.com.cn/shop/buy-iphone/iphone-13-pro"

The variable in Chrome here is the driver address of the ChromeDriver
driver = webdriver.Chrome()

# 2. Jump to apple's official website
driver.get(url)

# 3. Implicit wait Settings prevent network congestion of presales
driver.implicitly_wait(10)

# 4. Start selecting the spec [here I chose -13 Pro]
element_sku = driver.find_element_by_name('dimensionScreensize')
driver.implicitly_wait(10)
element_sku.click()

# 4.2 Select color [here I chose - silver]
element_color = driver.find_element_by_xpath(
    '//*[@value="silver"]')
driver.execute_script("arguments[0].click();", element_color)
driver.implicitly_wait(10)

# 4.3 Select memory
element_memory = driver.find_element_by_xpath(
    '//*[@value="256gb"]')
driver.execute_script("arguments[0].click();", element_memory)
driver.implicitly_wait(10)

# 4.4 Do you have a smartphone to discount [I chose here - no old phone discounts]
element_old = driver.find_element_by_xpath('//*[@id="noTradeIn"]')
driver.execute_script("arguments[0].click();", element_old)
driver.implicitly_wait(10)

# 4.5 Applecare
element_care = driver.find_element_by_id('iphonexs_ac_iup_noapplecare_label')
driver.execute_script("arguments[0].click();", element_care)
driver.implicitly_wait(10)

# 4.6 Add to shopping bag
element_car = driver.find_element_by_xpath(
    '//*[@value="add-to-cart"]')
driver.execute_script("arguments[0].click();", element_car)
driver.implicitly_wait(10)

# 5 Jump to the shopping bag
element_check = driver.find_element_by_xpath(
    '//*[@id="root"]/div[2]/div/div/div[2]/div/form/button')
driver.execute_script("arguments[0].click();", element_check)
driver.implicitly_wait(10)

# 6 checkout
element_check_out = driver.find_element_by_xpath(
    '//*[@id="shoppingCart.actions.checkout"]')
driver.execute_script("arguments[0].click();", element_check_out)
driver.implicitly_wait(10)

Enter a user name
element_username = driver.find_element_by_id(
    'signIn.customerLogin.appleId')
element_username.send_keys('apple appleId)
driver.implicitly_wait(10)

# 7.2 Enter a password
element_password = driver.find_element_by_id(
    'signIn.customerLogin.password')
element_password.send_keys('password')
driver.implicitly_wait(10)

# 7.3 Click Login
element_login = driver.find_element_by_id(
    'signin-submit-button')
element_login.click()
driver.implicitly_wait(10)

# 8.1 How would you like to receive the order?
element_want_order = driver.find_element_by_id(
    'fulfillmentOptionButtonGroup1')
driver.execute_script("arguments[0].click();", element_want_order)
driver.implicitly_wait(10)

Click to display retail stores near here
selectdistrict = driver.find_element_by_xpath(
    '//*[@aria-describedby="rs-fulfillment-storelocator-error"]')
driver.execute_script("arguments[0].click();", selectdistrict)
driver.implicitly_wait(10)

# 8.3 Click shandong
element_provice = driver.find_element_by_xpath(
    '/ / * [@ value = "shandong"]')
driver.execute_script("arguments[0].click();", element_provice)
driver.implicitly_wait(10)

# 8.4 Click Qingdao
element_city = driver.find_element_by_xpath(
    '/ / * [@ value = "Qingdao"]')
driver.execute_script("arguments[0].click();", element_city)
driver.implicitly_wait(10)

# 8.5 Click south of the city
element_area = driver.find_element_by_xpath(
    '//*[@value=" "]')
driver.execute_script("arguments[0].click();", element_area)
driver.implicitly_wait(20)

# Because there is no stock you need to determine if the element is clickable
isOK = driver.find_element_by_id(
    'checkout.fulfillment.pickupTab.pickup.storeLocator-R557').is_enabled()
isOKFlag = bool(1 - isOK)
#print(" isOKFlag "+ STR (isOKFlag)

# while loop to see if there is stock
while isOKFlag:
    try:
        # recall the province
        #print(" isOKFlag "+ STR (isOKFlag))
        driver.implicitly_wait(20)
        selectdistrict = driver.find_element_by_xpath(
            '//*[@aria-describedby="rs-fulfillment-storelocator-error"]')
        driver.execute_script("arguments[0].click();", selectdistrict)

        driver.implicitly_wait(20)
        provice = driver.find_element_by_xpath(
            '/ / * [@ value = "shandong"]')
        driver.execute_script("arguments[0].click();", provice)

        city = driver.find_element_by_xpath(
            '/ / * [@ value = "Qingdao"]')
        driver.execute_script("arguments[0].click();", city)

        area = driver.find_element_by_xpath(
            '//*[@value=" "]')
        driver.execute_script("arguments[0].click();", area)

        driver.implicitly_wait(20)
        isOK = driver.find_element_by_id(
            'checkout.fulfillment.pickupTab.pickup.storeLocator-R557').is_enabled()
        isOKFlag = bool(1 - isOK)
        #print(" isOK "+ STR (isOKFlag))
    except:
        print("Abnormal")
        break

# Tips: It is verified that if there is no stock in the physical store on the official Website of Apple before the payment page, if there is stock in the physical store on the settlement page, there is no option to choose the physical store

# 8.6 Select pick up retail store [here I choose -Apple Mixc Qingdao]
element_pickupTab = driver.find_element_by_id(
    'checkout.fulfillment.pickupTab.pickup.storeLocator-R557')
driver.execute_script("arguments[0].click();", element_pickupTab)
driver.implicitly_wait(20)

# 8.7 Pick up time
element_pickup_time = driver.find_element_by_xpath(
    '//*[@value="11"]')
driver.execute_script("arguments[0].click();", element_pickup_time)
driver.implicitly_wait(10)

# 8.8 Select delivery time [here I select - default first time]
element_time_quantum = driver.find_element_by_xpath(
    '//*[@aria-labelledby="timeWindows_label"]')
Select(element_time_quantum).select_by_index(1)
driver.implicitly_wait(15)

# 8.9 Continue to fill in the pickup details
element_checkout = driver.find_element_by_id(
    'rs-checkout-continue-button-bottom')
driver.implicitly_wait(15)
driver.execute_script("arguments[0].click();", element_checkout)
element_checkout.click()
driver.implicitly_wait(20)

Please enter the recipient's mobile phone number
element_Phone = driver.find_element_by_name('fullDaytimePhone')
element_Phone.send_keys('phone')
driver.implicitly_wait(10)

Please fill in recipient id card
element_nationalId = driver.find_element_by_name('nationalId')
element_nationalId.send_keys('Id Number')
driver.implicitly_wait(10)

Check the order
element_checkoutPay = driver.find_element_by_id(
    'rs-checkout-continue-button-bottom')
driver.execute_script("arguments[0].click();", element_checkoutPay)
driver.implicitly_wait(10)

# 10 Place your order now [here I chose wechat Pay]
element_billingOptions = driver.find_element_by_id(
    'checkout.billing.billingOptions.options.2')
driver.execute_script("arguments[0].click();", element_billingOptions)
driver.implicitly_wait(10)

# 11.1 determine
element_orderPay = driver.find_element_by_id(
    'rs-checkout-continue-button-bottom')
driver.execute_script("arguments[0].click();", element_orderPay)
driver.implicitly_wait(15)

Confirm the order
element_endPay = driver.find_element_by_xpath(
    '//*[@aria-describedby="rs-checkout-continuedisclaimer-bottom"]')
driver.execute_script("arguments[0].click();", element_endPay)
driver.implicitly_wait(15)

Exit the browser
time.sleep(10)
# driver.quit()

print("Automated testing of iphone13 is over.")
Copy the code
Start the

python apple-13.py

Fully automatic operation process GIF

Script results

Write in the last

The above orders are for testing purposes, our food dog did not buy iPhone, also hope that we still support more domestic products, no targeting, no moral kidnapping, just hope that our country’s products are more and more excellent ❤️

I am JavaDog, thank you for your patience, take the time to come to my doghouse 🐕 check out blog.javadog.net