1

I need to write some tests using PhantomJS. Basically I need to submit forms, but to do this I need data that is stored in a MySQL database.

I'm thinking to use Python and call the PhantomJS from Python, but I don't know what is the best way to pass data to the PhantomJS script.

For example I can pass via commandline a JSON ?

$ phantomjs script.js "{first_name: 'Peter', last_name: 'Brown'}"

Please guide me on how to do this.

1 Answer 1

0

To write browser tests utilizing Python code your best option is Selenium Web Driver which has phantomjs backend. There exist Python test frameworks and libraries, like Splinter, which aid in this use case.

On the other hand if you want to have phantomjs scripts to call Python code, you need to spawn Python processes to execute the Python scripts and then return the data back over a file / pipe / other communication channel. This is far more complex.

Alternatively you can just read your MySQL database from PhantomJS script if you execute PhantomJS tests in Node. There is MySQL driver for Node.js. On the other hand, this is not pure PhantomJS execution environment anymore.

Sign up to request clarification or add additional context in comments.

3 Comments

PhantomJS has a different execution environment than node.js. You can't just use arbitrary modules in PhantomJS. So are working, but more complex ones like the suggested mysql module probably won't work.
@ArtjomB. ah - that makes sense. No way to run phantomjs tests using Node itself?
Sure, one can use a bridge like github.com/sgentle/phantomjs-node, but the syntax is slightly different.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.