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.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
André
  • 24,706
  • 43
  • 121
  • 178

1 Answers1

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.

Community
  • 1
  • 1
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
  • 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. – Artjom B. May 06 '15 at 13:11
  • @ArtjomB. ah - that makes sense. No way to run phantomjs tests using Node itself? – Mikko Ohtamaa May 06 '15 at 13:25
  • Sure, one can use a bridge like https://github.com/sgentle/phantomjs-node, but the syntax is slightly different. – Artjom B. May 06 '15 at 14:14