I'm trying to run some headless tests locally on google app engine, python, selenium, nose tests, etc. I've managed to get everything working individually, but the problem is that I don't know where to point selenium when I run my tests.
One possible solution
Here is one possible solution which I've made progress on, but I'd be welcome to any solution that allowed me to use selenium to interact with the same database as my models running in testbed:
I could run dev_appserver
on 8080
and then point selenium to it, but then the testbed datastore will be different to the server's that selenium is pointed at. I've tried unifying them by running dev_appserver
like so:
$ dev_appserver.py --datastore_path tests/datastore --port 8080 .
and in my unit test's setUp
:
self.testbed.init_datastore_v3_stub(datastore_file='tests/datastore',use_sqlite=True)
(I'm setting use_sqlite because I got errors when I didn't. I think that dev_appserver
is also using sqlite and so they obviously need to be expecting the same format).
Unfortunately this doesn't work. I can create an entity in the datastore (either as part of my unit test or the running server), and confirm that it is persistent by deleting the file and seeing the entity disappear. However, if I use the datastore viewer provided by dev_appserver
to view the entities, it will never spot those entities created by my unit tests, and commands run by my unit tests will never spot those belonging to the local server.
One possible thought was that the app_id
was different between the unit tests and the server, so I manually set the app_id
using:
self.testbed.setup_env(app_id='foo')
where foo
is the same as in my app.yaml
file. I even tried dev~foo
, since that is what the admin console displays it as. That didn't work either.
Conclusion
This is as far as I've gotten. Any tips on how to get testbed and selenium (or the server that selenium visits) interacting with the same database would be greatly appreciated.
The following snippet works fine with the current SDK:
Start dev_appserver.py with the
--storage_path=/path/to/storage
option.Note:
setup_env(app_id=your_app_id)
should be called beforeactivate()
. Appengine documentation has an example with different sequence, this is probably a documentation bug.app_id
.