Rails rspec capybara selector not found
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have this integration test using capybara:
RSpec.describe 'adding a project', type: :system do
it 'allows a user to create a project with a tasks' do
visit new_project_path
fill_in 'Name', with: 'Project Runaway'
fill_in 'Tasks', with: 'Choose Fabric:3nMake it Work:5'
click_on('Create a project')
visit projects_path
@project = Project.find_by(name: "Project Runaway")
expect(page).to have_selector(
"#project_#{@project.id} > td.name", text: "Project Runaway"
)
expect(page).to have_selector(
"#project_#{@project.id} > td.total-size", text: "8"
)
end
end
Somehow it can't find the last selector (td.total-size):
Failures:
1) adding a project allows a user to create a project with a tasks
Failure/Error:
expect(page).to have_selector(
"#project_#{@project.id} > td.total-size", text: "8"
)
expected to find visible css "#project_1 > td.total-size" with text "8" but there were no matches. Also found "3", which matched the selector but not all filters.
# ./spec/system/add_project_spec.rb:14:in `block (2 levels) in <main>'
But the test is passed when I comment the last assertion. But failed if I commented the td.name part and left the td.total-size uncommented.
Here is the HTML page:
<h1>All Projects</h1>
<table>
<thead>
<tr>
<td>Project Name</td>
<td>Total Project Size</td>
</tr>
</thead>
<tbody>
<% @projects.each do |project| %>
<tr class="project-row", id="<%= dom_id(project) %>">
<td class="name"><%= project.name %></td>
<td class="total-size"><%= project.total_size %></td>
</tr>
<% end %>
</tbody>
</table>
I need to make sure all the data displayed on the table is right. Anyone has the same experience?
For additional information, I am using:
- Rails 5.2.1
- Ruby 2.5.0
- Rspec 3.7.1
- Capybara 3.11.1
Thanks in advance
Updated
<body>
<h1>All Projects</h1>
<table>
<thead>
<tr>
<td>Project Name</td>
<td>Total Project Size</td>
</tr>
</thead>
<tbody>
<tr class="project-row", id="project_1">
<td class="name">Project Runaway</td>
<td class="total-size">8</td>
</tr>
</tbody>
</table>
</body>
This is what the html rendered.
ruby-on-rails rspec tdd capybara
add a comment |
I have this integration test using capybara:
RSpec.describe 'adding a project', type: :system do
it 'allows a user to create a project with a tasks' do
visit new_project_path
fill_in 'Name', with: 'Project Runaway'
fill_in 'Tasks', with: 'Choose Fabric:3nMake it Work:5'
click_on('Create a project')
visit projects_path
@project = Project.find_by(name: "Project Runaway")
expect(page).to have_selector(
"#project_#{@project.id} > td.name", text: "Project Runaway"
)
expect(page).to have_selector(
"#project_#{@project.id} > td.total-size", text: "8"
)
end
end
Somehow it can't find the last selector (td.total-size):
Failures:
1) adding a project allows a user to create a project with a tasks
Failure/Error:
expect(page).to have_selector(
"#project_#{@project.id} > td.total-size", text: "8"
)
expected to find visible css "#project_1 > td.total-size" with text "8" but there were no matches. Also found "3", which matched the selector but not all filters.
# ./spec/system/add_project_spec.rb:14:in `block (2 levels) in <main>'
But the test is passed when I comment the last assertion. But failed if I commented the td.name part and left the td.total-size uncommented.
Here is the HTML page:
<h1>All Projects</h1>
<table>
<thead>
<tr>
<td>Project Name</td>
<td>Total Project Size</td>
</tr>
</thead>
<tbody>
<% @projects.each do |project| %>
<tr class="project-row", id="<%= dom_id(project) %>">
<td class="name"><%= project.name %></td>
<td class="total-size"><%= project.total_size %></td>
</tr>
<% end %>
</tbody>
</table>
I need to make sure all the data displayed on the table is right. Anyone has the same experience?
For additional information, I am using:
- Rails 5.2.1
- Ruby 2.5.0
- Rspec 3.7.1
- Capybara 3.11.1
Thanks in advance
Updated
<body>
<h1>All Projects</h1>
<table>
<thead>
<tr>
<td>Project Name</td>
<td>Total Project Size</td>
</tr>
</thead>
<tbody>
<tr class="project-row", id="project_1">
<td class="name">Project Runaway</td>
<td class="total-size">8</td>
</tr>
</tbody>
</table>
</body>
This is what the html rendered.
ruby-on-rails rspec tdd capybara
add a comment |
I have this integration test using capybara:
RSpec.describe 'adding a project', type: :system do
it 'allows a user to create a project with a tasks' do
visit new_project_path
fill_in 'Name', with: 'Project Runaway'
fill_in 'Tasks', with: 'Choose Fabric:3nMake it Work:5'
click_on('Create a project')
visit projects_path
@project = Project.find_by(name: "Project Runaway")
expect(page).to have_selector(
"#project_#{@project.id} > td.name", text: "Project Runaway"
)
expect(page).to have_selector(
"#project_#{@project.id} > td.total-size", text: "8"
)
end
end
Somehow it can't find the last selector (td.total-size):
Failures:
1) adding a project allows a user to create a project with a tasks
Failure/Error:
expect(page).to have_selector(
"#project_#{@project.id} > td.total-size", text: "8"
)
expected to find visible css "#project_1 > td.total-size" with text "8" but there were no matches. Also found "3", which matched the selector but not all filters.
# ./spec/system/add_project_spec.rb:14:in `block (2 levels) in <main>'
But the test is passed when I comment the last assertion. But failed if I commented the td.name part and left the td.total-size uncommented.
Here is the HTML page:
<h1>All Projects</h1>
<table>
<thead>
<tr>
<td>Project Name</td>
<td>Total Project Size</td>
</tr>
</thead>
<tbody>
<% @projects.each do |project| %>
<tr class="project-row", id="<%= dom_id(project) %>">
<td class="name"><%= project.name %></td>
<td class="total-size"><%= project.total_size %></td>
</tr>
<% end %>
</tbody>
</table>
I need to make sure all the data displayed on the table is right. Anyone has the same experience?
For additional information, I am using:
- Rails 5.2.1
- Ruby 2.5.0
- Rspec 3.7.1
- Capybara 3.11.1
Thanks in advance
Updated
<body>
<h1>All Projects</h1>
<table>
<thead>
<tr>
<td>Project Name</td>
<td>Total Project Size</td>
</tr>
</thead>
<tbody>
<tr class="project-row", id="project_1">
<td class="name">Project Runaway</td>
<td class="total-size">8</td>
</tr>
</tbody>
</table>
</body>
This is what the html rendered.
ruby-on-rails rspec tdd capybara
I have this integration test using capybara:
RSpec.describe 'adding a project', type: :system do
it 'allows a user to create a project with a tasks' do
visit new_project_path
fill_in 'Name', with: 'Project Runaway'
fill_in 'Tasks', with: 'Choose Fabric:3nMake it Work:5'
click_on('Create a project')
visit projects_path
@project = Project.find_by(name: "Project Runaway")
expect(page).to have_selector(
"#project_#{@project.id} > td.name", text: "Project Runaway"
)
expect(page).to have_selector(
"#project_#{@project.id} > td.total-size", text: "8"
)
end
end
Somehow it can't find the last selector (td.total-size):
Failures:
1) adding a project allows a user to create a project with a tasks
Failure/Error:
expect(page).to have_selector(
"#project_#{@project.id} > td.total-size", text: "8"
)
expected to find visible css "#project_1 > td.total-size" with text "8" but there were no matches. Also found "3", which matched the selector but not all filters.
# ./spec/system/add_project_spec.rb:14:in `block (2 levels) in <main>'
But the test is passed when I comment the last assertion. But failed if I commented the td.name part and left the td.total-size uncommented.
Here is the HTML page:
<h1>All Projects</h1>
<table>
<thead>
<tr>
<td>Project Name</td>
<td>Total Project Size</td>
</tr>
</thead>
<tbody>
<% @projects.each do |project| %>
<tr class="project-row", id="<%= dom_id(project) %>">
<td class="name"><%= project.name %></td>
<td class="total-size"><%= project.total_size %></td>
</tr>
<% end %>
</tbody>
</table>
I need to make sure all the data displayed on the table is right. Anyone has the same experience?
For additional information, I am using:
- Rails 5.2.1
- Ruby 2.5.0
- Rspec 3.7.1
- Capybara 3.11.1
Thanks in advance
Updated
<body>
<h1>All Projects</h1>
<table>
<thead>
<tr>
<td>Project Name</td>
<td>Total Project Size</td>
</tr>
</thead>
<tbody>
<tr class="project-row", id="project_1">
<td class="name">Project Runaway</td>
<td class="total-size">8</td>
</tr>
</tbody>
</table>
</body>
This is what the html rendered.
ruby-on-rails rspec tdd capybara
ruby-on-rails rspec tdd capybara
edited Nov 26 '18 at 6:02
Kris MP
asked Nov 25 '18 at 9:10
Kris MPKris MP
58011024
58011024
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
The error is telling you that the element you expect to have text content of "8" has text content of "3". That would imply to me that either your app has a bug or that fill_in 'Tasks', with: 'Choose Fabric:3nMake it Work:5'
isn't doing what you expect it to. Pause the test and look at the browser to see what's actually being created and/or look at your test.log
to see what is being submitted and what elements are actually being created. Note also that I would expect your test to be pretty flaky because you're not actually waiting for whatever action(s) click_on('Create a project')
performs. That means the following visit
can occur before those actions occur and end up cancelling them. Add an assertion between the click and visit for whatever visual change indicates the project creation has completed
click_on('Create a project')
expect(page).to have_text('Project created!') # whatever your app does to indicate successful creation
visit projects_path
Hi I updated my question with rendered html. There is a text 8 under the selector
– Kris MP
Nov 26 '18 at 6:03
@KrisMP Post thetest.log
for the test because the error is clearly telling you the element has "3" rather than "8" - so either the HTML you posted isn't from when the test is run, isn't being merged into the page (if AJAX), or is responding afterCapybara.default_max_wait_time
seconds. Also confused as to why the<tr class="project-row", id="project_1">
has a comma in the middle
– Thomas Walpole
Nov 26 '18 at 7:08
add a comment |
You can use element hierarchy for table and its td and tr.
such as
#getting text of 1st cell of 2nd row
name = find('#tableId tbody tr:nth-of-type(2) td:nth-of-type(1)').text
if name == "Project Name"
# do what ever you want to do
else
# do what ever you want to do
end
you can put above code block in while loop to go through each and every cell of table.
Note: Capybara counter starts with 1 so tr:nth-of-type(2) simply means 2nd row.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466083%2frails-rspec-capybara-selector-not-found%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The error is telling you that the element you expect to have text content of "8" has text content of "3". That would imply to me that either your app has a bug or that fill_in 'Tasks', with: 'Choose Fabric:3nMake it Work:5'
isn't doing what you expect it to. Pause the test and look at the browser to see what's actually being created and/or look at your test.log
to see what is being submitted and what elements are actually being created. Note also that I would expect your test to be pretty flaky because you're not actually waiting for whatever action(s) click_on('Create a project')
performs. That means the following visit
can occur before those actions occur and end up cancelling them. Add an assertion between the click and visit for whatever visual change indicates the project creation has completed
click_on('Create a project')
expect(page).to have_text('Project created!') # whatever your app does to indicate successful creation
visit projects_path
Hi I updated my question with rendered html. There is a text 8 under the selector
– Kris MP
Nov 26 '18 at 6:03
@KrisMP Post thetest.log
for the test because the error is clearly telling you the element has "3" rather than "8" - so either the HTML you posted isn't from when the test is run, isn't being merged into the page (if AJAX), or is responding afterCapybara.default_max_wait_time
seconds. Also confused as to why the<tr class="project-row", id="project_1">
has a comma in the middle
– Thomas Walpole
Nov 26 '18 at 7:08
add a comment |
The error is telling you that the element you expect to have text content of "8" has text content of "3". That would imply to me that either your app has a bug or that fill_in 'Tasks', with: 'Choose Fabric:3nMake it Work:5'
isn't doing what you expect it to. Pause the test and look at the browser to see what's actually being created and/or look at your test.log
to see what is being submitted and what elements are actually being created. Note also that I would expect your test to be pretty flaky because you're not actually waiting for whatever action(s) click_on('Create a project')
performs. That means the following visit
can occur before those actions occur and end up cancelling them. Add an assertion between the click and visit for whatever visual change indicates the project creation has completed
click_on('Create a project')
expect(page).to have_text('Project created!') # whatever your app does to indicate successful creation
visit projects_path
Hi I updated my question with rendered html. There is a text 8 under the selector
– Kris MP
Nov 26 '18 at 6:03
@KrisMP Post thetest.log
for the test because the error is clearly telling you the element has "3" rather than "8" - so either the HTML you posted isn't from when the test is run, isn't being merged into the page (if AJAX), or is responding afterCapybara.default_max_wait_time
seconds. Also confused as to why the<tr class="project-row", id="project_1">
has a comma in the middle
– Thomas Walpole
Nov 26 '18 at 7:08
add a comment |
The error is telling you that the element you expect to have text content of "8" has text content of "3". That would imply to me that either your app has a bug or that fill_in 'Tasks', with: 'Choose Fabric:3nMake it Work:5'
isn't doing what you expect it to. Pause the test and look at the browser to see what's actually being created and/or look at your test.log
to see what is being submitted and what elements are actually being created. Note also that I would expect your test to be pretty flaky because you're not actually waiting for whatever action(s) click_on('Create a project')
performs. That means the following visit
can occur before those actions occur and end up cancelling them. Add an assertion between the click and visit for whatever visual change indicates the project creation has completed
click_on('Create a project')
expect(page).to have_text('Project created!') # whatever your app does to indicate successful creation
visit projects_path
The error is telling you that the element you expect to have text content of "8" has text content of "3". That would imply to me that either your app has a bug or that fill_in 'Tasks', with: 'Choose Fabric:3nMake it Work:5'
isn't doing what you expect it to. Pause the test and look at the browser to see what's actually being created and/or look at your test.log
to see what is being submitted and what elements are actually being created. Note also that I would expect your test to be pretty flaky because you're not actually waiting for whatever action(s) click_on('Create a project')
performs. That means the following visit
can occur before those actions occur and end up cancelling them. Add an assertion between the click and visit for whatever visual change indicates the project creation has completed
click_on('Create a project')
expect(page).to have_text('Project created!') # whatever your app does to indicate successful creation
visit projects_path
answered Nov 25 '18 at 17:16
Thomas WalpoleThomas Walpole
32.4k33153
32.4k33153
Hi I updated my question with rendered html. There is a text 8 under the selector
– Kris MP
Nov 26 '18 at 6:03
@KrisMP Post thetest.log
for the test because the error is clearly telling you the element has "3" rather than "8" - so either the HTML you posted isn't from when the test is run, isn't being merged into the page (if AJAX), or is responding afterCapybara.default_max_wait_time
seconds. Also confused as to why the<tr class="project-row", id="project_1">
has a comma in the middle
– Thomas Walpole
Nov 26 '18 at 7:08
add a comment |
Hi I updated my question with rendered html. There is a text 8 under the selector
– Kris MP
Nov 26 '18 at 6:03
@KrisMP Post thetest.log
for the test because the error is clearly telling you the element has "3" rather than "8" - so either the HTML you posted isn't from when the test is run, isn't being merged into the page (if AJAX), or is responding afterCapybara.default_max_wait_time
seconds. Also confused as to why the<tr class="project-row", id="project_1">
has a comma in the middle
– Thomas Walpole
Nov 26 '18 at 7:08
Hi I updated my question with rendered html. There is a text 8 under the selector
– Kris MP
Nov 26 '18 at 6:03
Hi I updated my question with rendered html. There is a text 8 under the selector
– Kris MP
Nov 26 '18 at 6:03
@KrisMP Post the
test.log
for the test because the error is clearly telling you the element has "3" rather than "8" - so either the HTML you posted isn't from when the test is run, isn't being merged into the page (if AJAX), or is responding after Capybara.default_max_wait_time
seconds. Also confused as to why the <tr class="project-row", id="project_1">
has a comma in the middle– Thomas Walpole
Nov 26 '18 at 7:08
@KrisMP Post the
test.log
for the test because the error is clearly telling you the element has "3" rather than "8" - so either the HTML you posted isn't from when the test is run, isn't being merged into the page (if AJAX), or is responding after Capybara.default_max_wait_time
seconds. Also confused as to why the <tr class="project-row", id="project_1">
has a comma in the middle– Thomas Walpole
Nov 26 '18 at 7:08
add a comment |
You can use element hierarchy for table and its td and tr.
such as
#getting text of 1st cell of 2nd row
name = find('#tableId tbody tr:nth-of-type(2) td:nth-of-type(1)').text
if name == "Project Name"
# do what ever you want to do
else
# do what ever you want to do
end
you can put above code block in while loop to go through each and every cell of table.
Note: Capybara counter starts with 1 so tr:nth-of-type(2) simply means 2nd row.
add a comment |
You can use element hierarchy for table and its td and tr.
such as
#getting text of 1st cell of 2nd row
name = find('#tableId tbody tr:nth-of-type(2) td:nth-of-type(1)').text
if name == "Project Name"
# do what ever you want to do
else
# do what ever you want to do
end
you can put above code block in while loop to go through each and every cell of table.
Note: Capybara counter starts with 1 so tr:nth-of-type(2) simply means 2nd row.
add a comment |
You can use element hierarchy for table and its td and tr.
such as
#getting text of 1st cell of 2nd row
name = find('#tableId tbody tr:nth-of-type(2) td:nth-of-type(1)').text
if name == "Project Name"
# do what ever you want to do
else
# do what ever you want to do
end
you can put above code block in while loop to go through each and every cell of table.
Note: Capybara counter starts with 1 so tr:nth-of-type(2) simply means 2nd row.
You can use element hierarchy for table and its td and tr.
such as
#getting text of 1st cell of 2nd row
name = find('#tableId tbody tr:nth-of-type(2) td:nth-of-type(1)').text
if name == "Project Name"
# do what ever you want to do
else
# do what ever you want to do
end
you can put above code block in while loop to go through each and every cell of table.
Note: Capybara counter starts with 1 so tr:nth-of-type(2) simply means 2nd row.
answered Jan 2 at 19:34
Maharshi PatelMaharshi Patel
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466083%2frails-rspec-capybara-selector-not-found%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown