Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to check expected elements for section or page recursively #338

Closed
faceless7171 opened this issue Oct 23, 2018 · 10 comments
Closed
Assignees

Comments

@faceless7171
Copy link

faceless7171 commented Oct 23, 2018

Expected Behavior

It would be great to have ability to run method all_there? recursively in the specified section or page.

The solution can look something like this:

  module ElementChecker
    def all_there_r?
      elements_to_check.each do |e|
        if self.send(e).respond_to?('all_there?')
          self.send(e).all_there_r?
        end
      end
      self.all_there?
    end
  end
@luke-hill
Copy link
Collaborator

luke-hill commented Oct 23, 2018

Sounds like a good idea for a new feature I agree. Just to clarify a few points / ideas.
#1 - I am on a page which has sections / elements and I run all_there_r?

  • I first of all check every item that is mapped - If that's true. I then build a list of all section / sections
  • For each section, I run all_there?

#2 - How would you define the limit of recursiveness (Would it be infinite>?)

#3 - Are you wanting to discuss this / implement this, the code you've mentioned seems ok, but obviously I'm not behind my terminal at the moment.

EDIT: Needs a better name as well :)

@faceless7171
Copy link
Author

faceless7171 commented Oct 24, 2018

  1. For my understanding it should check only expected elements, not mapped ones (they will be equal if expected_elements is not specified). So for the page like this:
class Home < SitePrism::Page
  set_url '/index.htm'
  set_url_matcher /google.com\/?/

  section :s1, 's1' do
     element :e1, 'e1'
     element :e2, 'e2'
     section :s2, 's2' do
       element :e3, 'e3'
       element :e4, 'e4'
       element :e5, 'e5'
       sections :s3, 's3' do
         element :e6, 'e6'
       end
       expected_elements :e4, :e5, :s3
     end
  end
  element :e7, 'e7'
end

If I will run all_there_r? on this page it should check existence of:
s1.e1, s1.e2, s1.s2, s1.s2.e4, s1.s2.e5, s1.s2.s3, e7

Also I'm think that it is not possible to check existence of elements in "sections", we can only check that this sections are present. But I can be wrong here.

  1. I'm fine with infinite recursiveness, but it would be great if we will have possibility to change the limit.

  2. I'm pretty new to ruby, so I'm afraid I can't implement this feature. My code example is working only for the simplest case in my project.

P.S. I don't have any ideas of how to name this method :) Possibly we can improve existing "all_there?", and it will run recursively by default, will have arguments with recursive limit in it?

@luke-hill
Copy link
Collaborator

Thanks for the updates. I've got some ideas about how to start with this. Will probably put something up in 3.1 in the next couple of weeks.

@luke-hill
Copy link
Collaborator

I've got something which may land in a week or so (Spec refactor took a bit longer), which should allow for some small recursion to happen. Watch this space.

@luke-hill
Copy link
Collaborator

I've got an interim piece of code for this. But it's not really doing anything yet. I'll get something better up on a branch for you to have a play with sometime in December. @faceless7171

@luke-hill
Copy link
Collaborator

I've got some initial work that will hit a 3.0.1 release that will lay the foundations for some of this.

If you're interested in contributing at all let me know

@luke-hill luke-hill self-assigned this Mar 12, 2019
@luke-hill
Copy link
Collaborator

I've pushed up a branch with some of the boilerplate @ineverov which relates to this Feature Request. Check it out if you want.

@tgaff
Copy link
Contributor

tgaff commented Mar 28, 2019

Hi @luke-hill I was wondering what ended up happening with your recursive all_there? branch? We have an engineer who's interested in using that functionality.

@luke-hill
Copy link
Collaborator

https://github.com/natritmeyer/site_prism/tree/feature/all_there_recursion_struct - This doesn't actually recurse yet. But it does set all the boilerplate, all of the unit tests plus the additional logging / documentation

@luke-hill
Copy link
Collaborator

An initial cut of this is now in master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants