Skip to content

Commit

Permalink
Document functional test updated, Configuration functionality changed
Browse files Browse the repository at this point in the history
  • Loading branch information
bogtan committed Aug 3, 2010
1 parent 1ac7a1c commit 9f07f32
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 56 deletions.
12 changes: 3 additions & 9 deletions naaya/selenium/NySeleniumConfig.py
Expand Up @@ -3,14 +3,13 @@
import optparse

class NySeleniumConfig:
def __init__(self, options):
def __init__(self):
options = optparse.OptionParser()
self.data = {}

self.ParseArguments(options)

def ParseArguments(self, options):
options.add_option('--site', '-s', default='http://localhost/')
options.add_option('--port', '-p', default='8080')
options.add_option('--site', '-s', default='http://localhost:8080/')
options.add_option('--browsers', '-b', default="all")
options.add_option('--user', '-u', default="admin")
options.add_option('--password', '-P', default="admin")
Expand All @@ -20,12 +19,7 @@ def ParseArguments(self, options):
param_browsers = parsed_options.browsers.replace("=", "")
param_browsers = param_browsers.split(" ")

print "Browsers: "
for browser in param_browsers:
print "- " + browser

self.data['site'] = parsed_options.site
self.data['port'] = parsed_options.port
self.data['browsers'] = parsed_options.browsers
self.data['user'] = parsed_options.user
self.data['password'] = parsed_options.password
Expand Down
32 changes: 24 additions & 8 deletions naaya/selenium/NySeleniumTest.py
Expand Up @@ -6,17 +6,33 @@

class NySeleniumTest(unittest.TestCase):
def setUp(self):
parameters = optparse.OptionParser()
configuration = NySeleniumConfig(parameters)

configuration = NySeleniumConfig()
self.verificationErrors = []

if(configuration.data['browsers'] == "all"):
for browser in [ '*firefox', '*mock', '*firefoxproxy',
supported_browsers = [ '*firefox', '*mock', '*firefoxproxy',
'*pifirefox', '*chrome', '*iexploreproxy',
'*iexplore', '*firefox3', '*safariproxy',
'*googlechrome', '*konqueror', '*firefox2',
'*safari', '*piiexplore', '*firefoxchrome',
'*opera', '*iehta', '*custom']:
self.selenium = selenium("localhost", 5555, browser, "http://localhost:8080/")
'*opera', '*iehta', '*custom']
browsers = configuration.data['browsers'].split(",")

if(browsers[0] == '*all'):
for browser in supported_browsers:
self.selenium = selenium("localhost", 5555, browser,\
configuration.data['site'])
self.selenium.start()
elif((len(browsers) == 1) and (browsers[0] in supported_browsers)):
self.selenium = selenium("localhost", 5555, browsers[0],\
configuration.data['site'])
self.selenium.start()
elif((len(browsers) > 1)):
for browser in browsers:
if browser in supported_browsers:
import pdb;
pdb.set_trace()
print browser
self.selenium = selenium("localhost", 5555, browsers[0],\
configuration.data['site'])
self.selenium.start()
else:
print "No existing browser!"
3 changes: 0 additions & 3 deletions naaya/selenium/runtests.py
@@ -1,8 +1,5 @@
import sys
import os
import importlib
import inspect
import optparse
import time
import re
import unittest
Expand Down
146 changes: 110 additions & 36 deletions naaya/selenium/tests/document.py
@@ -1,11 +1,18 @@
import sys, os, unittest, time, re
import sys
import os
import re
import optparse
import logging
from selenium import selenium
sys.path.append(os.path.join(os.getcwd(), '..'))

from NySeleniumTest import NySeleniumTest
from NySeleniumConfig import NySeleniumConfig

class NaayaDocumentTest(NySeleniumTest):
def test_document(self):
"""Steps:
"""
Steps:
1. Access the login page
2. Check if elements username and passwords
are loaded before typing the values and submit form
Expand All @@ -19,64 +26,131 @@ def test_document(self):
"""

logger = logging.getLogger("Naaya Document Test")
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
ch.setFormatter(formatter)
logger.addHandler(ch)

configuration = NySeleniumConfig()

self.verificationErrors = []
self.selenium.open("/portal/login_html", True)
loaded = False
while(loaded == False):
loaded = self.selenium.is_element_present("__ac_name") and \
self.selenium.is_element_present("__ac_password")

self.selenium.type("__ac_name", "admidsa")
self.selenium.type("__ac_password", "admin")
self.selenium.type("__ac_name", configuration.data['user'])
self.selenium.type("__ac_password", configuration.data['password'])
self.selenium.click("submit")

self.selenium.wait_for_page_to_load("15000")

if((self.selenium.is_element_present("__ac_name") == True) and \
(self.selenium.is_element_present("__ac_password") == True)):
print "Login failed! Try again..."
return False
if(self.selenium.is_element_present("__ac_name") and \
(self.selenium.is_element_present("__ac_password"))):
self.verificationErrors.append("Login failed! Username and/or"
"password incorrect! Try again...")

self.selenium.open('/portal')
self.selenium.wait_for_page_to_load("15000")
self.selenium.click("link=Information")
self.selenium.wait_for_page_to_load("15000")

if(self.selenium.is_element_present("typetoadd") == False):
print "An error occured while trying to access `typetoadd` \
select field name!";
return False
self.verificationErrors.append("An error occured while trying to"
"access `typetoadd` select field"
" name!")

select_options = {'Folder': 1, 'News':2, 'Story':3, 'HTML Document':4, \
select_options = {'Folder': 1, 'News':2, 'Story':3, 'HTML Document':4,\
'Pointer':5, 'URL':6, 'Event':7, 'File':8, \
'GeoPoint':9}

for option in select_options:
if(self.selenium.is_element_present("typetoadd") != False):
self.selenium.select("typetoadd", "index=" + str(select_options[option]))
self.assertTrue(self.selenium.is_something_selected("typetoadd"));
self.assertEquals(option, self.selenium.get_selected_label("typetoadd"));
self.selenium.wait_for_page_to_load("15000")

return False

#
#self.selenium.select("typetoadd", "label=HTML Document")
#self.selenium.fireEvent("name=typetoadd", "change")
#import pdb
#pdb.set_trace()
#self.selenium.wait_for_page_to_load("30000")
#self.selenium.open("/portal/info/doc10154/add_html" , True)
#self.selenium.wait_for_page_to_load("30000")
#self.selenium.type("title", "dadasad")
#self.selenium.type("keywords", "dasdaqeqdqwweq")
#self.selenium.click("link=Today")
#self.selenium.click("//input[@value='Submit']")
#self.selenium.wait_for_page_to_load("30000")
if(option == "Story"):
self.selenium.select("typetoadd", "index=" + str(select_options[option]))
self.assertTrue(self.selenium.is_something_selected("typetoadd"));
self.assertEquals(option, self.selenium.get_selected_label("typetoadd"));
self.selenium.wait_for_page_to_load("15000")
if(self.selenium.is_element_present("id=lang") == False):
self.verificationErrors.append("Language element not"
" identified")

self.selenium.select("id=lang", "value=en")
self.selenium.type("title", "Test Story")
self.selenium.type("id=description", "This is a text")
self.selenium.type("keywords", "short, story, test story")
self.selenium.type("sortorder", "125")
self.selenium.click("link=Today")
self.selenium.click("//img[@alt='Calendar']")
self.selenium.click("link=16")
self.selenium.click("link=Today")
self.selenium.click("discussion")
self.selenium.type("resourceurl", "http://www.eaudeweb.ro/")
self.selenium.type("source", "http://www.wikipedia.com/")
self.selenium.type("frontpicture", "/home/bogdan/Desktop/no-pre.png")
self.selenium.click("//input[@value='Submit']")
self.selenium.wait_for_page_to_load("30000")

if(option == 'Folder'):
self.selenium.select("typetoadd", "index=" + str(select_options[option]))
self.assertTrue(self.selenium.is_something_selected("typetoadd"));
self.assertEquals(option, self.selenium.get_selected_label("typetoadd"));
self.selenium.wait_for_page_to_load("15000")
if(self.selenium.is_element_present("id=lang") == False):
self.verificationErrors.append("Language element not"
" identified")


self.selenium.select("id=lang", "value=en")
self.selenium.type("title", "My Folder")
self.selenium.type("id=description", "This is a text")
self.selenium.type("keywords", "my folder, test, folder, test folder")
self.selenium.type("sortorder", "132")
self.selenium.click("//img[@alt='Calendar']")
self.selenium.click("//div[@id='middle_port']/form/div[8]")
self.selenium.click("link=Today")
self.selenium.click("discussion")
self.selenium.click("//img[@alt='Calendar']")
self.selenium.click("link=28")
self.selenium.type("maintainer_email", "bogdan.tanase@eaudeweb.ro")
self.selenium.click("//input[@value='Submit']")
self.selenium.wait_for_page_to_load("30000")

if(option == "News"):
self.selenium.select("typetoadd", "index=" + str(select_options[option]))
self.assertTrue(self.selenium.is_something_selected("typetoadd"));
self.assertEquals(option, self.selenium.get_selected_label("typetoadd"));
self.selenium.wait_for_page_to_load("15000")
if(self.selenium.is_element_present("id=lang") == False):
self.verificationErrors.append("Language element not"
" identified")


self.selenium.select("id=lang", "value=en")
self.selenium.type("title", "My News")
self.selenium.type("coverage", "aoqk")
self.selenium.type("coverage", "test coverage")
self.selenium.type("keywords", "news, test")
self.selenium.type("sortorder", "83")
self.selenium.click("link=Today")
self.selenium.click("//img[@alt='Calendar']")
self.selenium.click("link=31")
self.selenium.type("releasedate", "29/07/2009")
self.selenium.click("discussion")
self.selenium.click("link=Today")
self.selenium.click("//div[@id='middle_port']/form/div[10]/span/a[1]")
self.selenium.click("//a[@id='calendarlink1']/img")
self.selenium.click("//div[@id='calendarin1']/table/tbody/tr[2]/td[1]/a")
self.selenium.click("topitem")
self.selenium.type("resourceurl", "http://www.eaudeweb.ro/")
self.selenium.type("source", "http://www.wikipedia.com/")
self.selenium.type("smallpicture", "/home/bogdan/Desktop/brain-icon.png")
self.selenium.click("//input[@value='Submit']")
self.selenium.wait_for_page_to_load("30000")

def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)

#if __name__ == "__main__":
# suite = unittest.TestLoader().loadTestsFromTestCase(DocumentTest)
2 changes: 2 additions & 0 deletions selenium_status.sh
@@ -0,0 +1,2 @@
#!/bin/bash

0 comments on commit 9f07f32

Please sign in to comment.