Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 1219

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 62k
Author
Asked: November 25, 20242024-11-25T06:06:08+00:00 2024-11-25T06:06:08+00:00

Selenium and AI: UI Validations with AI

  • 62k

Automated UI testing has long been a staple in ensuring that web applications meet design and functionality standards. Traditional methods, such as using Selenium, involve interacting with the UI through specific code tied to the structure of the webpage. However, a new AI-driven method using Tools4AI is changing the game by allowing us to translate visual elements directly into code objects, simplifying the testing process considerably.

In my previous article I wrote about how to function call based on images you can read about that here

The Traditional Selenium Way to validate UI

Lets take a simple example to start with, Imagine you’re testing a website for an auto repair shop.

Image description

With Selenium, you might write a test to check service prices:

WebElement oilChangePrice = driver.findElement(By.id("oilChangePrice")); assert "29.99".equals(oilChangePrice.getText()); 
Enter fullscreen mode Exit fullscreen mode

Conventionally, if you needed to verify that the “Full Inspection” service on the AutoServicingPro website is listed as “Starting at $99.99,” you would:

Use Selenium to locate the web element.
Extract the text from the element.
Assert the value against your expected text.
This method works well but has its drawbacks. Any change to the website’s layout could break your test, requiring you to update the code.

The AI-Based Method: Option 1 With JSON

Incorporating AI to convert images to JSON is an innovative approach to streamline the data extraction process from user interfaces. This method bypasses the traditional need for manual element identification and data extraction, offering a more efficient solution.

First you would either have the screenshot as files or can use Selenium to get one

 WebDriverManager.chromedriver().setup();          ChromeOptions options = new ChromeOptions();         options.addArguments("--headless");  // Setting headless mode         options.addArguments("--disable-gpu");  // GPU hardware acceleration isn't useful in headless mode         options.addArguments("--window-size=1920,1080");  // Set the window size         WebDriver driver = new ChromeDriver(options);           driver.get("https://google.com");         // Your code to interact with the page and take screenshots       // Take screenshot and save it as file or use as bytes         TakesScreenshot ts = (TakesScreenshot) driver;         byte[] screenshotBytes = ts.getScreenshotAs(OutputType.BYTES);         GeminiImageActionProcessor imageActionProcessor = new GeminiImageActionProcessor();         imageActionProcessor.imageToText(screenshotBytes)         //File srcFile = ts.getScreenshotAs(OutputType.FILE);         //File destFile = new File("screenshot.png");         //FileHandler.copy(srcFile, destFile);         driver.quit(); 
Enter fullscreen mode Exit fullscreen mode

With the AI-based method, a tool processes the image of the website and returns a JSON string containing the necessary information:

String jsonStr = processor.imageToJson(   GeminiImageExample.class.getClassLoader().getResource("auto.PNG"),   "Full Inspection" ); // you can directy feed the bytes of the image 
Enter fullscreen mode Exit fullscreen mode

// The returned JSON System.out.println(jsonStr); 
Enter fullscreen mode Exit fullscreen mode

The return Json looks like this

{   "fieldName": "Full Inspection",   "fieldType": "String",   "fieldValue": "Starting at $99.99" } 
Enter fullscreen mode Exit fullscreen mode

Now this can be easily validated with any json parser. You could also have a “golden copy” of your json which you can compare against every time the UI changes

The AI-Based Method: Option 2 With Pojos

Tools4AI can help take screenshot of the page and identifies the elements for you, converting them into a POJO (Plain Old Java Object):

import lombok.*; @Getter @Setter @ToString @NoArgsConstructor @AllArgsConstructor public class AutoRepairScreen {     double fullInspectionValue;     double tireRotationValue;     double oilChangeValue;     Integer phoneNumber;     String email;     String[] customerReviews; } 
Enter fullscreen mode Exit fullscreen mode

AutoRepairScreen screenData = aiProcessor.imageToPojo("screenshot.png", AutoRepairScreen.class); assert screenData.oilChangePrice == 29.99; 
Enter fullscreen mode Exit fullscreen mode

This method not only saves time but also enhances the robustness of UI testing. Testers can focus on the logic and data rather than on the underlying code required to fetch this information. Furthermore, as UIs evolve, tests written with Tools4AI can adapt to changes with minimal to no maintenance, provided the AI continues to recognize the UI elements correctly.

Tools4AI exemplifies how AI can simplify complex processes, offering a glimpse into a future where AI and machine learning continually reduce the manual workload in software development and quality assurance.

Example 2

Now, let’s delve into a second example. Here we have a gym schedule. Someone snaps a photo or captures a screenshot from their webpage using selenium. We’re going to explore how this visual information transitions into a usable Java object or becomes validated through an AI-driven process.

Image description

Picture a typical gym timetable: rows of classes and times across a grid representing the week. Traditionally, if you needed to digitize or validate this schedule, it would be a manual process. You’d have to type out each class into a database or cross-reference times and offerings with a source of truth.

Enter the AI solution by Tools4AI. It simplifies the transition of data from a visual format into structured, validated Java objects.

GeminiImageActionProcessor processor = new GeminiImageActionProcessor(); 
Enter fullscreen mode Exit fullscreen mode

Here’s how it works:

Object pojo = processor.imageToPojo(GeminiImageExample.class.getClassLoader().getResource("fitness.PNG"), MyGymSchedule.class); log.info(pojo.toString()); 
Enter fullscreen mode Exit fullscreen mode

The Pojo looks like this

@Getter @Setter @NoArgsConstructor @ToString public class MyGymSchedule {   @ListType(Activity.class)   List<Activity> myWeeklyActivity;  }  @Getter @Setter @NoArgsConstructor @ToString public class Activity {     String dayOfTheWeek;     String activityName; } 
Enter fullscreen mode Exit fullscreen mode

Image to Data Interpretation: First, the image of the gym schedule is processed. AI algorithms examine the picture, detect the text and its organization — understanding that “Monday at 7 PM” corresponds to “Yoga,” for example.

Data Mapping: The interpreted data is then mapped to Java objects. In this case, the AI populates a MyGymSchedule object that contains a List. Each Activity object holds the dayOfTheWeek and activityName, reflecting the schedule.

Validation and Use: If this process is part of a test, the populated Java objects can now be easily validated. Does the MyGymSchedule object contain “Yoga” under “Monday”? If the AI's interpretation aligns with the expected data, the test passes.
The result

INFO: MyGymSchedule(myWeeklyActivity=[Activity(dayOfTheWeek=Monday,  activityName=LES MILLS VIRTUAL RPM), Activity(dayOfTheWeek=Monday,  activityName=VIRTUAL NEWBODY), Activity(dayOfTheWeek=Tuesday,  activityName=VIRTUAL NEWBODY), Activity(dayOfTheWeek=Wednesday,  activityName=VIRTUAL ATHLETIC RIDE), Activity(dayOfTheWeek=Thursday,  activityName=VIRTUAL CYCLING), Activity(dayOfTheWeek=Friday,  activityName=VIRTUAL AWESOME ABS), Activity(dayOfTheWeek=Friday,  activityName=VIRTUAL NEWBODY), Activity(dayOfTheWeek=Saturday,  activityName=AQUAFIT), Activity(dayOfTheWeek=Sunday, activityName=AQUAFIT)]) 
Enter fullscreen mode Exit fullscreen mode

The real beauty of this approach is its versatility. Whether you’re dealing with a photo or a screenshot from a website, the method remains the same. The result is a quick and accurate digitization or validation of the information that was once locked in a static image, now dynamically accessible and usable within any system that can handle Java objects.

 public static void main(String[] args) throws AIProcessingException {         GeminiImageActionProcessor processor = new GeminiImageActionProcessor();         String jsonStr = processor.imageToJson(GeminiImageExample.class.getClassLoader().getResource("images/auto.PNG"),"Full Inspection");         log.info(jsonStr);         jsonStr = processor.imageToJson(GeminiImageExample.class.getClassLoader().getResource("images/auto.PNG"),"Full Inspection","Tire Rotation","Oil Change");         log.info(jsonStr);         jsonStr = processor.imageToJson(GeminiImageExample.class.getClassLoader().getResource("images/auto.PNG"), AutoRepairScreen.class);         log.info(jsonStr);         jsonStr = processor.imageToJson(GeminiImageExample.class.getClassLoader().getResource("images/fitness.PNG"), MyGymSchedule.class);         log.info(jsonStr);         Object pojo = processor.imageToPojo(GeminiImageExample.class.getClassLoader().getResource("images/fitness.PNG"), MyGymSchedule.class);         log.info(pojo.toString());         pojo = processor.imageToPojo(GeminiImageExample.class.getClassLoader().getResource("images/auto.PNG"), AutoRepairScreen.class);         log.info(pojo.toString());     } 
Enter fullscreen mode Exit fullscreen mode

Complete code for this article is available here

Conclusion

Testing user interfaces traditionally involves a significant amount of manual scriptwriting, often requiring tedious element location and extraction. Tools4AI revolutionizes this process, utilizing AI to convert UI screens into JSON objects or Java POJOs (Plain Old Java Objects). This transformation facilitates a more streamlined approach to interacting with and validating UI data.

With Tools4AI’s image processing capabilities, extracting data from a UI becomes as simple as feeding a screenshot into the system. The AI then analyzes the image, identifies text and UI components, and converts this information into a structured JSON or a Java object.

aijavascriptprogrammingwebdev
  • 0 0 Answers
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.