capybara

Testing the draft attribute of this post model (Rspec + Capybara)

淺唱寂寞╮ 提交于 2019-12-25 05:25:51
问题 I want to write a test using Rspec and Capybara. I have a Post model and I want to add a draft attribute to it. If the user checks that field the post is saved as draft ( draft = true ). Only posts that have he attribute draft = false will show in the post index page. Posts with draft = true will only show in the page of the user who created that post. I've never made a Rspec + Capybara test in my life. So I was wondering if someone could tell me how to start or give me an example. Thanks in

Why rspec doesn't wait completion of previous command?

青春壹個敷衍的年華 提交于 2019-12-25 03:44:26
问题 My rails-app contain rspec-tests using Capybara poltergeist (which uses phantomjs). Frontend is Backbone.js. Some tests are sometimes passed, sometimes not. Debugging shows that the right content is not loaded at the time of inspection. If i add an delay, e.c. sleep (inspection_time = 1), then the test passes. describe 'Direct visit page / # / desk / page / [ID]' do before {sign_in user} it 'should contain page title' do visit "/#/desk/pages/#{page.id}" #sleep (inspection_time = 1) expect

How do you get rspec to output what it encountered rather than it “didn't find what it expected”?

余生长醉 提交于 2019-12-25 02:50:32
问题 I have been struggling to using ruby/rspec/capybara/devise to test my code. A simple test I am trying to write is for signing in. I have a valid user sign in and expect to see an h1 tag as defined in the following code: describe "Authentication" do subject { page } describe "with valid information" do let(:user) { FactoryGirl.create(:user) } before { sign_in_with user.email } it { should have_css('h1', text: "Welcome to the Test") } end end Problem is that I get this in return: 1)

Capybara How to use within_frame for the only iframe in the page without id

守給你的承諾、 提交于 2019-12-25 02:28:19
问题 I have an in the the page that I need to test with Cucumber and Capybara, the iframe does not have a class or id attribute but it's the only iframe on the DOM. How can I use the within_frame capybara method? 回答1: use find to get the element and pass it to the within_frame method. iframe = find('iframe') within_frame(iframe) do # expect something here end 回答2: If you're using a recent version of Capybara the locator argument to within_frame is optional if there's only one iframe on the page

capybara regex xpath not working

好久不见. 提交于 2019-12-24 18:07:58
问题 I have the following hmtl code. li id is increasing sequentially, and I want to generate regex so as to use in xpath but is not working: irb#1(main):044:0* find(:xpath, "//li[@id = 'divPictureAndPrices_productListItem1']") => #<Capybara::Node::Element tag="li" path="/html/body/div[2]/div[7]/div[2]/div/div[3]/ol/li[2]"> irb#1(main):045:0> irb#1(main):017:0* all(:xpath, "//li[matches(@id, '^divPictureAndPrices_productListItem\d{0,2}$')]") Selenium::WebDriver::Error::InvalidSelectorError:

Upload file to an input area using FileApi

痞子三分冷 提交于 2019-12-24 16:19:25
问题 I'm using Capybara + RSpec and the capybara_webkit as driver. And a JS uploader with FileApi. I'm trying to upload three images here: <input type="file" name="image" multiple="" accept="image/*"> When I click on the "Select photos" button (on the browser), it opens the typical window where I can select 3 files from my computer . I'd like to know how to reproduce it on capybara, as when the photos selector opens, I don't have the control on it. I tried to add the pictures to my tests folder

How to test jQuery TokenInput field using Selenium

纵然是瞬间 提交于 2019-12-24 15:22:11
问题 I'm unable to test a Tokeninput field in a form using selenium. The situation is when we type something, it gives a list to options to select but those options aren't part of the DOM. The text fills the field but doesn't select the item. The code which I have written is: Given admin user is on schedule interview page And he select "obie[1]" and "DHH[1]" from the candidate name(s) auto sugget field **step defination** Given /^he select "([^"]*)" and "([^"]*)" from the candidate name\(s\) auto

Difference between click_on and click_link?

纵饮孤独 提交于 2019-12-24 15:01:17
问题 I am writing request specs and I am using poltergeist-1.0.2 and capybara-1.1.2. I have the following code: login_as @user, 'Test1234!' click_on 'Virtual Terminal' the login has flash message that shows to the user that he is successfully logged in. When I am using click_link, the spec fails because Capybara can't find element 'Virtual Terminal' but when I am using click_on everything passes. 'Virtual Terminal' is not a button, it is a link. What is the difference between click_on and click

RSpec + Capybara: How do I test a Bootstrap progress bar

ぃ、小莉子 提交于 2019-12-24 13:39:20
问题 I am testing a page that has a bootstrap progress bar using RSpec. How do I test the different Aria attributes in the Div? <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width: 40%"> </div> I appreciate any help you can provide. Thanks! 回答1: You can get the attribute values of an element using the [] method. For example: find('div.progress-bar')['aria-valuenow'] #=> "40" find('div.progress-bar')['aria-valuemax'

button_to form submittal working in browser but failing rspec/capybara test with routing error

蓝咒 提交于 2019-12-24 13:22:18
问题 I'm writing integration tests using rspec and capybara for a rails4 app that cover existing functionality (I was lazy when I first wrote the app). The following submit button works properly in the browser (Chrome) and redirects to a success page (as expected) <div class="actions"> <%= button_to "RSVP Now", new_event_attendee_path(f), :id => "open-contacts-dialog-btn", :class => "inbox-sf-add-btn tip", :style => "background:lightgreen" %> </div> But, the following test fails, describe "should