Giter Club home page Giter Club logo

site_prism's People

Contributors

abotalov avatar anuj-ssharma avatar anujflux avatar asavageiv avatar basuneko avatar dependabot[bot] avatar dnesteryuk avatar hoffi avatar ineverov avatar j16r avatar jmileham avatar jwarykowski avatar lparry avatar luke-hill avatar mikekelly avatar natritmeyer avatar oieioi avatar ricmatsui avatar rustynail avatar soulcutter avatar sponte avatar systho avatar tadashi0713 avatar teyamagu avatar tgaff avatar themetalcode avatar tmertens avatar tobithiel avatar tpbowden avatar twalpole avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

site_prism's Issues

has_some_element? doesn't check for uniqueness

Issue to raise for SitePrism framework

supposed there is an element some_element defined as

element :some_element, 'li'

and code

if some_page.has_some_element?
  some_page.some_element
end

Above example will raise an error if li element is not unique on the line
some_page.some_element :
Capybara::Ambiguous Exception: Ambiguous match, found N elements matching visible css "li"

This is happening in

def element_exists?(*find_args)
there we check for a selector, but not providing count: 1 option for element.

This issues can be seen in various places there?(:some_element), all_there? etc will also return true for above example. But will fail if you try to interact with element

Environment

  • all

Expected Behavior

has_some_element? to return false (maybe with warning "found multiple elements")

Actual Behavior

has_some_element? returns true but some_element fails with above error

Proposed workaround

 module Fix                                                                                                                  
   def element(name, *find_args)                                                                                             
     hash_args = find_args.last                                                                                              
     hash_args.merge!(count: 1) unless hash_args.has_key?(:count)                                                            
     super(name, *find_args)                                                                                                 
   end                                                                                                                       
   def section(name, *find_args)                                                                                             
     hash_args = find_args.last                                                                                              
     hash_args.merge!(count: 1) unless hash_args.has_key?(:count)                                                            
     super(name, *find_args)                                                                                                 
   end                                                                                                                       
 end                                                                                                                         
                                                                                                                             
 SitePrism::DSL::ClassMethods.prepend(Fix)

stale element reference from site_prism 2.15.1

stale element reference from site_prism 2.15.1

problem upgrading site_prism from 2.14 to 2.15

I don't have this problem with 2.14.
bumping this gem is the only changes I have

Environment

  • Operating System Ubuntu 18.04 + 20.04
  • site_prism 2.15.1 and 2.16 behave the same, 2.14 is working and capybara 2.18 / selenium-webdriver (3.142.7)
  • How you're interacting with the Framework: RSpec Units
  • Browser/s Driver/s being used - Chrome 81

Expected Behavior

elements should be found, test should pass.

Actual Behavior

when I access the rules section, trying to simply expect(dialog.rules.length).to eq(2)

I get this error.

*** Selenium::WebDriver::Error::StaleElementReferenceError Exception: stale element reference: element is not attached to the page document
  (Session info: chrome=81.0.4044.138)

Steps to reproduce

  class EditThresholdRule < SitePrism::Section
    element :condition_type, "select[name='condition_type']"
    element :action_type, "select[name='action_type']"
    element :action_options_rounding, "select[name='action_options_rounding']"
    element :action_options_minutes, "select[name='action_options_minutes']"
    element :destroy, "a.destroy_link"
  end
  class EditThresholdDialog < UiDialog
    element :save_and_apply, "button.primary-button"
    element :select_allow, "select[name='allow']"
    sections :rules, EditThresholdRule, "li.resolution-rules li.rule"
    element :add_rule, "li.resolution-rules li.actions button"
  end

probably important to add, these elements are hidden/shown via angular, but I see them in the browser when I stop the debugger

thanks

Require 'forwardable' somewhere in the project

Issue to raise for SitePrism framework

Environment

  • Operating System (Mac / Windows / Ubuntu e.t.c.)
    • Ubuntu
  • What Gems / Versions you are using (Specifically site_prism and capybara)
    • Ruby 3.1.0
    • site_prism 3.7.3
    • site_prism-all_there 0.3.2
    • capybara 3.37.1
  • How you're interacting with the Framework (Cucumber Tests / RSpec Units / Minitest)
    • RSpec and Cucumber
  • Browser/s Driver/s being used - with version numbers
    • Whatever the default is

Expected Behavior

To be able to define a class extending Section, e.g. class SomeSection < SitePrism::Section; end

Actual Behavior

An error occurs:

Failure/Error: class SomeSection < SitePrism::Section

NameError:
  uninitialized constant SitePrism::Section::Forwardable

      extend Forwardable
             ^^^^^^^^^^^

Steps to reproduce

Simply run the line of code under Expected Behavior in a fresh project.

Conclusion

Of course, this is very easily solvable by doing require 'forwardable' anywhere in the project, but it seems like this should be done in SitePrism.

Update graphic associated with Betterment in the wiki

Issue to raise for SitePrism wiki

The Betterment logo is outdated, however I lack permissions to edit the wiki directly. Would you be able to swap out

[<img src="http://static.squarespace.com/static/51eef63ae4b089778deccb24/t/522cb69be4b074119b21db97/1375925773732/Betterment.png" width="300"/>](https://www.betterment.com)

with

[![Betterment](https://www.betterment.com/hubfs/Graphics/shared-assets/betterment-logo.png)](https://www.betterment.com)

Thanks!

Add `attributes` as a name to the v4 blacklist for DSL definitions

Environment

  • Ubuntu
  • SitePrism v3.6
  • Using RSpec and Cucumber

Issue

When defining a new class inheriting from SitePrism::Page which defines a :attributes section, the default helper have_attributes from RSpec gets overwritten.

Steps to reproduce

Here is a RSpec test to showcase the issue:

RSpec.describe "have_attributes" do
  let(:struct) { Struct.new(:a, :b, :c) }

  it "checks that the object has the listed attributes" do
    expect(struct.new(1, 2, 3)).to have_attributes(a: 1, b: 2, c: 3)
  end
end

RSpec.describe "a Page implementing an attributes section" do
  let(:struct) { Struct.new(:a, :b, :c) }

  context "when it is defined" do
    let!(:page) do
      Class.new(SitePrism::Page) do
        section :attributes, '.foo' do
          element :unused_element, '.btn'
        end
      end
    end

    it "breaks `have_attributes`" do
      expect(struct.new(1, 2, 3)).to have_attributes(a: 1, b: 2, c: 3)
    end
  end

  context "after it has been defined once" do
    it "breaks `have_attributes`" do
      expect(struct.new(1, 2, 3)).to have_attributes(a: 1, b: 2, c: 3)
    end
  end
end

The matcher for have_attributes should be: https://relishapp.com/rspec/rspec-expectations/v/3-9/docs/built-in-matchers/have-attributes-matcher.

From what I saw in the docs and in the code, SitePrism::RSpecMatchers seems to define new have_* matchers. Is this still necessary since RSpec already have the have_xxx matcher?

Handling Dynamic Locators

How to handle Dynamic locators??
For E.g //input[contains(text()='sometext')] where sometext must be replaced by a certain value.
As in Site prism it returns CapybaraNodeElements, should I define these kind of xpaths as string in Locators section?

uninitialized constant SitePrism when using without Rails

When I use SitePrism with non rails, I can't inherit from SitePrism::Page.
On rails project this is working correctly, cause gems are loaded in spec_helper

Only workaround for this is not to require site-prism in spec helper and add in spec_helper:
require 'bundler'
Bundler.require(:default)

OS: Ubuntu 16.04
SitePrism version - 3.3
Capybara version - 3.25.0

Rework unit tests into using Dummy Capybara app

Issue to raise for SitePrism framework

Fix unit tests to use a dummy capybara app

Environment

N/A

Expected Behaviour

Unit tests to be easier to write, removal of rspec stubs

Actual Behaviour

Reliant on rspec stubs

Steps to reproduce

# define full html
html = <<-HTML
  <html><head></head><body><a href="#">a</a><table id="my-table"></table></body></html>
HTML

# define minimal positive puma app
Capybara.app = ->(_env) { [200, {}, html] }

# continue with loading pages as per usual
page = SitePrism::Page.new
page.load
page.html # dumps the capybara app html forced

element_checker_spec.rb - Fails in isolation

Issue to raise for SitePrism framework

Running the element_checker_spec on its own fails in isolation

Environment

Ubuntu 18.04 LTS - site_prism at master

Expected Behavior

rspec spec/site_prism/element_checker_spec.rb passes

Actual Behavior

rspec spec/site_prism/element_checker_spec.rb fails. Likely due to some leaking cross specs.

Steps to reproduce

Pull master, run in isolation

Custom Elements

This is more of a question than an issue. We have “elements” on the page that require more sophisticated set of actions to interact with the element beyond the set of public API methods on capybara’s Element. For example our “masked text died” requires passing in an option to set or in we have a date picker that needs some trickery to be able to set its value. I’d like to subclass Element and wrap those concepts up. It would be cool if this gem can have a declaration to load those classes instead of the normal Element. If that’s out of this gems control then perhaps a convention of a “Element Wrapper” would work:

element :foo, “#some-I’d”, wrapper: SpecialTextField

Where the wrapper just takes in the capybara element on initialization and proxies calls to the element. Within the wrapper, you can define methods that are special to your weird element.

Site_prism started to throw uninitialized constant SitePrism::Section error

Environment

  • Operating System ( Windows)
  • What Gems / Versions you are using
    site_prism v 3.3
    capybara (~> 3.25.0)
  • I have Cucumber tests
  • Browser/s Driver/s being used - headless chrome on Docker container or local terminal

Expected Behavior

site_prism v 3.3 installed and working as before

Actual Behavior

site_prism v 3.3 is auto installed with bundle_install but now gives following error when running tests:
uninitialized constant SitePrism::Section
Did you mean? Exception (NameError)
image

it ran successfully last time at 01 Jul 2019 at 13:39:38 BST

Steps to reproduce

I didn't change anything on my code base, it used to work fine with site_prism (3.2) but after bundle install now I have site_prism (3.3) and site_prism-all_there (~> 0.1.0) site_prism-all_there (0.1) in my Gemfile.lock and my tests doesn't run anymore and throws below error.

Headers_and_footers_rb in shared sections:
class Header < SitePrism::Section
  set_default_search_arguments '.header'
  element :provider_name, '.header__provider-name'
  element :provider_logo, '.header__service-logo'
end

admin_homepage.rb that uses headers_and_footers 
require 'capybara'
require 'capybara/cucumber'
require 'selenium-webdriver'
require 'site_prism'
require_relative '../page_objects/shared_sections/headers_and_footers'
require_relative '../page_objects/shared_sections/navigation_bars'

class AdminHomePage < SitePrism::Page
  set_url '/home.htm'
  section :header, Header
  section :footer, Footer
end

and then calling it from .rb
When(/^Admin clicks allocate cases button$/) do
  @home = AdminHomePage.new
  @home.quick_links.allocate_cases_link.click
end

Add the ability to select elements by their text

I would like to have the ability to select elements by the text they contain. For example:

class DummyPage < SitePrism::Page
  element :homepage_button, ".button", text: "Homepage"
end

This could be implemented using Capybara's page.users_with_text.

This same request was made in an issue on the old repo, but I'd like to revisit the decision not to implement this. That decision seems to have been made based on an opinion that selecting elements by text is bad. However, in my opinion, feature tests that use capybara and site_prism should test things as closely to the user's perspective as possible. User's do not know about CSS classes, ids, etc. All they see when they're viewing the page is the text and boxes and such. If I were to describe to a user how to navigate to something, I would not say "Click on the #button-homepage button" I would say "Click the button with the text "Homepage"". I would like to do the same in my feature tests.

This approach also has the advantage that it decouples the tests from the HTML structure a bit. If CSS classes or IDs change because of design or business decisions, but the button with that text is still on the page, the test does not break.

SitePrism does not delegate Capybara in-built matchers to root_element (3.30 bug)

Issue to raise for SitePrism framework

When running capybara matchers, the current_scope failure is only triggered for have_link. have_text seems to be fine. Maybe worth investigating more.

@tgaff - This is the 3.30 bug we found with capybara.

Environment

  • N/A

Expected Behavior

test runs

Actual Behavior

current_scope failure

Steps to reproduce

use have_link on site_prism 3.42 with capybara > 3.30

site_prism is locked to site_prism-all_there v0.3, so it's not possible to install latest version (1.0.1)

Environment

  • Operating System (Mac / Windows / Ubuntu e.t.c.):
    Unrelated
  • What Gems / Versions you are using (Specifically site_prism and capybara)
    site_prism v3.7.3, site_prism-all_there v1.0.1 (trying to install)
  • How you're interacting with the Framework (Cucumber Tests / RSpec Units / Minitest)
    Unrelated
  • Browser/s Driver/s being used - with version numbers
    Unrelated

Expected Behavior

Able to install both latest versions of site_prism and site_prism-all_there

Actual Behavior

# after adding site_prism-all_there to Gemfile

~/dev/app$ bundle
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/.
You have requested:
  site_prism-all_there ~> 1.0, >= 1.0.1

The bundle currently has site_prism-all_there locked at 0.3.2.
Try running `bundle update site_prism-all_there`

If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`

~/dev/app$ bundle update site_prism-all_there
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Bundler could not find compatible versions for gem "site_prism-all_there":
  In Gemfile:
    site_prism-all_there (~> 1.0, >= 1.0.1)

    site_prism (~> 3.7) was resolved to 3.7.3, which depends on
      site_prism-all_there (>= 0.3.1, < 1.0)

Steps to reproduce

  1. Add both gems to Gemfile:
    # Gemfile
    ...
    gem 'site_prism', '~> 3.7'
    gem 'site_prism-all_there', '~> 1.0', '>= 1.0.1'
    ...
  2. run bundle install

There is a way to make class element load after initialize?

I want to use an instance variable to receive a string and pass to element selector, but it seems that initialize method is running after the elements and his value is nil.

class AgentChat < SitePrism::Page
    
    element :chat_button_hover, '.ft-chatAgent'
    element :chat_list_item, '.ft-list-agent .item', text: @agent_name #nil value
    element :chat_input, '.chat-resizable.active .form .emojionearea-editor'
    element :chat_list, '.chat-resizable.active', text: @agent_name #nil value

    def initialize (agent_name)
        @agent_name = agent_name
    end

    def chat_agent_hover
        chat_button_hover.hover
    end
    
    def open_chat
        chat_list_item.click
    end

    def send_message(message, enter_key)
        chat_input.click
        chat_input.send_keys(message, enter_key)
    end

    def get_messages_on_chat
        chat_list.text
    end
end

Here is when i create an instance of this AgentChat class.

Dado("abriu o chat do agente {string}") do |name|
    @date = Date.today.to_s
    
    @chat_send_agent = AgentChat.new(name)
    @chat_send_agent.chat_agent_hover
    @chat_send_agent.open_chat
end

Hope someone could help me out.

How can I wait for a section's element?

I stumbled upon a situation where I need to wait for an element that resides in a section block. I would like to know how can I solve this problem. Thank you!

Add not_expected_elements function for a page/section class

From site_prism created by faceless7171: natritmeyer/site_prism#344

Right now we can specify expected_elements for a page/section class. It would be great if we will have ability to specify elements that we are not expecting to see on the page by default.

Expected behavior:
ability to add elements/sections on the page/section description to the not expected elements, so be_all_there matcher will ignore this elements/sections.

Example:

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
     end
  end
  element :e7, 'e7'
  
  not_expected_elements :e2, :e7
end

Then expect(HomePage).to be_all_there will check only existence of e1, s2 elements.

Unclear if "click" waits for element to be visible

Does click wait for an element to be visible before clicking it or does it depend on certain factors or Capybara settings? If so, which ones?

I have a flaky test where clicking a link sometimes brings us to the linked page and sometimes does not and no request for that page is sent to the server. I'm wondering if it's because the link is not yet visible.

New Work: Gem Updates

The first of a series of Issues I'm creating for outstanding "small" tasks that people can contribute to if they want to get involved with site_prism as an Open Source Project.

Problem to fix

Our low_spec gemfile and suite gemspec need validating and perhaps bringing slightly more up to date

Ideal behaviour

The suite gemspec should always be tracking as far back as it can do realistically, but our main two dependencies (addressable and capybara), shouldn't be so ancient that they are out of support.

Investigate at what point we cover a reasonable amount of users still, and then update the files accordingly.

We may also be able to go back down from 3 gemfiles to 2 in travis, which would massively speed up our CI times.

Steps to validate work is correct

bundle exec rake should still pass fully green.

Calling Section#within raises NoMethodError

Environment

  • Operating System: Ubuntu
  • Gems / Versions you are using:
    • site_prism 3.4.2
    • capybara 3.32.2
  • How you're interacting with the Framework: Minitest (5.14.1)
  • Browser/s Driver/s being used:
    • Remote chrome via browserless/chrome:1.31-chrome-stable Docker image
    • Cuprite 0.10

Expected Behavior

The following works as described in the docs:

my_page.sections.first.within do
   assert_text "some text"
end

my_page.form.within do
   assert_text "some text"
end

Actual Behavior

In both cases I see:

NoMethodError: undefined method `within' for Obsolete #<Capybara::Node::Element>:Capybara::Node::Element

Steps to reproduce

I see these exceptions even for the simplest scenarios:

class NewGroupPage < SitePrism::Page
  set_url "/groups/new"

  section :form, SitePrism::Section, "#new_message"

  load_validation { has_form? }
end

test "page should work" do
  page = NewGroupPage.new
  page.load

  page.form.within do
    assert_text "Save me"
  end
end

`loaded?` should raise an error if there are no load validations

Environment

  • Mac
  • site_prism 3.4.1, capybara 3.30.0
  • RSpec
  • Apparition

Expected Behavior

page.loaded? #=> raise exception if there are no load validations

Actual Behavior

page.loaded? #=> true if there are no load validations

Steps to reproduce

class ComplexPage < SitePrism::Page
  set_url "/complex-page"
  # nothing in here
end

complex_page = ComplexPage.new
# ...
click_on "Go to complex page"
expect(complex_page).to be_loaded

I think it's unexpected that loaded? returns true by default. If the page doesn't know how to check if it's been loaded (ie. there are no load validations defined) then it should raise an error.

[help needed] Programmatically set of an element

Hi,

Is there a way to set an element Programmatically?
The app I'm testing is a have a user of [data-test-id]. This identifier usually has an id that is related to a specific object of the application.

ex:
We have a list of users and each row have a <li data-test-id="user-434353"> Name </li>

What is the best approach to find those elements?

individual Section in sections do not exec block

From site_prism created by tgaff: natritmeyer/site_prism#395

Issue to raise for SitePrism framework

  section :my_section, MySection, 'div.locator'

  @page.my_section do |section|
    section.something # executes
  end

 sections :my_sections, MySection, 'div.locator'  #

  @page.my_sections.first do |section|
    section.something # does not execute block
  end

While the second behavior is not explicitly documented, one would it expect it to work since :sections is in many ways an Array-like of :section. Not sure whether this should be considered a bug or feature-request, but failing to execute the block could lead to incorrectly-passing tests.

Environment

  • OSX
  • SitePrism itself at recent master 4c568dd
  • SitePrism's own cucumber scenarios
  • firefox default

Expected Behavior

We can exec inside a section similar to Capybara within functionality on an individual section. But on an array of sections generated by :sections this does not work.
I expected that my block would be executed when passed as @page.my_sections {|s| raise 'ermagerd'}

Actual Behavior

Code in the block is not exec'd

Steps to reproduce

  1. clone https://github.com/tgaff/site_prism/tree/tg/sections_dont_exec_blocks
  2. cucumber -r features
  3. observe test failure

cucumber scenario

In the below I verify that on the Section features we do execute the contents of the block.
However when it comes to the Sections features, the same functionality fails - the block is not executed. Specifically the tests fail with:

    Then I can execute in the context of a section using a block # features/step_definitions/sections_steps.rb:22

      expected: 2
           got: 0

      (compared using ==)
       (RSpec::Expectations::ExpectationNotMetError)
      ./features/step_definitions/sections_steps.rb:39:in `"I can execute in the context of a section using a block"'
      features/sections.feature:21:in `Then I can execute in the context of a section using a block'

Failing Scenarios:
cucumber features/sections.feature:19 # Scenario: access elements in the section by passing a block

91 scenarios (1 failed, 90 passed)
229 steps (1 failed, 228 passed)
0m23.693s

Patch that reproduces this behavior

diff --git a/features/sections.feature b/features/sections.feature
index 1705336..4f9aee8 100644
--- a/features/sections.feature
+++ b/features/sections.feature
@@ -15,3 +15,7 @@ Feature: Interaction with groups of elements
   Scenario: anonymous sections collection
     When I navigate to the nested section page
     Then I can see a collection of anonymous sections
+
+  Scenario: access elements in the section by passing a block
+    When I navigate to the nested section page
+    Then I can execute in the context of a section using a block
diff --git a/features/step_definitions/section_steps.rb b/features/step_definitions/section_steps.rb
index a56cd57..45e5bb0 100644
--- a/features/step_definitions/section_steps.rb
+++ b/features/step_definitions/section_steps.rb
@@ -12,13 +12,19 @@ Then('I can see a section in a section') do
 end

 Then('I can access elements within the section using a block') do
+  block_inner_executions = 0
+
   expect(@test_site.home).to have_people

   @test_site.home.people do |section|
+    block_inner_executions += 1
+
     expect(section.headline.text).to eq('People')

     expect(section).to have_individuals(count: 4)
   end
+
+  expect(block_inner_executions).to eq 1
 end

 Then('I cannot access elements that are not in the section using a block') do
diff --git a/features/step_definitions/sections_steps.rb b/features/step_definitions/sections_steps.rb
index f57cbe7..4e1f0c9 100644
--- a/features/step_definitions/sections_steps.rb
+++ b/features/step_definitions/sections_steps.rb
@@ -17,3 +17,24 @@ Then('I can see a collection of anonymous sections') do

   expect(anonymous_sections.size).to eq(2)
 end
+
+
+Then('I can execute in the context of a section using a block') do
+  block_inner_executions = 0
+
+  expect(@test_site.nested_sections).to have_search_results(count: 4)
+
+  @test_site.nested_sections.search_results.first do |sec|
+    block_inner_executions += 1
+    expect(sec).to be_an_instance_of(SitePrism::Section)
+    expect(sec).to have_text('Result 0')
+  end
+
+  @test_site.nested_sections.search_results.last do |sec|
+    block_inner_executions += 1
+    expect(sec).to be_an_instance_of(SitePrism::Section)
+    expect(sec).to have_text('Result 3')
+  end
+
+  expect(block_inner_executions).to eq 2
+end

SitePrism::ElementVisibilityTimeoutError on a Chrome headless mode

I updated the chromedriver to be the same as the Google Chrome browser: version 80.

The same code works perfectly on a :selenium_chrome mode, but it fails on a :selenium_chrome_headless.

It always returns SitePrism::ElementVisibilityTimeoutError, even passing a amount of seconds to wait for it.

Environment

  • Windows 10 Enterprise
  • site_prism (3.4.2) & capybara (3.31.0)
  • Cucumber
  • ChromeDriver 80.0.3987.16 (320f6526c1632ad4f205ebce69b99a062ed78647-refs/branch-heads/3987@{#185})

Expected Behavior

The element is found between the set time.

Actual Behavior

It fails with SitePrism::ElementVisibilityTimeoutError.

Steps to reproduce

Piece of the code:

within_window(@topics_window) do
    @topics_page.wait_until_sorter_view_visible(wait: 10)
    @topics_page.sorter_view.click
    puts "\t#{'=' * 27} \n| Tópico Mais Visualizado |\n #{'=' * 27}"
    puts "\t#{@topics_page.topics.first.find('.title').text}"
end

Feature: Generate way for SitePrism to regenerate #root_element (Fixes Stale Element)

Expected Behavior

When using a section which becomes stale, when trying to access any method or locator inside it, SitePrism should firstly try to regenerate the root_element and then if not, provide some API for doing so, to mitigate un-wanted StaleElements being caused by headers/footers being altered.

Actual Behavior

When using a section which becomes stale, when trying to access any method or locator inside it, a StaleElement is thrown

Steps to reproduce

N/A

[feature request] Add missing_elements method

Issue to raise for SitePrism framework

It's very useful for debugging purposes to have
missing_elements method which will return self.class.expected_items - expected_elements_present_on_the_page

[Feature request] - ViewComponent support

ViewComponent is a new library from Github that is gaining support quickly. It encapsulates views and partials into objects that can be easily rendered and tested. However, as far as I can tell, there is not a great way to use the Page Object Model and specifically site_prism with this awesome new tool.

In my head, I think the ideal way this would work is I would create a section class (inheriting from SitePrism::Section), then instantiate that with the html output coming from render_inline(MyComponent.new(...)).to_html from ViewComponent's helpers. Then I could interact with that in the same way I could any other section on a page. I could also reuse that section class in a feature test when I'm using a browser driver to interact with the page, getting double bang for my buck.

I'm not sure exactly what would be needed to make this work. Essentially I think I want to instantiate a Section without a Page, and without requiring capybara to pre-define a page object. I'm not sure if this requires any changes to site_prism or even capybara, or if I'm just missing how to do this with the current version of the library.

Any help with this is greatly appreciated!

[feature request] Avoid anonymous sections in case section defined with a block

It will be useful currently anonymous sections defined with block argument to have a class name.

Proposed solution: deduce_section_class to be rewritten similar to this:

   def deduce_section_class(base_class, &block)                                                                            
       klass = base_class                                                                                                    
       if block_given?                                                                                                       
         const_set(@_last_section_name.to_s.camelcase, Class.new(klass || SitePrism::Section))                               
         klass = const_get(@_last_section_name.to_s.camelcase)                                                               
         klass.class_eval(&block)                                                                                            
       end                                                                                                                   
       return klass if klass                                                                                                 
                                                                                                                             
       raise ArgumentError, "You should provide descendant of \                                                              
 SitePrism::Section class or/and a block as the second argument."                                                            
     end

where @_last_section_name is a name parameter from section/sections call.

Why?

I'm currently working on an internal framework (going to make it public someday) for mobile automation based on site_prism which identify arguments based on element/section name and section/page class name

For example, I have a page object classes defined like this

# module SitePrismDSLExtension extend and override/monkeypatch some basic site_prism DSL methods
class BaseSection < Section
   include SitePrismDSLExtension
end
class BasePage < Section
  include SitePrismDSLExtension
end

class Row < BaseSection
   set_default_search_arguments
   element :column1
   element :column2
end

class Home < BasePage
   element :header
   sections :rows1, Row

   sections :rows2, Row do
      element :column3
   end

   section :rows3, Row do
      element :column4
   end
end

This DSL extension identifies locator based on class name and element name. For example, a locator for column1, column2 and default search args for section Row will be looked in YAML file row.yml;
header, rows1 and rows2 in home.yml;
column3 will be defined in home.yml but nested

header: 
   locator: header_locator
# rows1 may use default locator
rows2: 
  locator: rows2_locator
  column3:
     locator: column3_locator

This allows to extract locators to another abstract layer and use config overlay to define locators based on device or platform (iOS and Android) without defining separate page object for same page structure in case locator differ for specific platform/device.

The logic of mapping depends on the class name. If the page class name is Home it will be looking for locators in home.yml. If section class name is Row it will be looking for locators in row.yml etc.

The problem arise for section definitions like rows2 with section name as well as a block. The actual class won't have a name (anonymous). Finding superclass of this class may slightly help, but will create another issue - row.yml will have to hold locators for all the possible extensions of Row section and it will hold no binding to the parent section/page. To avoid this problem 2 things are needed:

  1. Section class should have a name
  2. Name of the class should be based on parent section/page name + section name
    For example, for our case, it can be Home::Rows2 < Row and Home::Rows3 < Row

This should not be a breaking change as it only changes internal implementation.

page.displayed? specs fail when all specs run but not when run individually

For some reason, some of our specs fail consistently when all specs are run, but never fail when run individually. Using expect(page).to be_displayed it will time out waiting for the page to be displayed (even bumping Capybara max wait to 10 seconds doesn't fix it), but always pass when run individually. This makes me think there is some kind of clean up that is not happening between test runs.

Environment

  • Operating System: Mac (local), Linux (GitHub Actions CI)
  • What Gems / Versions you are using
    • capybara 3.36.0
    • cuprite 0.13
    • site_prism 3.7.3
    • rspec 3.11.0
    • rspec-rails 6.0.1
  • How you're interacting with the Framework
    • RSpec Rails System Specs
  • Browser/s Driver/s being used - with version numbers
    • Cuprite (Chrome)

Expected Behavior

Pass consistently

Actual Behavior

Fails consistently when running entire suite.

Steps to reproduce

Sorry, I'm not sure how to reproduce this issue. I wonder if maybe a timer from a previous spec is not getting cleaned up.

[feature request] - Run load validations on instantiation - not `#load`

Issue to raise for SitePrism framework

Ideally we should be able to configure when to run load validations in a nice clear way - Config option e.t.c.

Environment

N/A

Expected Behavior

Have some config switch that modifies the initialize method to run load validations

Actual Behavior

I currently modify my app class to run @class ||= Class.new.tap(&:when_loaded)

Steps to reproduce

N/A

NB: This would not be viable for site_prism 3.x - It would need to go into a 4.x release. With the behaviour experimental so default turned off.

How to fill input dates when I've mapped them with Site Prism?

I'm developing automated tests with SitePrism, Ruby and Capybara and I didn't find a way to fill input dates when I'm using Site Prism.

I know I can use the Capybara's fill_in method and pass the field and the value in the parameters. But when I map the field in a page object, fill_in is not enough to my automation write the input date field with the date.

How can I work with Site Prism and Capybara together in this case, if it's possible?

Thanks!

iFrames - Full scoping capabilities not confirmed to be working when defining iFrames in Sections

From site_prism created by luke-hill: natritmeyer/site_prism#341

Issue to raise for SitePrism framework

Need to re-triage this on a sample page. But it appears as though all SitePrism iFrame locators are queried at a Capybara.current_session level. meaning any section scoping will be ignored.

Environment

All

Expected Behavior

If 2 iframes with same styling exist on a page at different scoping levels, you should be able to locate the relevant one within your page/section scope.

Actual Behavior

If 2 iframes with same styling exist on a page at different scoping levels, then you may get an ambiguous error or similar issues due to the code not working as intended

A way to work code completion

I have classic element(s) and section(s) definitions on page classes. I would like to use code completion while searching for those.

Example, while using ruby mine, you can find the methods inside page object class but you can not find the elements.
This would avoid wrong typing elements,
Finding available elements much faster,

Is there a pattern that I can change the page objects or element to support this?

New Work: Clean up and isolate Test Helpers properly

The first of a series of Issues I'm creating for outstanding "small" tasks that people can contribute to if they want to get involved with site_prism as an Open Source Project.

Problem to fix

Our Test Suite is kind of mangled. We should be using spec/support files and including them in, instead of muddying the waters

Ideal behaviour

All of our helpers should live in small diet files located in spec/support (And be namespaced under SpecSupport::xxx

Once we've done this, use RSpec to load these into the RSpec runtime, and then we can still access them across the suite.

As an extension, we could also look to isolate the shared_contexts and suchlike in their own support folders and load those in

Steps to validate work is correct

bundle exec rake should still pass fully green.

New Work: Rubocop RSpec Fixes

The first of a series of Issues I'm creating for outstanding "small" tasks that people can contribute to if they want to get involved with site_prism as an Open Source Project.

Problem to fix

We have a series of rubocop overrides in rubocop_todo.yml

Ideal behaviour

These need removing, and manually fixing up in the spec files.
You can fix up "some" of these, or all of these. Whatever you find easiest. There is a reasonable amount of work to fix up.

Steps to validate work is correct

bundle exec rake should still pass fully green.

Upgrading from 4.0.0 to 4.0.1 throws "uninitialized constant Capybara::DSL"

Issue to raise for SitePrism framework

I'm guessing this issue is related to the latest changes regarding autoload.

We're using Capybara 3.39.1. When upgrading site_prism from 4.0.0 to 4.0.1 we get this error on load (running rspec or rails itself, same result):

$ RAILS_ENV=test bin/rails c
$ /home/oboxodo/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/site_prism-4.0.1/lib/site_prism/page.rb:14:in `<class:Page>': uninitialized constant Capybara::DSL

    include Capybara::DSL
                    ^^^^^ (NameError)
	from /home/oboxodo/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/site_prism-4.0.1/lib/site_prism/page.rb:13:in `<module:SitePrism>'
	from /home/oboxodo/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/site_prism-4.0.1/lib/site_prism/page.rb:3:in `<main>'
...

Environment

  • Operating System: Ubuntu
  • What Gems / Versions you are using: capybara 3.39.1, site_prism 4.0.1
  • How you're interacting with the Framework: Rspec
  • Browser/s Driver/s being used - with version numbers: Cuprite 0.14.3

Expected Behavior

Tests would run as they were running with v4.0.0.

Actual Behavior

"uninitialized constant Capybara::DSL"

Steps to reproduce

Upgrade from 4.0.0 to 4.0.1 then run any rails command loading the app in test env.

Capybara causing deprecation warnings in Ruby 2.7

Capybara 3.28.x includes code that throws keyword parameter deprecation warnings in Ruby 2.7 and does not work in Ruby 3+.

These issues were fixed in 3.30.0 and all versions up to 3.32.0 are supported by Ruby 2.4 (currently set in .ruby-version).

PR #78 increases the maximum allowed version and fixes a test broken by the upgrade

Can't match Section values with composable matchers

I have a table in a page that returns items that match certain filters. I am trying to write a test that verifies those rows have the correct values as the filters change, but I am unable to do this cleanly using matcher composition.

Here is some simplified code demonstrating the issue

class Row < SitePrism::Section
  element :valueA, 'td:nth-of-type(3)'
  element :valueB, 'td:nth-of-type(2)'
end

class TablePage < SitePrism::Page
  set_url '/table_page'
  sections :rows, OrderTableRow, '#my_table tbody tr'
end

describe 'table page' do
  it 'updates the table with changing filters' do
    items = []
    items << createItem(valA: 'foo', valB: 'bar')
    items << createItem(valA: 'baz', valB: 'boz')
    item_matchers = items.map do |i|
      have_attributes(valueA: have_text(i.valA), valueB: have_text(i.valB))
    end
    
    p = TablePage.new
    p.load
    expect(p).to have_rows(count: 2)
    expect(p.rows[0].valueA).to have_text(items[0].valA) # this passes
    expect(p.rows[0]).to have_attributes(valueA: items[0].valA) # this gives an error that valueA is a Capybara::Node::Element
    expect(p.rows[0]).to match(valueA: items[0].valA) # this gives an error that valueA is a Row
    expect(p.rows).to match(item_matchers) # this is what I want to write but gives the error above
end

2.14 has breaking changes

Issue to raise for SitePrism framework

I am trying to upgrade to the latest SitePrism and I found out the error I am getting started happening at 2.14

I can not find a mention about a breaking change in the changelog
https://github.com/site-prism/site_prism/blob/master/CHANGELOG.md#214---2018-06-22

it seems that a new validation was introduced to ensure Sections has child elements.
but in the large project I am working on, its not straight forward to defined all of those.

Note that I never setup site_prism and I dont have previous experience with this gem.

Environment

  • Operating System (Ubuntu)
  • site_prism 2.14 up, capybara is locked at 2.18 until we can upgrade site_prism
  • rspec 3.7.0

Expected Behavior

my tests should pass.
I wish there might be a configuration option to maybe fallback to the previous behaviour
or sufficient documentation to help us upgrade.

I don't believe such breaking changes should have occurred before 3.0 IMO

Actual Behavior

ArgumentError:
  You should provide descendant of SitePrism::Section class or/and a block as the second argument.
# /root/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/site_prism-2.14/lib/site_prism/element_container.rb:258:in `deduce_section_class'
# /root/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/site_prism-2.14/lib/site_prism/element_container.rb:247:in `extract_section_options'
# /root/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/site_prism-2.14/lib/site_prism/element_container.rb:77:in `sections'
# ./spec/page_objects/employees/totals_based_payroll_page.rb:8:in `<class:TotalsBasedPayrollPage>'

Steps to reproduce

this is how my sections was defined
sections :list_items, PayrollItem, 'tbody tr'

Support for finding inputs by value, i.e. Capybara find_field query options

Expected Behavior

If I have an element that represents an input element with a value, I should be able to wait for that element to be visible with a particular value like Capybara's find_field(id: 'someid', with: 'somefieldvalue')

E.g.
class MyPage < SitePrism::Page
element :my_input, '#input-id'
end

page = MyPage.new
page.load
page.wait_for_my_input_visible(with: 'somefieldvalue')

Actual Behavior

page.wait_for_my_input_visible(text: 'somefieldvalue') is the closest I can get and it does not work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.