ก็จะกลายเป็นแบบนี้ save เป็นไฟล์ชื่อว่า test_login2.py
# Generated by Selenium IDE
import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
class TestLogin():
def setup_method(self, method):
self.driver = webdriver.Chrome(executable_path=r"C:\chromedriver.exe")
self.vars = {}
def teardown_method(self, method):
self.driver.quit()
def test_login(self):
# Test name: login
# Step # | name | target | value
# 1 | open | https://www.facebook.com/ |
self.driver.get("https://www.facebook.com/")
# 2 | setWindowSize | 974x1050 |
self.driver.set_window_size(974, 1050)
# 3 | click | id=email |
self.driver.find_element(By.ID, "email").click()
# 4 | click | id=email |
self.driver.find_element(By.ID, "email").click()
# 5 | type | id=email | username
self.driver.find_element(By.ID, "email").send_keys("username")
# 6 | type | id=pass | pass
self.driver.find_element(By.ID, "pass").send_keys("pass")
obj = TestLogin()
obj.setup_method(obj)
obj.test_login()
แล้วเราลองนำ code นี้ไป run ดูใน command line
python test_login2.py
ก็จะเห็นว่าตัว Selenium จะทำการเปิด Chrome (จะเห็นว่ามีขึ้นว่า Chrome is being controlled by automated test software) แล้วทำงานตาม command ที่เราเขียนอัตโนมัติแล้วละ