/*
*
* TC29_Create_Audit_Policy: Create/Verify Audit Policy
*
* This Test Case verifies the following:
* - user login : configurator
* - Click on Complaince->Manage Policies
* - Click New and create a new audit policy
* - Verify it is created successfully
* - Logout
*
* */
package smartware;
import com.thoughtworks.selenium.*;
import static org.testng.Assert.*;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.regex.Pattern;
import org.testng.Reporter;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Parameters;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.Test;
public class TC24_Create_Audit_Policy {
private DefaultSelenium browser ;
/*
* These parameters are specified in testSuite/testSuite.xml file
* browser.host - Host on which test case is executed
* browser.testBrowser - Browser on which test Case is executed
* Example of Browser and parameter to be passed for them are:
* *firefox = to open TestCase in Firefox.
* *iexplorer = To open Test Case in Internet Explorer
* *chrome = To Open Test Case in Google Chrome
*
* browser.port - port number on which selenium server will start
* browser.url - Application Under Test - IDM URL
*
* */
@BeforeSuite(alwaysRun = true)
@Parameters({"browser.host","browser.port","browser.testBrowser","browser.url"})
public void start (String host, String port, String testBrowser, String url ){
browser = new DefaultSelenium (host, Integer.parseInt(port), testBrowser, url);
// browser.start();
}
/*
* in the testAuditPolicy():
*
* These parameters are specified in testSuite/testSuite.xml file
*
* browser.setSpeed - Browser speed of execution
*
* browser.language,browser.country - used with IDM URL to display the webUI in the specified language
*
* Note: Also used to open respective MessagesBundle and Configs properties files - Locale dependent values
* Note: The code may show that:
* All statements working with l10n strings (MessageBundles) are commented,
* instead language independent locators, XPaths for finding the elements
* In case of using of MessageBundle, a comment is given for using the same.
*
* browser.timeout - used with waitForPageToLoad() : wait till the specified time period
*
* browser.screenshot_path - Path to store the screenshot images taken
*
* browser.Password_Minimum_Length - Minimum Password length
* browser.Password_Maximum_Length - Maximum Password length
* browser.SQP_user - A test user used to verify just the policy violation messages
* AUDIT_POLICY_NAME,AUDIT_POLICY_DESC,LDAP_RESOURCE_NAME - Configs Bundle
*
* */
@Test(groups = { "functest" })
@Parameters({"browser.setSpeed","browser.language","browser.country","browser.timeout","browser.screenshot_path"})
public void testAuditPolicy(String setSpeed,String language, String country, String timeout, String screenshot_path) throws Exception {
// Browser is started here
browser.start();
// Get the Test Case Name
Class cls=this.getClass();
String Class_Name= cls.getName();
/*
* Open the URL: in the form, example:
* http://192.168.1.214:8080/idm/login.jsp?lang=es&cntry=ES
* language, country are taken from testSuite.xml
* This way IDM WebUI is started in the respective language as per testSuite.xml settings
*
* */
// Open the Application Under Test IDM URL in specified language,country
browser.open("/idm/login.jsp?lang="+language+"&"+"cntry="+country);
browser.windowFocus();
browser.windowMaximize();
// Set the speed of execution
browser.setSpeed(setSpeed);
Locale currentLocale;
// Load Message catalogs - MessageBundles : Contains l10n values of button labels etc.
//Configs contain locale dependent parameters like: firstname etc.
ResourceBundle messages,configs;
currentLocale = new Locale(language, country);
messages = ResourceBundle.getBundle("MessagesBundle",currentLocale);
configs = ResourceBundle.getBundle("Configs",currentLocale);
// Login Page: Enter Username = configurator - using id
browser.type("accountId","configurator");
// "accountID" - from MessageBundle.
//browser.type(messages.getString("USERNAME"), "configurator");
// Enter password = configurator - using id
browser.type("password","configurator");
// "password" - from MessageBundle
//browser.type(messages.getString("PASSWORD"), "configurator");
// Click button "Login" - Using Xpath
browser.click("//input[@onClick=\"submitCommand(this.form, 'login');\"]");
// Click button "Login" - Using MessageBundle
//browser.click(messages.getString("LOGIN_BUTTON"));
try {
// Check for the Tab = Compliance. Using css locator, independent of language
for (int second = 0;; second++) {
if (second >= 60) break;
try { if (browser.isElementPresent("css=a[href*=compliance/manage.jsp]")) break; } catch (Exception e) {}
Thread.sleep(1000);
}
// Click on Compliance Tab
browser.click("css=a[href*=compliance/manage.jsp]");
browser.waitForPageToLoad(timeout);
// Click on button New
browser.click("//input[@onClick=\"setValue(this.form, 'create', '*null*');this.form.action='compliance/editAuditPolicy.jsp?newView=true';submitCommandAndYallComeBack('create', this.form, 'New');\"]");
browser.waitForPageToLoad(timeout);
// Input Policy Name,Policy Description using id=policyName
browser.type("id=policyName",configs.getString("AUDIT_POLICY_NAME"));
browser.type("id=description",configs.getString("AUDIT_POLICY_DESC"));
// Audit Policy Wizard: Click on button Next
browser.click("//input[@onClick=\"setValue(this.form, 'Main Wizard Panel', 'RuleTypePanel');submitCommandAndYallComeBack('Main Wizard Panel', this.form, 'Recalculate');\"]");
browser.waitForPageToLoad(timeout);
// Audit Policy Wizard: Click on button Next
browser.click("//input[@onClick=\"setValue(this.form, 'Main Wizard Panel', 'RuleNamePanel');submitCommandAndYallComeBack('Main Wizard Panel', this.form, 'Recalculate');\"]");
browser.waitForPageToLoad(timeout);
// Enter Rule Name
browser.type("rules[Rule1].ruleName",configs.getString("AUDIT_POLICY_NAME")+"::"+"Rule3");
// Audit Policy Wizard: Click on button Next
browser.click("//input[@onClick=\"setValue(this.form, 'Main Wizard Panel', 'ResourceSelectPanel');submitCommandAndYallComeBack('Main Wizard Panel', this.form, 'Recalculate');\"]");
browser.waitForPageToLoad(timeout);
assertFalse(browser.isElementPresent("css=img[src=images/alerts/error_large.gif]"),"Rule Name already exists");
// Select the resource that will be referenced by this rule.Using LDAP_RESOURCE_NAME created in TC16_Create_LDAP_Resource
browser.select("rules[Rule1].PolicyResource", "label="+configs.getString("LDAP_RESOURCE_NAME"));
// Audit Policy Wizard: Click on button Next
browser.click("//input[@onClick=\"setValue(this.form, 'Main Wizard Panel', 'AttributeConditionPanel');submitCommandAndYallComeBack('Main Wizard Panel', this.form, 'Recalculate');\"]");
browser.waitForPageToLoad(timeout);
// Fill in rule (e.g. "lastname contains xxx")
browser.check("id=rules[Rule1].terms[cond1].removeRow");
browser.select("rules[Rule1].terms[cond1].ref", "label=lastname");
browser.type("rules[Rule1].terms[cond1].value", "xxx");
// Audit Policy Wizard: Click on button Next
browser.click("//input[@onClick=\"setValue(this.form, 'Main Wizard Panel', 'RuleList');submitCommandAndYallComeBack('Main Wizard Panel', this.form, 'Recalculate');\"]");
browser.waitForPageToLoad(timeout);
browser.click("rules[Rule1].removeRow");
// Audit Policy Wizard: Click on button Next
browser.click("//input[@onClick=\"setValue(this.form, 'Main Wizard Panel', 'WorkflowPanel');submitCommandAndYallComeBack('Main Wizard Panel', this.form, 'Recalculate');\"]");
browser.waitForPageToLoad(timeout);
browser.select("remediationWorkflow", "label=Standard Remediation");
browser.waitForPageToLoad(timeout);
// Audit Policy Wizard: Click on button Next
browser.click("//input[@onClick=\"setValue(this.form, 'Main Wizard Panel', 'RemediatorsPanel');submitCommandAndYallComeBack('Main Wizard Panel', this.form, 'Recalculate');\"]");
browser.waitForPageToLoad(timeout);
// Input Level1 Remediators=configurator
browser.type("inputescalations[level1].remediators", "configurator");
// browser.click("add");
// add
browser.click("//input[@onClick=\"listeditor_add(this.form, 'escalations[level1].remediators', 'inputescalations[level1].remediators',true,false);\"]");
// browser.addSelection("escalations[level1].remediators", "label=configurator");
// Audit Policy Wizard: Click on button Next
browser.click("//input[@onClick=\"setValue(this.form, 'Main Wizard Panel', 'MemberObjectGroupsPanel');submitCommandAndYallComeBack('Main Wizard Panel', this.form, 'Recalculate');\"]");
browser.waitForPageToLoad(timeout);
// Select the organization = Top that will have visibility to this audit policy.
browser.addSelection("unselectedorganizations", "label=Top");
// Click on button '>' to add the organization = Top: Using button id
browser.click("select");
// Click button "Finish"
// Audit Policy Wizard: Click on button Next
browser.click("//input[@onClick=\"submitCommand(this.form, 'Save');\"]");
browser.waitForPageToLoad(timeout);
assertTrue(browser.isTextPresent(configs.getString("AUDIT_POLICY_NAME")),"Audit Policy Creation Fails");
// Log the result to the Reports file, File name will be: Class_Name:PASSED:"Message"
Reporter.log(Class_Name+":PASSED:" + "Audit Policy is Created successfully");
}
// Catch - if problem exists, Take a screenshot
//and print the error message to the log file
catch(AssertionError e) {
browser.captureScreenshot(screenshot_path + Class_Name + ".PNG");
Reporter.log("Test Case:"+Class_Name+":FAILED:" + e.getMessage() + "Please check the screenshot for more details");
}
/*
* Wait for logout element present in webpage .
* Default timeout is set to 60.
*
* */
for (int second = 0;; second++) {
if (second >= 60) break;
try { if (browser.isElementPresent("css=a[href*=logout]")) break; } catch (Exception e) {}
Thread.sleep(1000);
}
// Click on button Logout - using css locator
browser.click("css=a[href*=logout]");
// Close the Browser
//browser.close();
// Stop the Browser
browser.stop();
}
/*
*
*In stop() method browser is closed after complete execution of Test Case
*and Selenium Server is also closed for corresponding Test Case
*
* */
@AfterTest(alwaysRun = true)
public void stop() {
Reporter.log ("Test Case Completed");
}
}
/*
* TC16_Create_LDAP_Resource: Create a LDAP Resource
*
* This Test Case verifies the following:
* - user login : configurator
* - Create a LDAP resource
* - Verify the newly created LDAP resource
* - Logout from IDM
*
* */
package smartware;
import com.thoughtworks.selenium.*;
import static org.testng.Assert.*;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.regex.Pattern;
import org.testng.Reporter;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Parameters;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.Test;
public class TC16_Create_LDAP_Resource {
private DefaultSelenium browser ;
/*
* These parameters are specified in testSuite/testSuite.xml file
* browser.host - Host on which test case is executed
* browser.testBrowser - Browser on which test Case is executed
* Example of Browser and parameter to be passed for them are:
* *firefox = to open TestCase in Firefox.
* *iexplorer = To open Test Case in Internet Explorer
* *chrome = To Open Test Case in Google Chrome
*
* browser.port - port number on which selenium server will start
* browser.url - Application Under Test - IDM URL
*
* */
@BeforeSuite(alwaysRun = true)
@Parameters({"browser.host","browser.port","browser.testBrowser","browser.url"})
public void start (String host, String port, String testBrowser, String url ){
browser = new DefaultSelenium (host, Integer.parseInt(port), testBrowser, url);
// browser.start();
}
/*
* in the testRHELResource():
*
* These parameters are specified in testSuite/testSuite.xml file
*
* browser.setSpeed - Browser speed of execution
*
* browser.language,browser.country - used with IDM URL to display the webUI in the specified language
*
* Note: Also used to open respective MessagesBundle and Configs properties files - Locale dependent values
* Note: The code may show that:
* All statements working with l10n strings (MessageBundles) are commented,
* instead language independent locators, XPaths for finding the elements
* In case of using of MessageBundle, a comment is given for using the same.
*
* browser.timeout - used with waitForPageToLoad() : wait till the specified time period
*
* browser.screenshot_path - Path to store the screenshot images taken
*
* RHEL System config details: are taken from testSuite.XML
* "browser.RHEL_Host","browser.RHEL_TCP_Port","browser.RHEL_Root_User",
* "browser.RHEL_Root_Passwd","browser.RHEL_Shell_Prompt",
* "browser.RHEL_Connection_Type","browser.RHEL_Home_Dir",
*
* RHEL Resource Name: is taken from Configs Bundle
* "browser.RHEL_Resource_Name
*
* * */
@Test(groups = { "functest" })
@Parameters({"browser.setSpeed","browser.language","browser.country","browser.timeout","browser.screenshot_path","browser.LDAP_Host","browser.LDAP_Port","browser.LDAP_UserDN","browser.LDAP_Credentials","browser.LDAP_BaseContext","browser.LDAP_TemplateName"})
public void testLDAPResource(String setSpeed,String language,String country,String timeout,String screenshot_path,String LDAP_Host,String LDAP_Port,String LDAP_UserDN,String LDAP_Credentials,String LDAP_BaseContext , String LDAP_TemplateName) throws Exception {
// Browser is started here
browser.start();
// Get the Test Case Name
Class cls=this.getClass();
String Class_Name= cls.getName();
/*
* Open the URL: in the form, example:
* http://192.168.1.214:8080/idm/login.jsp?lang=es&cntry=ES
* language, country are taken from testSuite.xml
* This way IDM WebUI is started in the respective language as per testSuite.xml settings
*
* */
// Open the Application Under Test IDM URL in specified language,country
browser.open("/idm/login.jsp?lang="+language+"&"+"cntry="+country);
browser.windowFocus();
browser.windowMaximize();
// Set the speed of execution
browser.setSpeed(setSpeed);
Locale currentLocale;
// Load Message catalogs - MessageBundles : Contains l10n values of button labels etc.
//Configs contain locale dependent parameters like: firstname etc.
ResourceBundle messages,configs;
currentLocale = new Locale(language, country);
messages = ResourceBundle.getBundle("MessagesBundle",currentLocale);
configs = ResourceBundle.getBundle("Configs",currentLocale);
// Login Page: Enter Username = configurator - using id
browser.type("accountId","configurator");
// "accountID" - from MessageBundle.
//browser.type(messages.getString("USERNAME"), "configurator");
// Enter password = configurator - using id
browser.type("password","configurator");
// "password" - from MessageBundle
//browser.type(messages.getString("PASSWORD"), "configurator");
// Click button "Login" - Using Xpath
browser.click("//input[@onClick=\"submitCommand(this.form, 'login');\"]");
// Click button "Login" - Using MessageBundle
//browser.click(messages.getString("LOGIN_BUTTON"));
browser.waitForPageToLoad(timeout);
// Check Tab = Resources -using css locator
browser.click("css=a[href*=resources/list]");
browser.waitForPageToLoad(timeout);
// Select Action = New Resource, using value
browser.select("ResourceTypeActionsMASTHEADResourceTypeActions","value="+"New Resource");
// Select Action = New Resource, from Message Bundle
// browser.select("ResourceTypeActionsMASTHEADResourceTypeActions","label="+messages.getString("NEWRESOURCE_OPTION"));
/*
* Hanaki's code: Check if the Resource LDAP is managed, if it is not present
* Click on Configure Types and Check the LDAP and Save */
if(false == browser.isElementPresent("css=option[value=LDAP]")){
browser.click("css=a[href=resources/managedResources.jsp]");
browser.waitForPageToLoad(timeout);
browser.check("com.waveset.adapter.LDAPResourceAdapter.managed");
// Click on button save - XPath
browser.click("//input[@onClick=\"submitCommand(this.form, 'Save');\"]");
// Click on Save button - using MessagesBundle
//browser.click(messages.getString("SAVE_BUTTON"));
browser.waitForPageToLoad(timeout);
browser.click("css=a[href*=resources/list]");
browser.waitForPageToLoad(timeout);
// Select Action = New Resource, using value
browser.select("ResourceTypeActionsMASTHEADResourceTypeActions","value="+"New Resource");
// Select Action = New Resource, using Messagebundle
// browser.select("ResourceTypeActionsMASTHEADResourceTypeActions","label="+messages.getString("NEWRESOURCE_OPTION"));
browser.waitForPageToLoad(timeout);
}
try {
// New Resource Page: Select an LDAP resource
browser.select("resType", "label=LDAP");
browser.waitForPageToLoad(timeout);
// New Resource Page: Click on button New - Using XPath
browser.click("//input[@onClick=\"submitCommand(this.form, 'New');\"]");
// New Resource Page: Click on button New - Using MessagesBundle
//browser.click(messages.getString("NEW_BUTTON"));
browser.waitForPageToLoad(timeout);
// Create LDAP Resource Wizard: Welcome page: Click on button Next - Using XPath
browser.click("//input[@onClick=\"setValue(this.form, 'Resource Wizard', 'Resource Parameters');submitCommandAndYallComeBack('Resource Wizard', this.form, 'Recalculate');\"]");
// Create LDAP Resource Wizard: Welcome page: Click on button Next - Using MessagesBundle
// browser.click(messages.getString("NEXT_BUTTON"));
browser.waitForPageToLoad(timeout);
// Create LDAP Wizard: Resource Parameters page:
//Set the Host address,port,username,password,shell prompt,connection type and Home Dir
// Taken from testSuite.xml
browser.type("resourceAttributes[host].value", LDAP_Host );
browser.type("resourceAttributes[port].value", LDAP_Port);
browser.type("resourceAttributes[principal].value", LDAP_UserDN);
browser.type("resourceAttributes[credentials].value", LDAP_Credentials);
browser.type("resourceAttributes[baseContext].value", LDAP_BaseContext);
// Click on button : Test Configuration : Using XPath
browser.click("//input[@onClick=\"setValue(this.form, 'testConnection', 'true');submitCommandAndYallComeBack('testConnection', this.form, 'Recalculate');\"]");
// Click on button : Test Configuration : Using MessagesBundle
//browser.click(messages.getString("TEST_CONFIGURATION_BUTTON"));
browser.waitForPageToLoad(timeout);
// Check the Test Connection status, using MessagesBundle in order to verify the l10n message
assertTrue(browser.isTextPresent(messages.getString("TEST_CONFIG_SUCCESS_MSG")),"Connection to RHEL system failed");
// Click on button Next in "Create LDAP Wizard: Resource Parameters page:" - Using XPath
browser.click("//input[@onClick=\"setValue(this.form, 'Resource Wizard', 'Account Attributes');submitCommandAndYallComeBack('Resource Wizard', this.form, 'Recalculate');\"]");
// Click on button Next in "Create LDAP Wizard: Resource Parameters page:" - Using Messages Bundle
//browser.click(messages.getString("NEXT_BUTTON"));
browser.waitForPageToLoad(timeout);
// Account Attributes page: Initially uncheck the attributes = accountId and lastname
browser.click("accountAttributes[origAttr1].required");
browser.click("accountAttributes[origAttr4].required");
// Account Attributes page: type accountId in the first field and select it as "required"
browser.type("accountAttributes[origAttr0].attributeName", "accountId");
browser.click("accountAttributes[origAttr0].required");
// Account Attributes page: type firstname=cn and select it as "required"
browser.type("accountAttributes[origAttr3].mapName", "cn");
browser.click("accountAttributes[origAttr3].required");
// Account Attributes page: type lastname=sn and select it as "required"
browser.type("accountAttributes[origAttr4].mapName", "sn");
browser.click("accountAttributes[origAttr4].required");
// Account Attributes Page: Click on button Next - Using XPath
browser.click("//input[@onClick=\"setValue(this.form, 'Resource Wizard', 'Identity Template');submitCommandAndYallComeBack('Resource Wizard', this.form, 'Recalculate');\"]");
// Account Attributes Page: Click on button Next - Using MessagesBundle
//browser.click(messages.getString("NEXT_BUTTON"));
// Identity Template Page: Insert the value of "Identity Template":
browser.waitForPageToLoad(timeout);
browser.type("template", LDAP_TemplateName);
// Identity Template Page: Click on button Next - Using XPath
browser.click("//input[@onClick=\"setValue(this.form, 'Resource Wizard', 'Lighthouse Parameters');submitCommandAndYallComeBack('Resource Wizard', this.form, 'Recalculate');\"]");
// Identity Template Page: Click on button Next - Using MessagesBundle
// browser.click(messages.getString("NEXT_BUTTON"));
browser.waitForPageToLoad(timeout);
// Identify System Parameters Page: Enter LDAP_RESOURCE_NAME : From Configs Bundle
// Using id attribute
browser.type("name", configs.getString("LDAP_RESOURCE_NAME"));
// Identify System Parameters Page: Select the Display Name Attribute = accountId
browser.select("resourceAttributes[Display Name Attribute].value", "label=accountId");
// Click on button Save - Using XPath
browser.click("//input[@onClick=\"submitCommand(this.form, 'Save');\"]");
//Click on button Save - Using Messages Bundle
//browser.click(messages.getString("SAVE_BUTTON"));
browser.waitForPageToLoad(timeout);
// Check if any error message is displayed while clicking on button "Save"
// Verify the image displayed with the l10n error message
assertFalse(browser.isElementPresent("css=img[src=images/alerts/error_large.gif]"),"LDAP Resource Name already exists");
// List Resources Page: Click on ResetView button - Using id attribute
browser.click("ResetView");
browser.waitForPageToLoad(timeout);
// List Resources Page: Click on the button Tree View
browser.click("css=img[src=images/tree/tree_handlerightmiddle.gif]");
browser.waitForPageToLoad(timeout);
// Check if the new LDAP resource name is present in the page
assertTrue(browser.isTextPresent(configs.getString("LDAP_RESOURCE_NAME")),"Could not find the LDAP resourcename");
// Log the result to the Reports file, File name will be: Class_Name:PASSED:"Message"
Reporter.log(Class_Name+":PASSED:" + "LDAP resource is created successfully");
}
// Catch - Any problem encountered, Take a screenshot
//and print the error message to the log file
catch(AssertionError e) {
browser.captureScreenshot(screenshot_path + Class_Name + ".PNG");
Reporter.log("Test Case:"+Class_Name+":FAILED:" + e.getMessage() + "Please check the screenshot for more details");
}
/*
* Wait for logout element present in webpage .
* Default timeout is set to 60.
*
* */
for (int second = 0;; second++) {
if (second >= 60) break;
try { if (browser.isElementPresent("css=a[href*=logout]")) break; } catch (Exception e) {}
Thread.sleep(1000);
}
// Click on button Logout - using css locator
browser.click("css=a[href*=logout]");
// Close the Browser
//browser.close();
// Stop the Browser
browser.stop();
}
/*
* In stop() method browser is closed after complete execution of Test Case
* and Selenium Server is also closed for corresponding Test Case
*
* */
@AfterTest(alwaysRun = true)
public void stop() {
Reporter.log ("Test Case Completed");
}
} |
Reply |
| Forward |
|
|
|
|
|
| New window Print all |