Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Compare content of two arrays

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 470
    Comment on it

    Many times we face a situation where we have to assert the content of two tables in a web-page. The best solution of this problem is that we first put the content of both the tables in an array and then compare the content of these two arrays.

     

    Suppose we have a web-page

     

    Here we have to assert the employee names present in the left navigation with the employee names present in the middle section of the page in the form of table.

     

    We have taken two arrays ie array1(for left navigation) and array2(for middle section), then pushed elements in array one by one. Once all the elements were pushed then we will compare both the arrays

     

      def assert_project_members
        @session.within_frame 'mainiframe' do
          @array1 = Array.new
          @array2 = Array.new
          sleep 1
          c = "input[@type='checkbox'][@checked='checked'][not(contains(@name, 'allUsers'))]"
          @session.all(:xpath, "//*[@id='projUserListing']//#{c}/following-sibling::span").each do |a|
            @array1.push a.text
          end
          sleep 3
          @session.all(:xpath, ".//*[@id='tabCalendar']//ul[@class='tabReportUl']/li[@class='empName']").each do |b|
            @array2.push b.text
          end
        end
        expect(@array1).to match_array(@array2)
        self
      end

     

    expect(@array1).to match_array(@array2)

     

    This will compare the elements array1 with the elements of array2 and if both the array contains the same elements then it will return true otherwise it will return false.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: