Skip to content

Commit

Permalink
Solve error with the selective Download
Browse files Browse the repository at this point in the history
Updates in the documentation
New Examples
  • Loading branch information
carrerasrodrigo committed Mar 11, 2013
1 parent c70311a commit 210f909
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/tests_scripts/cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from ghost import Ghost

# Here we create a ghost instance with cache in /tmp/ghost.py and a max size of 10 MB.
# We also indicates that the cache folder would be shared between tabs
gh = Ghost(cache_dir="/tmp/ghost.py", cache_size=10, share_cache=True)
gpage, name = gh.create_page(download_images=True, prevent_download=["css"])

# Open google
gpage.open("http://www.google.com")
27 changes: 27 additions & 0 deletions tests/tests_scripts/fast_open.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from ghost import Ghost

url = "http://news.ycombinator.com/"
# We enable the cache and set the maximun size to 10 MB
# We don't want to load images and load css or js files
gh = Ghost(cache_size=10)

# We create a new page
page, page_name = gh.create_page(download_images=False,
prevent_download=["css", "js"])

# wait_onload_event will tell to Ghost to leave the open method
# when the On Ready event on the web page has been fired
page_resource = page.open(url, wait_onload_event=False)

# We retrive the links from the web page
links = page.evaluate("""
var links = document.querySelectorAll("a");
var listRet = [];
for (var i=0; i<links.length; i++){
listRet.push(links[i].href);
}
listRet;
""")
# Print the links
for l in links:
print l
24 changes: 24 additions & 0 deletions tests/tests_scripts/multiple_tabs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from ghost import Ghost

# Creates a Ghost instance telling to share cache and don't share cookies
gh = Ghost(share_cache=True, share_cookies=False)
page1, name = gh.create_page()
page2, name = gh.create_page()

# Open google
page1.open("http://www.google.com")

# Open Hacker News
page2.open("http://news.ycombinator.com/")

# Saves an image of the screen 1
page1.capture_to("/tmp/tab1.png")
print "open /tmp/tab1.png"

# Saves an image of the screen 2
page2.capture_to("/tmp/tab2.png")
print "open /tmp/tab2.png"

# Then we remove the tabs from ghost instance
gh.remove_page(page1)
gh.remove_page(page2)
36 changes: 36 additions & 0 deletions tests/tests_scripts/multiple_tabs_concurrent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from ghost import Ghost
import time

# Creates a Ghost instance telling to share cache and don't share cookies
gh = Ghost(share_cache=True, share_cookies=False)
page1, name = gh.create_page()
page2, name = gh.create_page()

# Open google
page1.open("http://www.google.com", wait_for_loading=False)

# Open Hacker News
page2.open("http://news.ycombinator.com/", wait_for_loading=False)

# At this point ghost it's rendering the two pages at the same time. Now we
# need to check if the pages are loaded.
while page1.get_loaded_page() is None:
page_resource = page1.get_loaded_page()
gh.process_events()
time.sleep(0.01)

# Saves an image of the screen 1
page1.capture_to("/tmp/tab1.png")
print "open /tmp/tab1.png"


#Or we can use wait_for_page_loaded() instead
page2.wait_for_page_loaded()

# Saves an image of the screen 2
page2.capture_to("/tmp/tab2.png")
print "open /tmp/tab2.png"

# Then we remove the tabs from ghost instance
gh.remove_page(page1)
gh.remove_page(page2)
12 changes: 12 additions & 0 deletions tests/tests_scripts/selective_download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from ghost import Ghost

# Creates a Ghost instance telling to don't download css files and images
gh = Ghost()
gpage, name = gh.create_page(download_images=True, prevent_download=["css"])

# Open google
gpage.open("http://www.google.com")

# Saves an image of the screen
gpage.capture_to("/tmp/selective_download.png")

0 comments on commit 210f909

Please sign in to comment.