Code Example
Example how to automate login testing. Download here simplehq_login.py
import aiviro
if __name__ == "__main__":
# init aiviro logger
aiviro.init_logging()
#################
# Test case
#################
# create web-robot
r = aiviro.create_web_robot(headless=False) # only works in non-headless mode
r.go_to_url("https://app.simplehq.co/login.html")
# wait until page is fully loaded
r.wait_for(aiviro.Text("Hello!"))
# type login credentials & click log-in button
r.type_text(aiviro.Input("Email"), "jelenovi.pivo.nelej@wtf.com")
r.type_text(aiviro.Input("Password"), "123456789")
r.click(aiviro.Button("Log In"))
# check that the log-in was invalid
r.wait_for(aiviro.Text("Information provided is incorrect."), timeout=10)
# close the web-robot
r.close()
Example how to check the alignment of elements. Download here todo_mvc_alignment.py
import aiviro
URLS = [
"http://todomvc.com/examples/vanillajs/",
"http://todomvc.com/examples/backbone/",
"http://todomvc.com/examples/angularjs/#/",
"http://todomvc.com/examples/emberjs/",
"http://todomvc.com/examples/knockoutjs/",
"http://todomvc.com/examples/dojo/",
"http://todomvc.com/examples/knockback/",
"http://todomvc.com/examples/canjs/",
"http://todomvc.com/examples/polymer/index.html",
"http://todomvc.com/examples/react/#/",
"http://todomvc.com/examples/mithril/#/",
"http://todomvc.com/examples/vue/",
"http://todomvc.com/examples/backbone_marionette/",
]
if __name__ == "__main__":
# init aiviro logger
aiviro.init_logging()
#################
# Test case
#################
# create web-robot
r = aiviro.create_web_robot(headless=True)
for url in URLS:
r.go_to_url_in_new_tab(url)
# create Input search-object & wait until it appears on the website
input_object = aiviro.Or(
aiviro.Button("What needs to be done?", element_index=0),
aiviro.Input("What needs to be done?", element_index=0),
)
input_box = r.wait_for(input_object, timeout=15)
# add 3 tasks into list
r.type_text(input_box, "Do the laundry\n")
r.type_text(input_box, "Go shopping\n")
r.type_text(input_box, "Pay the bills\n")
# wait until the last task appears in the list
r.wait_for(aiviro.Text("Pay the bills"), timeout=10)
do_the_laundry_label = aiviro.Text("Do the laundry")
go_shopping_label = aiviro.Text("Go shopping")
pay_the_bills_label = aiviro.Text("Pay the bills")
# check different alignment of the elements
r.check_are_in_column(
do_the_laundry_label,
go_shopping_label,
pay_the_bills_label,
anchor=aiviro.layout_anchor.LEFT,
tolerance=10,
)
r.check_is_positioned(
do_the_laundry_label,
go_shopping_label,
direction_type=aiviro.layout_positions.IS_ABOVE,
)
r.check_is_positioned(
pay_the_bills_label,
go_shopping_label,
direction_type=aiviro.layout_positions.IS_BELOW,
)
# close the web-robot
r.close()
Example of filling up the registration forms. Download here eshop_registration.py
import aiviro
if __name__ == "__main__":
aiviro.init_logging()
r = aiviro.create_web_robot(headless=True)
r.set_animation_timeout(5)
FIRST_NAME = "Aiviro"
LAST_NAME = "Test"
EMAIL = "aiviro@test.cz"
PHONE_NUMBER = "777189234"
# e-shop Nazuby
r.go_to_url("https://www.nazuby.cz/")
r.click(aiviro.Icon("Prihlasit"), aiviro.Text("Registrace"))
r.type_text(aiviro.Input("Jmeno"), FIRST_NAME + " " + LAST_NAME)
r.type_text(aiviro.Input("Vas e-mail"), EMAIL)
# e-shop MALL
r.go_to_url("https://www.mall.cz")
r.move(aiviro.Text("Muj ucet"))
box_button = r.wait_for(aiviro.Button("Zaregistrovat"))
r.click(box_button)
r.type_text(aiviro.Input("Jmeno"), FIRST_NAME)
r.type_text(aiviro.Input("Prijmeni"), LAST_NAME)
r.type_text(aiviro.Input("Vas e-mail"), EMAIL)
r.type_text(aiviro.Input("Telefon"), PHONE_NUMBER)