what is object repository in selenium

To test web applications from the end-user’s point of view, QAs need to interact with many web elements. To do so, they use the locator concept in Selenium while writing test automation scripts. However, hard-coding the locators in the script each time will lead to code duplication. Also, if a value of any single locator changes, it needs to be updated throughout the project to ensure consistency. This is a time consuming job. Using an object store in Selenium helps QAs solve both of these problems. This article will explain the concept of an object store. Read: What is object store in selenium

What is Object Store in Selenium?

Contents

An object store is a centralized storage of locators in the form of objects. QAs store all element locators in a separate file, also known as the properties file (.properties) in Selenium. The properties file stores information in a core values pair format. This file serves as an object store in Selenium WebDriver. QAs may also store these objects in XML files depending on the framework being used. The image below represents the Sample Properties file. It has a named extension “.characteristic”QAs can create two types of object stores in Selenium WebDriver:

  • Using properties file in Selenium
  • Using XML files
  • Furthermore, let us understand three things:

  • How to create and store data in the Properties file
  • How to read data from Properties file
  • Use data stored in properties file in test script
  • 1. How to create a Properties file and add data

    Read more: What is a group of penguins called First need to set up the basic project structure on eclipse. To create a properties file, one needs to follow the below steps:

    • Right click on Project Folder > New > Other > General > FileObject Store in Selenium
    • Click Next and then give the file a name (eg: topqa.infoerties) and then click End.
    See Also  0xabad1dea / speedrunning-faq.md

    Properties file in SeleniumNow, one needs to store the data in this file in key-value pairs. Just double click yours file .properties and add key-values. In this example, we will look at the web elements of the Facebook login page. So we’ll add the XPath of the username, password and login button in our properties file.facebook.login.username.xpath=. // *[@id=’email’] topqa.infoh =. // *[@id=’pass’] topqa.infoh =. // *[@id=’loginbutton’]Test case scenario consists of three basic steps:

  • Go to Facebook login page
  • Enter username and password
  • Click the login button
  • 2. How to read data from the Properties file

    To read data from Properties file we need to use Property class available in topqa.infoage So one need to create an object of Property class: Property obj = new Property(); Read more: What does the snowman emoji mean? Now we also need to create an object of the FileInputStream class with its path pointing to the file .properties: FileInputStream objfile = new FileInputStream(System.getProperty( “user.dir”) + ” ”); Now to integrate the properties file in our test script that includes the locator we need to load the file. To do this, we will use the property class’s load method. Refer to the code below.Properties obj = new Properties(); FileInputStream objfile = new FileInputStream(System.getProperty (“user.dir”) + ” ”); topqa.info (objfile); String username = topqa.inforoperty (“facebook.login.username.xpath”); The string username will contain the XPath to find the username field on the login page. Try running Selenium tests in the cloud for free

    3. Using Properties file in Selenium Script

    Now to use the location information available in the properties file, we will pass the data available as a parameter using the findElement.driver.findElement(By.xpath(obj.getProperty(“facebook.login. password.xpath”))). sendKeys (“adsadasdas”); Refer to the complete code below to understand the program flow: import topqa.infoInputStream; enter topqa.infoNotFoundException; enter topqa.infoception; enter topqa.information; enter topqa.info; enter topqa.inforiver; enter topqa.infofoxDriver; enter topqa.info; public class TestFacebook {@Test public void TestOR() throws IOException { // Specify the file location I used. works here because // we have object store inside project folder only File src = new File (“.Object_Repo.properties”); // Create object FileInputStream FileInputStream objfile = new FileInputStream (src); // Create a Properties class object to read the properties file Properties obj = new Properties(); // Load the file so we can use it in the topqa.info script (objfile); topqa.infotln (“Attribute class loaded”); // Open driver FirefoxBrowser WebDriver = new FirefoxDriver(); // Maximize the topqa.infoge() window. Window (). Max(); // Transfer the topqa.info application (“http://www.facebook.com”); // getProperty Fetch the value of the target key from the properties file // In this case, enter the username topqa.infoElement (By.xpath (obj.getProperty (“facebook.login.username.xpath”))). sendKeys (“[email protected]”); // getProperty Fetch the value of the target key from the properties file // In this case, enter the password topqa.infoElement (By.xpath (obj.getProperty (“facebook.login.password.xpath”))). sendKeys (“adsadasdas”); // getProperty Fetch the value of the target key from the properties file // In this case, click the login button topqa.infoElement (By.xpath (pro.getProperty (“facebook.login.Signup.xpath”))) . click() ; }} Using an object store in Selenium helps QAs manage their test suites more efficiently. The centralized approach of maintaining web element location information makes it easy for test teams to make changes quickly with less effort. Hence, an understanding of Object Repositories will make QA’s life easier in a significant way.

    See Also  what is pooh shiesty net worth

    Last, Wallx.net sent you details about the topic “what is object repository in selenium❤️️”.Hope with useful information that the article “what is object repository in selenium” It will help readers to be more interested in “what is object repository in selenium [ ❤️️❤️️ ]”.

    Posts “what is object repository in selenium” posted by on 2021-08-27 20:12:11. Thank you for reading the article at wallx.net

    Rate this post
    Back to top button