How to SetUp Object Repository in Selenium?

谁说胖子不能爱 提交于 2019-12-13 10:39:07

问题


I am trying to setup an Object Repository in Selenium Webdriver in order to make sure that future changes in objects don't impact my script.


回答1:


From my point of view PageObjects are the way to go.

That simple!




回答2:


  1. Have a CSV with all the object locator's....
  2. A CSV parser and store all the values in a multidimensional array with column and and row as index..
  3. Use that array wherever you need to use the locater in the code...
  4. If you don't want to have the hard-coded index values for the array then you will need to have some increment mechanism...



回答3:


  try{
    while(loc_index<=loc_type.size()-1){
    //  System.out.println("1sy");
    while(loc_val_index<=loc_val.size()){
        while(obj_index<=obj_value.size()-1){   
          String loc_data = loc_type.get(loc_index);
          if(loc_data.equals("name")){           
     WebElement element = driver.findElement(By.name(loc_val.get(loc_val_index)));
    if (element!=null){
        try {
       element.sendKeys(obj_value.get(obj_index)); } catch (Exception e){}
       obj_index++;}}else if(loc_data.equals("xpath")){
      WebElement element = driver.findElement(By.xpath(loc_val.get(loc_val_index)));
      if (element!=null){                            
          element.sendKeys(obj_value.get(obj_index));  
           Log("Data Entered");
          obj_index++;}}
      else if(loc_data.equals("id")){ 
      try{
          WebElement element = driver.findElement(By.id(loc_val.get(loc_val_index))); 
          if (element!=null){
             element.sendKeys(obj_value.get(obj_index));                                
               obj_index++;}} catch (Exception e) {}}
             break;}
        loc_val_index++;
        break;}
    loc_index++;
    }
        }catch (Exception e){}
        finally{
            obj_index=0;
            loc_index=0;
            loc_val_index=0;
        }


来源:https://stackoverflow.com/questions/11653772/how-to-setup-object-repository-in-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!