Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions asynchronous/01_Navigate_Url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""
Learn to navigate to a URL using Selenium

DISCLAIMER: This code is aimed at Selenium BEGINNERS
For more advanced tutorials and to learn how Qxf2 writes GUI automation, please visit our:
a) Our GUI automation guides: http://qxf2.com/gui-automation-diy
b) Other GitHub repos: https://github.com/qxf2

AUTHOR: Douglas Cardoso
Contact: https://github.com/douglasdcm

SCOPE:
1) Launch Firefox Driver
2) Navigate to Qxf2 Tutorial page
3) Check the page title
4) Close the browser
"""
from caqui.caqui import AsyncDriver
from caqui.by import By
import asyncio

# Create an instance of WebDriver
# To run the webdriver, run "./chromedriver --port=9999"
remote = "http://127.0.0.1:9999"
capabilities = {
"desiredCapabilities": {
By.NAME: "webdriver",
"browserName": "chrome",
"acceptInsecureCerts": True,
# "goog:chromeOptions": {"extensions": [], "args": ["--headless"]},
}
}
browser = AsyncDriver(remote, capabilities)

# KEY POINT: The driver.get method will navigate to a page given by the URL
get_task = browser.get('http://qxf2.com/selenium-tutorial-main')
asyncio.run(get_task)

# Check if the title of the page is proper
if(browser.title=="Qxf2 Services: Selenium training main"):
print ("Success: Qxf2 Tutorial page launched successfully")
else:
print ("Failed: Qxf2 Tutorial page Title is incorrect")

# Quit the browser window
browser.quit()
73 changes: 73 additions & 0 deletions asynchronous/02_Fill_Text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
Learn to fill text fields with Selenium

DISCLAIMER: This code is aimed at Selenium BEGINNERS
For more advanced tutorials and to learn how Qxf2 writes GUI automation, please visit our:
a) Our GUI automation guides: http://qxf2.com/gui-automation-diy
b) Other GitHub repos: https://github.com/qxf2

AUTHOR: Douglas Cardoso
Contact: https://github.com/douglasdcm

SCOPE:
1) Launch Firefox Driver
2) Navigate to Qxf2 Tutorial page
3) Find elements using id, xpath, xpath without id
4) Fill name, email and phone no in the respective fields
5) Close the browser
"""
import asyncio
from caqui.caqui import AsyncDriver
from caqui.by import By

async def demo():
# Create an instance of WebDriver
# To run the webdriver, run "./chromedriver --port=9999"
remote = "http://127.0.0.1:9999"
capabilities = {
"desiredCapabilities": {
By.NAME: "webdriver",
"browserName": "chrome",
"acceptInsecureCerts": True,
# "goog:chromeOptions": {"extensions": [], "args": ["--headless"]},
}
}

# The driver.get method will navigate to a page given by the URL
driver = AsyncDriver(remote, capabilities)
await driver.get("http://qxf2.com/selenium-tutorial-main")

# Check if the title of the page is proper
if(driver.title=="Qxf2 Services: Selenium training main"):
print ("Success: Qxf2 Tutorial page launched successfully")
else:
print ("Failure: Qxf2 Tutorial page Title is incorrect")

# Find the name field using xpath with id
name = driver.find_element(By.XPATH, "//input[@id='name']")

# Find the email field using xpath without id
email = driver.find_element(By.XPATH, "//input[@name='email']")

# Find the phone no field using id
phone = driver.find_element("id", "phone")

# Run all commands concurrently
name, email, phone = await asyncio.gather(name, email, phone)

# KEY POINT: Send text to an element using send_keys method
await asyncio.gather(
name.send_keys('Avinash'),
email.send_keys('avinash@qxf2.com'),
phone.send_keys('9999999999'),
)

# Sleep is one way to wait for things to load
# Future tutorials cover explicit, implicit and ajax waits
await asyncio.sleep(3)

# Close the browser window
driver.close()

if __name__ == "__main__":
asyncio.run(demo())
58 changes: 58 additions & 0 deletions asynchronous/03_Set_Dropdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""
Learn to set dropdowns with Selenium

DISCLAIMER: This code is aimed at Selenium BEGINNERS
For more advanced tutorials and to learn how Qxf2 writes GUI automation, please visit our:
a) Our GUI automation guides: http://qxf2.com/gui-automation-diy
b) Other GitHub repos: https://github.com/qxf2

AUTHOR: Douglas Cardoso
Contact: https://github.com/douglasdcm

SCOPE:
1) Launch Firefox Driver
2) Navigate to Qxf2 Tutorial page
3) Set Gender to Male in the Example Form
4) Close the browser
"""
import asyncio
from caqui.caqui import AsyncDriver
from caqui.by import By

async def demo():
# Create an instance of Firefox WebDriver
# To run the webdriver, run "./chromedriver --port=9999"
remote = "http://127.0.0.1:9999"
capabilities = {
"desiredCapabilities": {
By.NAME: "webdriver",
"browserName": "chrome",
"acceptInsecureCerts": True,
# "goog:chromeOptions": {"extensions": [], "args": ["--headless"]},
}
}
driver = AsyncDriver(remote, capabilities)

# Maximize the browser window
await driver.maximize_window()

# Navigate to Qxf2 Tutorial page
await driver.get("http://qxf2.com/selenium-tutorial-main")

# KEY POINT: Identify the dropdown and click on it
dropdown_element = await driver.find_element("xpath", "//button[@data-toggle='dropdown']")
await dropdown_element.click()
# Sleep is one way to pause while the page elements load
await asyncio.sleep(1)

# KEY POINT: Locate a particular option and click on it
await (await driver.find_element("xpath", "//a[text()='Male']")).click()
# Future tutorials cover explicit, implicit and ajax waits
await asyncio.sleep(3)

# Close the browser window
driver.close()
print("Finished")

if __name__ == "__main__":
asyncio.run(demo())
51 changes: 51 additions & 0 deletions asynchronous/04_Enable_Checkbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""
Learn to select a checkbox using Selenium

DISCLAIMER: This code is aimed at Selenium BEGINNERS
For more advanced tutorials and to learn how Qxf2 writes GUI automation, please visit our:
a) Our GUI automation guides: http://qxf2.com/gui-automation-diy
b) Other GitHub repos: https://github.com/qxf2

AUTHOR: Douglas Cardoso
Contact: https://github.com/douglasdcm

SCOPE:
1) Launch Firefox Driver
2) Navigate to Qxf2 Tutorial page
3) Find the Checkbox element in the Example form and enable it
4) Close the browser
"""
import asyncio
from caqui.caqui import AsyncDriver
from caqui.by import By

async def demo():
# Create an instance of WebDriver
# To run the webdriver, run "./chromedriver --port=9999"
remote = "http://127.0.0.1:9999"
capabilities = {
"desiredCapabilities": {
By.NAME: "webdriver",
"browserName": "chrome",
"acceptInsecureCerts": True,
# "goog:chromeOptions": {"extensions": [], "args": ["--headless"]},
}
}
driver = AsyncDriver(remote, capabilities)

# Maximize the browser window
await driver.maximize_window()
await driver.get("http://qxf2.com/selenium-tutorial-main")

# KEY POINT: Locate the checkbox and click on it
checkbox = await driver.find_element("xpath", "//input[@type='checkbox']")
await checkbox.click()

# Pause the script for 3 sec so you can confirm the check box was selected
await asyncio.sleep(3)

# Close the browser window
driver.close()

if __name__ == "__main__":
asyncio.run(demo())
52 changes: 52 additions & 0 deletions asynchronous/05_Click_Button.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""
Learn to click a button with Selenium

DISCLAIMER: This code is aimed at Selenium BEGINNERS
For more advanced tutorials and to learn how Qxf2 writes GUI automation, please visit our:
a) Our GUI automation guides: http://qxf2.com/gui-automation-diy
b) Other GitHub repos: https://github.com/qxf2

AUTHOR: Douglas Cardoso
Contact: https://github.com/douglasdcm

SCOPE:
1) Launch Chrome driver
2) Navigate to Qxf2 Tutorial page
3) Find the Click me! button and click on it
4) Close the driver
"""
import asyncio
from caqui.caqui import AsyncDriver
from caqui.by import By

async def demo():
# Create an instance of WebDriver
# To run the webdriver, run "./chromedriver --port=9999"
remote = "http://127.0.0.1:9999"
capabilities = {
"desiredCapabilities": {
By.NAME: "webdriver",
"browserName": "chrome",
"acceptInsecureCerts": True,
# "goog:chromeOptions": {"extensions": [], "args": ["--headless"]},
}
}
driver = AsyncDriver(remote, capabilities)

# Maximize the browser window
await driver.maximize_window()
# Navigate to Qxf2 Tutorial page
await driver.get("http://qxf2.com/selenium-tutorial-main")

# KEY POINT: Locate the button and click on it
button = await driver.find_element("xpath", "//button[text()='Click me!']")
await button.click()

# Pause the script to wait for page elements to load
await asyncio.sleep(3)

# Close the browser
driver.close()

if __name__ == "__main__":
asyncio.run(demo())
65 changes: 65 additions & 0 deletions asynchronous/06_Form_Validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""
Check for the presence of absence of page elements

DISCLAIMER: This code is aimed at Selenium BEGINNERS
For more advanced tutorials and to learn how Qxf2 writes GUI automation, please visit our:
a) Our GUI automation guides: http://qxf2.com/gui-automation-diy
b) Other GitHub repos: https://github.com/qxf2

AUTHOR: Douglas Cardoso
Contact: https://github.com/douglasdcm

SCOPE:
1) Launch Firefox driver
2) Navigate to Qxf2 Tutorial page
3) Find the Click me! button and click on it
4) Check for the validation message
5) Close the browser
"""
import asyncio
from caqui.caqui import AsyncDriver
from caqui.by import By

async def demo():
# Create an instance of WebDriver
# To run the webdriver, run "./chromedriver --port=9999"
remote = "http://127.0.0.1:9999"
capabilities = {
"desiredCapabilities": {
By.NAME: "webdriver",
"browserName": "chrome",
"acceptInsecureCerts": True,
# "goog:chromeOptions": {"extensions": [], "args": ["--headless"]},
}
}
driver = AsyncDriver(remote, capabilities)

# Maximize the browser window
await driver.maximize_window()
# Navigate to Qxf2 Tutorial page
await driver.get("http://qxf2.com/selenium-tutorial-main")

# Find the click me! button and click it
button = await driver.find_element("xpath" ,"//button[text()='Click me!']")
await button.click()
# Pause the script to wait for validation messages to load
await asyncio.sleep(3)

# KEY POINT: Check if the validation mesage for name field
try:
await driver.find_element("xpath", "//label[text()='Please enter your name']")
except Exception as e:
#This pattern of catching all exceptions is ok when you are starting out
result_flag = False
else:
result_flag = True
if result_flag is True:
print("Validation message for name present")
else:
print("Validation message for name NOT present")

# Close the browser window
driver.close()

if __name__ == "__main__":
asyncio.run(demo())
Loading