We have an RSpec test we want to run that uses selenium running with js: true
. i.e. as you run the test it will literally launch firefox in front of you and go through the test itself.
Our test is policing a single page angular application and needs to do a combination of navigating around the app and then manipulating the database directly to see how the front end responds to it.
context "in my single page Angular application" do
context "given I go to a user's profile page" do
it "should contain the user's profile photo" do
visit profile_page_url
expect(page).to have_text(profile_photo_url)
end
context "and then I go to the homepage, remotely destroy the photo and return to the profile page" do
before :each do
visit homepage_url
profile_photo.destroy
visit profile_page_url
end
it "expects the profile photo to be gone" do
expect(page).not_to have_text(profile_photo_url)
end
end
end
end
In the example above you can see that we go to a user's profile page, check that their photo is there then go to the homepage. Whilst we're on the homepage we destroy the user's profile photo (directly using the script rather than the interface) and then return to the original page to see whether it's gone. Or at least this is what we do in theory.
It looks like the two processes are in different threads / transactions
In practice everything hangs once we've deleted the photo. Reading up on this it seems like this might be due to the console and selenium running two different DB transactions in parallel in different processes (threads?). The console is waiting for Selenium to finish before it can execute its DB query.
So superficially it seems like we're stuck. Anecdotally it looks like we can't do direct DB maniupulation at the same time as Selenium is running as one transaction is waiting for the other to finish.
It is possible to do this if we put a binding.pry
debugger statement in. But it doesn't work in the test suite.
Is it possible to manipulate the DB synchronously with a Selenium session
We need to be able to alter the DB directly via the console and Selenium during the same session. Is this possible?