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:
- Have a CSV with all the object locator's....
- A CSV parser and store all the values in a multidimensional array with column and and row as index..
- Use that array wherever you need to use the locater in the code...
- 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;
}