Is there anyway to run JavaScript in python?

C

crow

Hi, I'm writing a test tool to simulate Web browser. Is there anyway
to run JavaScript in python? Thanks in advance.
 
R

Roy Smith

crow said:
Hi, I'm writing a test tool to simulate Web browser. Is there anyway
to run JavaScript in python? Thanks in advance.

The answer to the question you asked is, "Probably. You might want to
check out SpiderMonkey as a starting point".

The answer to the question you didn't ask is, "Before you invest a lot
of effort in this, check out Selenium".

http://en.wikipedia.org/wiki/SpiderMonkey_(JavaScript_engine)
http://en.wikipedia.org/wiki/Selenium_(software)

Another thing to think about is whether you really do need JS to test
your web app. Depending on how much your app depends on JS for its core
functionality, you may find that just using urllib to fetch pages,
parsing the HTML with lxml, and verifying that certain data exists in
the appropriate HTML elements might get you 80% of the testing value for
20% of the effort. But, I digress.
 
D

Dan Stromberg

Hi, I'm writing a test tool to simulate Web browser. Is there anyway
to run JavaScript in python? Thanks in advance.

You might also consider Pyjamas, which translates Python (somewhere
between 2.5 and 2.6) to Javascript. Then your python code ends up
running on a javascript interpreter with interlanguage calling
available.
 
D

Diez B. Roggisch

crow said:
Hi, I'm writing a test tool to simulate Web browser. Is there anyway
to run JavaScript in python? Thanks in advance.

Not really. Yes, you can invoke spidermonkey. But the crucial point
about running JS is not executing JS, it's about having the *DOM* of the
browser available. Which spidermonkey obviously hasn't.

So, I recommend using Selenium.

Diez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top