Skip to content

Instantly share code, notes, and snippets.

@ibotdotout
Last active July 22, 2016 11:10
Show Gist options
  • Save ibotdotout/9a567b2c2f90df2d59c5 to your computer and use it in GitHub Desktop.
Save ibotdotout/9a567b2c2f90df2d59c5 to your computer and use it in GitHub Desktop.
Robotframework script to claim free packtpub book
*** Settings ***
Library Selenium2Library
*** Variables ***
${USER} [email protected]
${PASSWORD} password
${BROWSER} phantomjs
${HOME URL} https://www.packtpub.com/packt/offers/free-learning
${END URL} https://www.packtpub.com/account/my-ebooks
${CLAIM BUTTON} xpath=//*[@id="deal-of-the-day"]/div/div/div[2]/div[4]/div[2]/a/div/input
${CLAIM BUTTON 2} xpath=//*[@id="deal-of-the-day"]/div/div/div[2]/div[5]/div[2]/a/div/input
${LOGIN BUTTON} xpath=//*[@id="account-bar-form-login"]/div[1]/form/div/div/div[3]/input
${USER INPUT} xpath=//*[@id="account-bar-form-login"]/div[1]/form/div/div/div[1]/div/input
${PASS INPUT} xpath=//*[@id="account-bar-form-login"]/div[1]/form/div/div/div[2]/div/input
${BOOK TITLE} xpath=//*[@id="deal-of-the-day"]/div/div/div[2]/div[2]/h2
${LOGIN DONE} My Account
${CLAIM DONE} My eBooks
${TIMEOUT} 10
*** Test Cases ***
Get Free Ebook
Open Normal Browser ${HOME URL} ${BROWSER}
Get Ebook
*** Keywords ***
Open Normal Browser
[Arguments] ${url} ${browser}
Open Browser ${url} ${browser}
Maximize Browser Window
Login
[Arguments] ${user} ${pass}
Click Claim Book
Input Text ${USER INPUT} ${user}
Input Text ${PASS INPUT} ${pass}
Click Button ${LOGIN BUTTON}
Wait Until Page Contains ${LOGIN DONE} ${TIMEOUT}
Click Claim Book
${status} ${value}= Run Keyword And Ignore Error Click Button ${CLAIM BUTTON}
Run Keyword If '${status}'=='FAIL' Click Button ${CLAIM BUTTON 2}
Claim Book
Click Claim Book
Wait Until Page Contains ${CLAIM DONE} ${TIMEOUT}
Get Book Title
${book title}= Get Text ${BOOK TITLE}
[return] ${book title}
Get Ebook
Location Should Be ${HOME URL}
Login ${USER} ${PASSWORD}
${book title}= Get Book Title
Claim Book
Location Should Be ${END URL}
Page Should Contain ${book title}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment