Commit a147acc4 by Mark L. Chang

moved out of test_root

parent f0755202
from lettuce import * #before, world
from selenium import *
import lettuce_webdriver.webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
url = 'http://anant:agarwal@sandbox-test-001.m.edx.org/'
#url = 'http://anant:agarwal@stage-edx-001.m.edx.org/'
## Helper methods for selenium tests for EdX
#### Utility Methods
## Utility method for finding elements in a selection
def find_element_by_name_in_selection(selection_id, field):
e = world.browser.find_element_by_xpath("//*[@id='"+selection_id+"']").find_element_by_name(field)
return e
## Utility methods for waiting for elements to render
def wait_until_class_renders(class_name,time):
try:
e = WebDriverWait(world.browser, time).until(lambda driver : driver.find_element_by_class_name(class_name))
return e
except:
return False
def wait_until_id_renders(element_id,time):
try:
e = WebDriverWait(world.browser, time).until(lambda driver : driver.find_element_by_id(element_id))
return e
except:
return False
## Utility methods for courses
def has_courses():
if wait_until_class_renders('empty-dashboard-message',3):
return False
else:
return True
def register_for_course(coursename):
world.browser.get(url+'courses')
world.browser.find_element_by_xpath("//*[@id='"+coursename+"']//a[1]").click()
wait_until_class_renders('register',3).click()
def check_if_registered(coursename):
world.browser.get(url+'dashboard')
world.browser.find_element_by_xpath("//a[@href='/courses/"+coursename+"/info']")
def unregister_for_course(coursename):
world.browser.get(url+'dashboard')
world.browser.find_element_by_xpath("//a[@data-course-id='"+coursename+"']").click()
find_element_by_name_in_selection('unenroll_form','submit').click()
Feature: Homepage renders
In order to get an idea of edX
As anonymous web users
We want to see lots of information about edX on the home page
Scenario: We can see all the courses
Given I visit "http://anant:agarwal@sandbox-test-001.m.edx.org/"
#"http://anant:agarwal@stage-edx-001.m.edx.org/"
I should see "3.091x"
I should see "CS50x"
I should see "CS169.1x"
I should see "6.002x"
I should see "PH207x"
I should see "CS188.1x"
I should see "6.00x"
Scenario: We can see the "Login" button
Given I visit "http://anant:agarwal@sandbox-test-001.m.edx.org/"
#"http://anant:agarwal@stage-edx-001.m.edx.org/"
I should see "Sign Up"
Scenario: We can see the "Sign up" button
Given I visit "http://anant:agarwal@sandbox-test-001.m.edx.org/"
#"http://anant:agarwal@stage-edx-001.m.edx.org/"
I should see "Log In"
Scenario: We can see the three partner institutions
Given I visit "http://anant:agarwal@sandbox-test-001.m.edx.org/"
#"http://anant:agarwal@stage-edx-001.m.edx.org/"
I should see "MITx"
I should see "HarvardX"
I should see "BerkeleyX"
Scenario: We can see the static content pages
Given I visit "http://anant:agarwal@sandbox-test-001.m.edx.org/"
#"http://anant:agarwal@stage-edx-001.m.edx.org/"
I should see "Find Courses"
I should see "About"
I should see "Blog"
I should see "Jobs"
I should see "Contact"
Feature: Login
In order to login
As a registered user
We'll see if I can log in to my account and perform user actions
Scenario: Login to an existing account and logout
Given I visit "http://anant:agarwal@sandbox-test-001.m.edx.org/"
#"http://anant:agarwal@stage-edx-001.m.edx.org/"
When I click "LOG IN"
And I login with "ddieker@gmail.com" in the "email" field
And I login with "password" in the "password" field
And I press "Access My Courses"
Then I should see an element with class of "user" within "3" seconds
# Scenario: Add a course
# Given I have no courses
# When I click "Find courses now!"
# And I click on a course
# And I register for the course
# Then I should see the course in my dashboard
# Scenario: Drop a course
# Given I have a course
# When I click "Unregister"
# And I confirm the course drop
# Then I should have no courses
Scenario: I register for a course, unregister, then register again
Given I have a list of courses
When I click "Find Courses"
And I register for every course
And I notice I have been registered for every course
And I unregister for every course
And I notice I have been unregistered
And I register for one course
Then I should see that course in my dashboard
Scenario: Logout of a signed in account
Given I am logged in
When I click the "▾" dropdown
And I click "Log Out"
Then I should see an element with id of "login" within "3" seconds
\ No newline at end of file
from lettuce import * #before, world
from selenium import *
import lettuce_webdriver.webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from helpers import *
## Login
url = 'http://anant:agarwal@sandbox-test-001.m.edx.org/'
#url = 'http://anant:agarwal@stage-edx-001.m.edx.org/'
@step(u'I login with "(.*)" in the "(.*)" field')
def i_login_with_data_in_the_fieldname_field(step,data,field):
e = find_element_by_name_in_selection('login-modal',field)
e.send_keys(data)
## I register for a course, unregister, then register again
course_list = ['MITx/6.00x/2012_Fall']
@step(u'Given I have a list of courses')
def get_list_of_courses(step):
return course_list
#do some back-end code stuff here
@step(u'I register for every course')
def i_register_for_every_course(step):
for course in course_list:
register_for_course(course)
@step(u'I notice I have been registered for every course')
def i_notice_i_have_been_registered_for_every_course(step):
for course in course_list:
check_if_registered(course)
@step(u'I unregister for every course')
def i_unregister_for_every_course(step):
for course in course_list:
unregister_for_course(course)
@step(u'I notice I have been unregistered')
def i_notice_i_have_been_unregistered(step):
world.browser.get(url+'dashboard')
assert has_courses() == False
@step(u'I register for one course')
def i_click_on_one_course(step):
register_for_course(course_list[0])
@step(u'Then I should see that course in my dashboard')
def then_i_should_see_that_course_in_my_dashboard(step):
check_if_registered(course_list[0])
Feature: Sign up and Sign out
In order to create an account
As someone who wants to use the site
We'll see if I can create an account and log out
Scenario: Visit the homepage to Sign Up
Given I visit "http://anant:agarwal@sandbox-test-001.m.edx.org/"
## "http://anant:agarwal@stage-edx-001.m.edx.org/"
When I click "SIGN UP"
And I signup with "bob62@bob.com" in the "email" field
And I signup with "password" in the "password" field
And I signup with "Bob62" in the "username" field
And I signup with "Bob Jones" in the "name" field
# And I select "None" from "level_of_education"
# And I select "Male" from "gender"
# And I select "1986" from "year_of_birth"
And I click the checkbox "terms_of_service"
And I click the checkbox "honor_code"
And I login with "submit"
Then I should see an element with class of "activation-message" within "3" seconds
And I should see "Thanks For Registering!"
Scenario: Logout of a signed in account
Given I am logged in
When I click the "▾" dropdown
And I click "Log Out"
Then I should see an element with id of "login" within "3" seconds
from lettuce import * #before, world
from selenium import *
import lettuce_webdriver.webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from helpers import *
## Signup Step
@step(u'I signup with "(.*)" in the "(.*)" field')
def i_signup_with_data_in_the_field_field(step, data, field):
e = find_element_by_name_in_selection('signup-modal',field)
e.send_keys(data)
@step(u'I fill the "(.*)" field with "(.*)"')
def i_fill_the_field_with_value(step, field, value):
field = world.browser.find_element_by_name(field);
field.send_keys(value);
@step(u'I select "(.*)" from "(.*)"')
def i_select_option_from_selection(step, option, selection):
select = world.browser.find_element_by_name(selection)
allOptions = select.find_elements_by_tag_name("option")
for option in allOptions:
if (option.text == "None"):
option.click()
@step(u'I click the checkbox "(.*)"')
def i_click_the_checkbox(step, checkbox):
e = find_element_by_name_in_selection('signup-modal',checkbox)
e.click()
@step(u'I login with "(.*)"')
def i_login_with_text(step,text):
e = find_element_by_name_in_selection('signup-modal',text)
e.click()
@step(u'Then I should see an element with class of "([^"]*)" within "(.*)" seconds')
def then_i_should_see_an_element_with_class_of_classname_within_duration_seconds(step, classname, duration):
wait_until_class_renders(classname, int(duration))
## Logout Step
@step(u'Given I am logged in')
def given_i_am_logged_in(step):
pass
@step(u'I click the (.*) dropdown')
def i_logout(step,arg):
dropdown = world.browser.find_element_by_xpath("//nav//ol[2]//li[2]//a")
dropdown.click()
@step(u'Then I should see an element with id of "(.*)" within "(.*)" seconds')
def then_i_should_see_an_element_with_id_of_elementid_within_duration_seconds(step, element_id, duration):
wait_until_id_renders(element_id, int(duration))
from lettuce import before, after, world
from selenium import webdriver
import lettuce_webdriver.webdriver
@before.all
def setup_browser():
world.browser = webdriver.Firefox()
@after.all
def teardown_browser(total):
world.browser.quit()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment