Is there anyway to run JavaScript in python?

Discussion in 'Python' started by crow, Dec 30, 2010.

  1. crow

    crow Guest

    Hi, I'm writing a test tool to simulate Web browser. Is there anyway
    to run JavaScript in python? Thanks in advance.
     
    crow, Dec 30, 2010
    #1
    1. Advertising

  2. crow

    Roy Smith Guest

    In article
    <>,
    crow <> wrote:

    > 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.
     
    Roy Smith, Dec 30, 2010
    #2
    1. Advertising

  3. On Thu, Dec 30, 2010 at 5:52 AM, crow <> wrote:
    > Hi, I'm writing a test tool to simulate Web browser. Is there anyway
    > to run JavaScript in python? Thanks in advance.
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >


    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.
     
    Dan Stromberg, Jan 1, 2011
    #3
  4. crow <> writes:

    > 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
     
    Diez B. Roggisch, Jan 3, 2011
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TmVpbA==?=
    Replies:
    1
    Views:
    670
    Mark Newby
    Apr 27, 2005
  2. José Joye

    Is there anyway to detect a F5-Refresh

    José Joye, Jun 27, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    3,113
    José Joye
    Jun 27, 2006
  3. Vajira

    Is there anyway to iterate STL queue ?

    Vajira, Jan 28, 2005, in forum: C Programming
    Replies:
    3
    Views:
    7,261
    Vajira
    Jan 28, 2005
  4. Jonathan Wood
    Replies:
    10
    Views:
    544
    Jonathan Wood
    Jan 3, 2009
  5. Casey Hawthorne
    Replies:
    1
    Views:
    425
    Gerhard Häring
    Jan 24, 2009
Loading...

Share This Page