diff --git a/asynchronous/01_Navigate_Url.py b/asynchronous/01_Navigate_Url.py new file mode 100644 index 0000000..92c5ab4 --- /dev/null +++ b/asynchronous/01_Navigate_Url.py @@ -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() diff --git a/asynchronous/02_Fill_Text.py b/asynchronous/02_Fill_Text.py new file mode 100644 index 0000000..ef61b55 --- /dev/null +++ b/asynchronous/02_Fill_Text.py @@ -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()) \ No newline at end of file diff --git a/asynchronous/03_Set_Dropdown.py b/asynchronous/03_Set_Dropdown.py new file mode 100644 index 0000000..34c7d76 --- /dev/null +++ b/asynchronous/03_Set_Dropdown.py @@ -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()) \ No newline at end of file diff --git a/asynchronous/04_Enable_Checkbox.py b/asynchronous/04_Enable_Checkbox.py new file mode 100644 index 0000000..02085fe --- /dev/null +++ b/asynchronous/04_Enable_Checkbox.py @@ -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()) \ No newline at end of file diff --git a/asynchronous/05_Click_Button.py b/asynchronous/05_Click_Button.py new file mode 100644 index 0000000..4e4d6a0 --- /dev/null +++ b/asynchronous/05_Click_Button.py @@ -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()) \ No newline at end of file diff --git a/asynchronous/06_Form_Validation.py b/asynchronous/06_Form_Validation.py new file mode 100644 index 0000000..3cdd246 --- /dev/null +++ b/asynchronous/06_Form_Validation.py @@ -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()) \ No newline at end of file diff --git a/asynchronous/07_Form_Submit_Success.py b/asynchronous/07_Form_Submit_Success.py new file mode 100644 index 0000000..e4c46fc --- /dev/null +++ b/asynchronous/07_Form_Submit_Success.py @@ -0,0 +1,68 @@ +""" +Learn to fill and submit a form 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) Fill all the text field in Example form +4) Click on Click me! button +5) Verify user is taken to Selenium Tutorial redirect page +6) 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") + + #KEY POINT: Code to fill forms + # Find the name field and fill name + name = await driver.find_element("xpath", "//input[@id='name']") + await name.send_keys('Avinash') + # Find the email field and fill your email + await (await driver.find_element("xpath", "//input[@name='email']")).send_keys('avinash@qxf2.com') + # Find the phone no field and fill phone no + phone = await driver.find_element("id", "phone") + await phone.send_keys('9999999999') + # Identify the xpath for Click me button and click on it + button = await driver.find_element("xpath", "//button[text()='Click me!']") + await button.click() + # Wait for the new page to load + await asyncio.sleep(3) + # Verify user is taken to Qxf2 tutorial redirect url + if (driver.current_url== 'https://qxf2.com/selenium-tutorial-redirect'): + print("Success") + else: + print("Failure") + + # Close the browser + driver.close() + +if __name__ == "__main__": + asyncio.run(demo()) \ No newline at end of file diff --git a/asynchronous/08_Hover.py b/asynchronous/08_Hover.py new file mode 100644 index 0000000..f9b0704 --- /dev/null +++ b/asynchronous/08_Hover.py @@ -0,0 +1,70 @@ +""" +Learn to hover over elements 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) Click on Menu icon +4) Hover over Resource and GUI automation and click on GUI automation link +5) Close the browser +""" + + +import asyncio +#Notice this extra import statement (ActionChains)! +from caqui.caqui import AsyncDriver, ActionChains +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") + + # Locate the Menu icon and click on it + menu = await driver.find_element("xpath", "//img[@src='./assets/img/menu.png']") + await menu.click() + + # Locate the Resource element to hover over + resource = await driver.find_element("xpath", "//a[text()='Resources']") + + # KEY POINT: Use ActionChains to hover over elements + action = ActionChains(driver) + action.move_to_element(resource) + await action.perform() + await asyncio.sleep(2) #Adding waits to make the example more visual + + # Click the GUI automation link + gui_automation = await driver.find_element("xpath", "//a[text()='GUI automation']") + await gui_automation.click() + + # Wait for 3 seconds for the page to load + await asyncio.sleep(3) + + # Close the browser + driver.close() + +if __name__ == "__main__": + asyncio.run(demo()) \ No newline at end of file diff --git a/asynchronous/09_Count_Rows.py b/asynchronous/09_Count_Rows.py new file mode 100644 index 0000000..cf2e867 --- /dev/null +++ b/asynchronous/09_Count_Rows.py @@ -0,0 +1,57 @@ +""" +Learn to count the rows in a table 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 no of rows in the Example tabel +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() + # Navigate to Qxf2 Tutorial page + await driver.get("http://qxf2.com/selenium-tutorial-main") + + # Find the table element in the page + table = await driver.find_element("xpath", "//table[@name='Example Table']") + + # KEY POINT: Find the tr elements in the table + rows = await table.find_elements("xpath", "//tbody/descendant::tr") + print("Total No of Rows: %d"%len(rows)) + + # Pause the script for 3 seconds + await asyncio.sleep(3) + + # Close the browser + driver.close() + +if __name__ == "__main__": + asyncio.run(demo()) \ No newline at end of file diff --git a/asynchronous/10_Table_Text.py b/asynchronous/10_Table_Text.py new file mode 100644 index 0000000..43221df --- /dev/null +++ b/asynchronous/10_Table_Text.py @@ -0,0 +1,71 @@ +""" +Learn to parse the text within each cell of a table + +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) Get all the fields from the table +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() + # Navigate to Qxf2 Tutorial page + await driver.get("http://qxf2.com/selenium-tutorial-main") + + # KEY POINT: Logic to get the text in each cell of the table + # Find the Example table element in the page + table = await driver.find_element("xpath", "//table[@name='Example Table']") + # Use find_elements_by_xpath method to get the rows in the table + rows = await table.find_elements("xpath", "//tbody/descendant::tr") + # Create a list to store the text + result_data = [] + # Go to each row and get the no of columns and the navigate to column + # Then get the text from each column + for row in rows: + # Find no of columns by getting the td elements in each row + cols = await row.find_elements("tag name", "td") + cols_data = [] + for j in range(0,len(cols)): + # Get the text of each field + cols_data.append(cols[j].text.encode('utf-8')) + result_data.append(cols_data) + + # Print the result list + print(result_data) + + # Pause the script for 3 sec + await asyncio.sleep(3) + + # Close the browser + driver.close() + + +if __name__ == "__main__": + asyncio.run(demo()) \ No newline at end of file diff --git a/asynchronous/11_Consolidated_Test.py b/asynchronous/11_Consolidated_Test.py new file mode 100644 index 0000000..573526d --- /dev/null +++ b/asynchronous/11_Consolidated_Test.py @@ -0,0 +1,114 @@ +""" +Selenium script that performs several common actions like: +click button, select dropdown, enable checkbox, set text, get text from table + +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) Print the contents of the table +4) Fill all the text fields +5) Select Dropdown option +6) Enable the checkbox +7) Take a screenshot +8) Click on Submit button +9) 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 Example table element in the page + table = await driver.find_element("xpath", "//table[@name='Example Table']") + # Find no of rows in the table by getting the tr elements in the table + # Using find_elements_by_xpath method + rows = await table.find_elements("xpath", "//tbody/descendant::tr") + # Create a list to store the text + result_data = [] + # Go to each row and get the no of columns and the navigate to column + # Then get the text from each column + for i in range(0,len(rows)): + # Find no of columns by getting the td elements in each row + cols = await rows[i].find_elements("tag name", "td") + cols_data = [] + for j in range(0,len(cols)): + # Get the text of each field + cols_data.append(cols[j].text.encode('utf-8')) + result_data.append(cols_data) + # Print the result set + print(result_data) + + # Find the name field using xpath with id + name = await driver.find_element("xpath", "//input[@id='name']") + # Send text to the name element using send_keys method + await name.send_keys('Avinash') + # Find the email field using xpath without id + email = await driver.find_element("xpath", "//input[@name='email']") + await email.send_keys('avinash@qxf2.com') + # Find the phone no field using id + phone = await driver.find_element("id", "phone") + await phone.send_keys('9999999999') + + # Set a dropdown + await (await driver.find_element("xpath", "//button[@data-toggle='dropdown']")).click() + await asyncio.sleep(1) + # Find the xpath of particular option and click on it + await (await driver.find_element("xpath", "//a[text()='Male']")).click() + + # Set a checkbox + checkbox = await driver.find_element("xpath", "//input[@type='checkbox']") + await checkbox.click() + + # Take screenshot + await driver.save_screenshot('Qxf2_Tutorial.png') + + # Identify the xpath for Click me button and click on it + button = await driver.find_element("xpath", "//button[text()='Click me!']") + await button.click() + + # Pause the script for 3 sec + await asyncio.sleep(3) + + # Verify user is taken to Qxf2 tutorial redirect url + print(driver.current_url) + if (driver.current_url== 'https://qxf2.com/selenium-tutorial-redirect'): + print("Success") + else: + print("Failure") + + # Pause the script for 3 sec + await asyncio.sleep(3) + + # Close the browser + driver.close() + + +if __name__ == "__main__": + asyncio.run(demo()) \ No newline at end of file diff --git a/asynchronous/README.md b/asynchronous/README.md new file mode 100644 index 0000000..424cf94 --- /dev/null +++ b/asynchronous/README.md @@ -0,0 +1,25 @@ +# Asynchronous calls + +To perform asynchornous calls to WebDrivers you can use **Caqui** + +## Simple start +Install the lastest version of **Caqui** + +``` +pip install -r requirements.txt +``` + +Download the same [ChromeDriver](https://chromedriver.chromium.org/downloads) version as your installed Chrome and start the Driver as a server using the port "9999" + +``` +$ ./chromedriver --port=9999 +Starting ChromeDriver 94.0.4606.61 (418b78f5838ed0b1c69bb4e51ea0252171854915-refs/branch-heads/4606@{#1204}) on port 9999 +Only local connections are allowed. +Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe. +ChromeDriver was started successfully. +``` +Run the examples +``` +python asynchronous/01_Navigate_Url.py +``` + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..52f4a94 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +# used to run asynchronous calls against webdrivers +caqui>=2.0.0rc2 \ No newline at end of file