Wednesday 2 December 2015

Comparing Array and list of array

 public Mobile_AboutMePage verifyaboutMeScreen() throws IOException, InterruptedException{
       
        //expected Array list
        String[] expectedLabels={"Basic Info","More about Myself, Partner and Family", "Family","Religious Background","Family","Astro Details","Location, Education & Career","Lifestyle","Partner Preferences","Partner Location","Partner Education & Career","Partner Lifestyle & Appearance"};
        //created actual label list from find element
        List<String> actualLabels=new ArrayList<String>();
        try{
            List<WebElement> lable=driver.findElements(TestUtils.GetPropertiesWeb("AboutMe_BasicInfo"));
            System.out.println(lable.size());
           
           
       
            //for loop -to check every element(e1) from list (lable)
            for(WebElement el:lable){
                if(!el.getText().equals(""))
                    //adding to arraylist
                    System.out.println(actualLabels.add(el.getText()));
            }
           
            for(int i=0;i<expectedLabels.length;i++){
                // comparing 2 list
                if(actualLabels.contains(expectedLabels[i]))
                {
                    System.out.println(lable.get(i).getText());
                    System.out.println( "matching with expected text" );
                    Reports.addToReport("In Basic Info Section: "+expectedLabels[i]+" Displayed<>ASSERT-PASS<>"+Page,PASS);
                }
                else{
                   
                    System.out.println(lable + "not matching with expected text" );
                    Reports.takeSnapshot("Element not found: Basic Info Locator<>ASSERT-FAIL<>"+Page+"<>*",FAIL, driver);
                }
            }
               
        }catch(Exception e){
            System.out.println("Lable locator not found");
            Reports.takeSnapshot("Element not found: Basic Info Locator<>ASSERT-FAIL<>"+Page+"<>*",FAIL, driver);
        }
        return this;
    }

No comments:

Post a Comment