Mercurial > org-tools
changeset 9:d09937a6cb4b
trying to build something to automatically refresh the browser.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 25 Oct 2011 05:33:36 -0700 |
parents | 73beed20f7de |
children | 83e16df2288a |
files | auto-weave.pl play-browser.py refresh-browser.py sample.py |
diffstat | 4 files changed, 79 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/auto-weave.pl Tue Oct 25 01:08:31 2011 -0700 1.2 +++ b/auto-weave.pl Tue Oct 25 05:33:36 2011 -0700 1.3 @@ -13,22 +13,34 @@ 1.4 $" = "\n"; 1.5 print "@org_files\n"; 1.6 1.7 +$ignore_next = 0; 1.8 + 1.9 1.10 foreach(@org_files){ 1.11 # add watchers 1.12 $inotify->watch ($_, IN_MODIFY, sub 1.13 { 1.14 - my $e = shift; 1.15 - my $name = $e->fullname; 1.16 - print "$name was modified\n" if $e->IN_MODIFY; 1.17 - system ("weave $name"); 1.18 - print ("$name\n"); 1.19 - $path = `readlink -f $name`; 1.20 - $path =~ s|/home/r/proj|http://aurellem.localhost|; 1.21 - print ("$path\n"); 1.22 - $path =~ s|org|html|g; 1.23 - print ("$path\n"); 1.24 - system ("firefox $path"); 1.25 + print ("IGNORE : $ignore_next\n"); 1.26 + # ok, for some reason this get's called exactly 1.27 + # twice every time the file is saved from emacs. 1.28 + # so ignore every other invocation. 1.29 + if ($ignore_next) { 1.30 + $ignore_next = 0; 1.31 + return; 1.32 + } 1.33 + 1.34 + my $e = shift; 1.35 + my $name = $e->fullname; 1.36 + print "$name was modified\n" if $e->IN_MODIFY; 1.37 + $output = `weave $name`; 1.38 + print ("$name\n"); 1.39 + $path = `readlink -f $name`; 1.40 + $path =~ s|/home/r/proj|http://aurellem.localhost|; 1.41 + print ("$path\n"); 1.42 + $path =~ s|org|html|g; 1.43 + print ("$path\n"); 1.44 + #system ("firefox $path"); 1.45 + $ignore_next = 1; 1.46 1.47 }); 1.48 }
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/play-browser.py Tue Oct 25 05:33:36 2011 -0700 2.3 @@ -0,0 +1,19 @@ 2.4 +#!/usr/bin/env python 2.5 + 2.6 + 2.7 +from selenium import webdriver 2.8 +from selenium.common.exceptions import TimeoutException 2.9 +from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0 2.10 +import time 2.11 + 2.12 +# Create a new instance of the Firefox driver 2.13 +#driver = webdriver.Firefox() 2.14 + 2.15 +driver = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.FIREFOX) 2.16 + 2.17 + 2.18 +# go to the google home page 2.19 +driver.get("http://tycho.usno.navy.mil/cgi-bin/timer.pl") 2.20 + 2.21 +# you HAVE to quit if you're reusing firefox sessions 2.22 +driver.quit()
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/refresh-browser.py Tue Oct 25 05:33:36 2011 -0700 3.3 @@ -0,0 +1,19 @@ 3.4 +#!/usr/bin/env python 3.5 + 3.6 + 3.7 +from selenium import webdriver 3.8 +from selenium.common.exceptions import TimeoutException 3.9 +from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0 3.10 +import time 3.11 + 3.12 +# Create a new instance of the Firefox driver 3.13 +#driver = webdriver.Firefox() 3.14 + 3.15 +driver = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.FIREFOX) 3.16 + 3.17 + 3.18 +# go to the google home page 3.19 +driver.get("http://tycho.usno.navy.mil/cgi-bin/timer.pl") 3.20 + 3.21 +# you HAVE to quit if you're reusing firefox sessions 3.22 +driver.quit()
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/sample.py Tue Oct 25 05:33:36 2011 -0700 4.3 @@ -0,0 +1,18 @@ 4.4 +#!/usr/bin/env python 4.5 + 4.6 +from selenium import webdriver 4.7 +from selenium.common.exceptions import NoSuchElementException 4.8 +from selenium.webdriver.common.keys import Keys 4.9 +import time 4.10 + 4.11 +browser = webdriver.Firefox() # Get local session of firefox 4.12 +browser.get("http://www.yahoo.com") # Load page 4.13 +assert "Yahoo!" in browser.title 4.14 +elem = browser.find_element_by_name("p") # Find the query box 4.15 +elem.send_keys("seleniumhq" + Keys.RETURN) 4.16 +time.sleep(0.2) # Let the page load, will be added to the API 4.17 +try: 4.18 + browser.find_element_by_xpath("//a[contains(@href,'http://seleniumhq.org')]") 4.19 +except NoSuchElementException: 4.20 + assert 0, "can't find seleniumhq" 4.21 +#browser.close()