Skip to content

Instantly share code, notes, and snippets.

@sidchilling
Last active February 17, 2018 11:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidchilling/6112208 to your computer and use it in GitHub Desktop.
Save sidchilling/6112208 to your computer and use it in GitHub Desktop.
This is a python script which uses Splinter to automate tests for Viral Flash Deal App for ShopSocially. This was used for demo purpose on the technext talk on automating testing for single-page app
# This script tests the VFS
from splinter import Browser
def main(browser):
browser.visit(url = 'https://deals.shopsocially.com/flashsales/nikitaisawesome?cmp_id=516cfc502bba0163b6000002&offer_ref=nikitaisawesome_email')
# Press the unlock link
try:
try:
browser.find_by_id(id = 'unlock').click()
except:
# probably because it was already unlocked
print 'the deal was alreadt unlocked - moving ahead'
while not browser.find_by_id(id = 'buy').first.visible:
# waiting here
a = 1 # Some dummy statement to be executed
browser.find_by_id(id = 'buy').click()
while not browser.find_by_name(name = 'confirm_email').first.visible:
a = 1
# fill up all the fiels
browser.find_by_name(name = 'email').first.fill(value = 'siddharth@shopsocially.com')
browser.find_by_name(name = 'confirm_email').first.fill(value = 'siddharth@shopsocially.com')
browser.find_by_xpath(xpath = '//input[@class="cardholder_name"]').first.fill(value = \
'Siddharth Saha')
browser.find_by_xpath(xpath = '//input[@class="card_number"]').first.fill(value = \
'4242424242424242')
browser.find_by_xpath(xpath = '//input[@class="card_cvc"]').first.fill(value = '123')
browser.find_by_xpath(xpath = '//input[@class="billing_address"]').first.fill(value = \
'Aundh')
browser.find_by_xpath(xpath = '//input[@class="city"]').first.fill(value = 'Pune')
browser.find_by_xpath(xpath = '//input[@class="state"]').first.fill(value = 'MH')
browser.find_by_xpath(xpath = '//input[@class="zipcode"]').first.fill(value = '122001')
browser.find_by_xpath(xpath = '//input[@class="phone"]').first.fill(value = \
'8698789798')
browser.find_by_xpath(xpath = '//select[@class="card_expiry_month"]').first.find_by_xpath('//option[@value="02"]').first.click()
browser.find_by_xpath(xpath = '//select[@class="card_expiry_year"]').first.find_by_xpath('//option[@value="2019"]').first.click()
browser.find_by_id(id = 'quantity').first.find_by_xpath('//option[@value="2"]').first.click()
browser.find_by_id(id = 'complete_order').click()
while not browser.find_by_id(id = 'codes').first.visible:
a = 1
print(browser.find_by_id(id = 'codes').value)
except Exception as e:
print('FAILED: %s' %(e))
if __name__ == '__main__':
browser = Browser()
main(browser = browser)
browser.quit()
@ldong
Copy link

ldong commented May 23, 2014

@sidchilling, have you figured out a way to write CasperJS in splinter? I know CasperJS actually uses PhantomJS, but the syntax is slight different. Could you kindly give an update? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment