Selenium RC UI Mapping


Why we need to map the Elements or identifiers or locators in UI?
Imagine that if you have a case with hundreds of input in login field. Now the login text box has been changed to drop down list or the name of the identifier has been changed from Textbox_Login to txt_login. If you run your existing case, All the cases will be failed as cannot find the locator and you have to find and replace all in your script. Hence we have to map the UI objects for using a centralized location for make the script more efficient and maintainable.
Sample Script without mapping UI:
public void testlogin() throws Exception {
                selenium.open("http://www.samplesite.com");
                selenium.type("ctl00_MainCntPlaceHlder_txtFirstName", "dt");
                selenium.type("ctl00_MainCntPlaceHlder_txtMiddleName", "q");
                selenium.type("ctl00_MainCntPlaceHlder_txtLastName", "dt");
                selenium.type("ctl00_MainCntPlaceHlder_txtLoginName", "dt");
                selenium.type("ctl00_MainCntPlaceHlder_txtPassword", "dt");
Create the properties file:
Create a file like name.properties and we can assign the UI element as follows:
user.firstname = ctl00_MainCntPlaceHlder_txtFirstName
user.middlename = ctl00_MainCntPlaceHlder_txtMiddleName
user.lastname = ctl00_MainCntPlaceHlder_txtLastName
user.loginname = ctl00_MainCntPlaceHlder_txtLoginName
user.password = ctl00_MainCntPlaceHlder_txtPassword


Sample Script with Mapped UI:
public void testlogin() throws Exception {
                selenium.open("http://www.samplesite.com");
                selenium.type("
user.firstname", "dt");
                selenium.type("
user.middlename", "q");
                selenium.type("
user.lastname", "dt");
                selenium.type("
user.loginname", "dt");
                selenium.type("
user.password", "dt");
Simple Steps with Sample UI Map File 

10 comments:

  1. hi

    your post was very much useful

    the attempt to include the ui mapping file(.js) in selenium IDE was successful


    but when i created a ui mapping as property file in eclipse
    like mapping.properties which contains

    google.searchbox = q


    and when i included the stmt
    selenium.type("google.searchbox","selenium");
    in my java program

    it is giving
    ERROR: Element google.searchbox not found

    please help me
    tell how to write the property file for selenium rc and how to include in the test

    ReplyDelete
    Replies
    1. It is very late to answer but it may help the one who is facing same problem.

      Before you use "selenium.type("google.searchbox","selenium");", you need to load your properties file, that you can do it as Riy said or by
      Properties properties= new Properties();
      properties.load(new FileInputStream("with path to xxx.properties"));

      Delete
    2. Hello pooja,
      it does not work for me...

      i load first:
      Properties properties= new Properties();
      properties.load(new FileInputStream("with path to xxx.properties"));
      and then try to use it,
      "selenium.type("google.searchbox","selenium");"

      canyou provide snippet if possible?

      Delete
  2. There are many ways to call the selenium script.The below script is to connect the property file in RC.

    getClass().getResourceAsStream("xxx.properties")

    ReplyDelete
  3. Thanks for the great information in your blog Selenium Training in Chennai

    ReplyDelete
  4. Advanced Selenium Framework Training in Chennai by Vishwa

    Hi, Reach Mr.Vishwa for Best Selenium and Coded UI Training in Chennai with real time project assistance. This people will teach everything from the basics up to advanced level scenarios from frameworks.

    I learned from Mr.Vishwa and Raj they are very good automation people for Selenium Frameworks. After joined with them I learned many things and now I am writing automation scripts in own project. Vishwa 9003085882
    selenium training in chennai

    ReplyDelete
  5. Thanks for sharing this blog.Creating Experts provides Best training in selenium

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact 8122241286

    ReplyDelete
  6. The Creating Experts provides training in SELENIUM

    They provide hands on training with real time scenarios

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact +91-08122241286

    ReplyDelete
  7. Very Nice...Contains A to Z concepts...Thanks a lot.. and looking for the best selenium training in Chennai with certification from us. we have experienced selenium experts offer selenium course training with industry exposure. Check Here https://goo.gl/VRNEXv

    ReplyDelete