Topview Logo
  • Create viral videos with
    GPT-4o + Ads library
    Use GPT-4o to edit video empowered by Youtube & Tiktok & Facebook ads library. Turns your links or media assets into viral videos in one click.
    Try it free
    gpt video

    QA Test Automation Framework integration with Open Source A.I. Image Detection

    blog thumbnail

    QA Test Automation Framework Integration with Open Source AI Image Detection


    Introduction

    In the current technological era, machine learning (ML) and artificial intelligence (AI) are increasingly ubiquitous, providing user-friendly solutions that enhance the efficiency and simplicity of our lives. Thus, it is paramount that our test automation frameworks evolve beyond conventional methods. This article delves into the integration of open-source AI for image detection within test automation frameworks, making them quicker, more accurate, and efficient.

    Steps to Implement AI Image Detection in Test Automation Framework

    To implement AI image detection in your test automation framework, follow these key steps:

    1. Capture Element Screenshots:

      • Take screenshots of the elements on which you want to perform interactions.
    2. Import Necessary Libraries:

      • Import essential libraries such as PyAutoGUI and Selenium.
    3. Create Methods for Image Interactions:

      • Develop methods that facilitate interactions based on image detection.
    4. Utilize Methods in Framework:

      • Implement the developed methods within your test automation framework.

    Detailed Implementation

    1. Capturing Screenshots:

      • Take screenshots of the desired elements and store them in the respective framework directory.
    2. Importing Libraries:

      import pyautogui
      from selenium import webdriver
      
    3. Creating Methods:

      def click_on_image(image_path):
          location = pyautogui.locateCenterOnScreen(image_path)
          if location:
              pyautogui.click(location)
          else:
              raise Exception("Image not found on screen")
      

      This method takes the image path as an input, locates the image on the screen, retrieves the coordinates of the center, and clicks on the identified coordinates.

    4. Running Demo:

      • Visit the desired website.
      • Detect the username, password, and sign-in button images on the screen.
      • Utilize the method by passing the image paths to perform respective actions.

    Example Code

    Here is an example implementation for a demo:

    1. Capturing Screenshots:

      - resources/username.png
      - resources/password.png
      - resources/sign_in.png
      
    2. Importing Libraries:

      import pyautogui
      from selenium import webdriver
      
    3. Creating Methods:

      def click_on_image(image_path):
          location = pyautogui.locateCenterOnScreen(image_path)
          if location:
              pyautogui.click(location)
          else:
              raise Exception("Image not found on screen")
      
      def fill_field(image_path, text):
          click_on_image(image_path)
          pyautogui.write(text)
      
    4. Utilizing Methods:

      driver = webdriver.Chrome()
      driver.get("http://example.com")
      
      fill_field("resources/username.png", "myusername")
      fill_field("resources/password.png", "mypassword")
      click_on_image("resources/sign_in.png")
      

    This method demonstrates launching a website, locating fields using captured screenshots, performing text entry, and simulating a button click based on the detected image coordinates.

    Conclusion

    This approach eliminates the need for complicated XPaths or locators and replicates human interaction more closely. While it necessitates keeping the screen on during test script execution, it addresses numerous challenges in quick UI-based automation.

    Resources

    Keywords

    • Machine Learning
    • Artificial Intelligence
    • Test Automation
    • Open Source AI
    • PyAutoGUI
    • Selenium
    • Image Detection
    • UI Automation

    FAQ

    Q1: What are the prerequisites for implementing this method in a test automation framework?

    A1: You need to capture screenshots of the elements, import necessary libraries like PyAutoGUI and Selenium, and integrate the methods into your framework.

    Q2: Do I need to keep the screen on while running the test scripts?

    A2: Yes, the screen must remain on during script execution to facilitate real-time image detection.

    Q3: How does this approach handle complex XPaths or dynamic elements?

    A3: By using image detection, this approach bypasses the need for XPaths, simplifying the interaction with complex or dynamically changing elements.

    Q4: What happens if the image is not found on the screen?

    A4: The script raises an exception indicating that the image was not found, prompting further investigation or script adjustment.

    One more thing

    In addition to the incredible tools mentioned above, for those looking to elevate their video creation process even further, Topview.ai stands out as a revolutionary online AI video editor.

    TopView.ai provides two powerful tools to help you make ads video in one click.

    Materials to Video: you can upload your raw footage or pictures, TopView.ai will edit video based on media you uploaded for you.

    Link to Video: you can paste an E-Commerce product link, TopView.ai will generate a video for you.

    You may also like