The best way to check that the action is competed succefully is to check that given user is presented in this report and has appropriate permissions set. It is very easy to do using the QueryTable fixture.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!|script| | |
|start|Browser| | |
|$port=|get port| | |
|go|http://${IP_HOST}:$port/make/search?filter=wappl&search_limit=20| | |
|wait for load complete;| | |
|set selected;|id=${wa7}| | |
|set selected;|id=${wa8}| | |
|click|id=btnGrant-button| | |
!|script| | |
|is element displayed;|id=dialogGrant| | |
|check|get_value|id=id_scope_grant|${wa8};${wa7};| | |
|type;|id=id_users_grant|${domain}\${U1};${domain}\${U2}| | |
|click|xpath=//input[@name="Full Control"]| | |
|submit|xpath=//form[@id="formGrantPermissions"]| | |
!|script| | |
|wait for element is not displayed;|id=perpetum|${actionTimeout}| | |
|Subset Query:permissions actions report|${domain}\${U1}| | |
|site|level| | |
|${SITE_COLLECTION1}|${PM}| | |
|${SITE_COLLECTION2}|${PM}| | |
|${wa7}|${PM}| | |
|${wa8}|${PM}| |
Just define a class with the query method and a constructor that takes a user name. Pay attention that this QueryTable class should aggregate the Browser class instance to access data on the html page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PermissionsActionsReport(): | |
def __init__(self,u): | |
self.ip = Browser() | |
self.user = u | |
def query(self): | |
ret = [] | |
i=0 | |
while True: | |
i=i+1 | |
try: | |
curuser = self.ip.get_text('xpath=//*[@id="result"]/ul/li[%s]/b'%str(i)) | |
if self.user.lower() == curuser.lower(): | |
break | |
except: | |
return [] | |
j=0 | |
while True: | |
j=j+1 | |
try: | |
url = self.ip.get_text('xpath=//*[@id="result"]/ul/li[%s]/table/tbody/tr[%s]/td/div/span/a'%(str(i),str(j))) | |
permissions = self.ip.get_text('xpath=//*[@id="result"]/ul/li[%s]/table/tbody/tr[%s]/td[2]'%(str(i),str(j))) | |
print "%i. %s %s" % (j, url, permissions) | |
if type(url)!=type(u""): | |
return ret | |
ret.append([['site',url],['level',permissions]]) | |
except: | |
return ret |
But actually here is a problem. An architecture of FITNesse does not allow the PermissionsActionsReport QueryTable class instance to access existed instance of the Browser class that was used to make the action and that contains the result of this action. Fortunately this obstacle can be solved easy using the singleton pattern.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Browser(object): | |
__active = False | |
def __new__(type, browser): | |
if not '_instance' in type.__dict__: | |
type._instance = object.__new__(type) | |
return type._instance | |
def __init__(self, browser): | |
if browser == 'chrome': | |
from selenium.chrome.webdriver import WebDriver | |
elif browser == 'firefox': | |
from selenium.firefox.webdriver import WebDriver | |
else: | |
from selenium.ie.webdriver import WebDriver | |
if not self.__active: | |
self.__wd = WebDriver() | |
self.__active = True |
No comments:
Post a Comment