Saturday, August 14, 2010

selenium with pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</
modelVersion>
    <groupId>com.itgrids</groupId>
    <artifactId>SampleTest1</artifactId>
    <version>1.0.0</version>
    <packaging>pom</packaging>
    <name>Selenium Functional Tests</name>
    <url>http://www.salesforce.com</url>
    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium.client-drivers</groupId>
            <artifactId>selenium-java-client-driver</artifactId>
            <version>1.0.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium.server</groupId>
            <artifactId>selenium-server</artifactId>
            <version>1.0.1</version>
            <scope>test</scope>
        </dependency>
    <dependency>
          <groupId>org.testng  </groupId>
          <artifactId>testng</artifactId>
          <version>5.8</version>
          <scope>test</scope>
          <classifier>jdk15</classifier>
        </dependency>
     </dependencies>
    <build>
 
        <plugins>
       
         <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
           
             <!-- Selenium Maven Plugin -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
       <artifactId>selenium-maven-plugin</artifactId>
        <version>1.0</version>
                <executions>
                    <execution>
                     <id>copy</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start-server</goal>
                        </goals>
                        <configuration>
                            <!-- <artifactItems>
                                <artifactItem>
                                    <groupId>org.seleniumhq.selenium.server</groupId>
                                    <artifactId>selenium-server</artifactId>
                                    <version>1.0.1</version>
                                    <type>jar</type>
                                    <outputDirectory></outputDirectory>
                                    <destFileName>selenium-server.jar</destFileName>
                                </artifactItem>
                            </artifactItems> -->
                            <background>true</background>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            
            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>start-selenium</id>
                        <phase>pre-integration-test</phase>
                        <configuration>
                            <tasks>
                                <echo taskname="selenium" message=" Starting Selenium Remote Control                        "/>
                                <java jar="/selenium-server.jar" fork="yes" spawn="true">
                                 <arg line="-firefoxProfileTemplate ${profiles} -singleWindow -ensureCleanSession" />
                              </java>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop-selenium</id>
                        <phase>post-integration-test</phase>
                        <configuration>
                            <tasks>
                                <echo taskname="selenium" message=" Shutting down Selenium Remote Control"/>
                                <echo taskname="selenium" message=" DGF Errors during shutdown are expected"/>
                                <get taskname="selenium"
                                     src="http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer"
                                     dest="result.txt" ignoreerrors="true"/>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
           
            <!-- Surefire plugin -->
   
   <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
       
        <executions>
            <execution>
                <phase>integration-test</phase>
                <goals>
                    <goal>test</goal>
                </goals>
                <configuration>
                <excludes>
                    <exclude>**/*.java</exclude>
                  </excludes>
                    <skip>false</skip>
                </configuration>
            </execution>
        </executions>
        <configuration>
            <suiteXmlFiles>
                <suiteXmlFile>
                    **/*.xml
                  </suiteXmlFile>
            </suiteXmlFiles>
            <parallel>true</parallel>
            <threadCount>10</threadCount>
        </configuration>
    </plugin>

        </plugins>
    </build>
   
     <reporting>
    <outputDirectory>SampleTest1/reports</outputDirectory>
  </reporting>
   
    <repositories>
        <repository>
            <id>openqa</id>
            <url>http://maven.openqa.org</url>
        </repository>
    </repositories>
    <properties>
        <selenium-version>1.0.1</selenium-version>
    </properties>
</project>

selenium configurations with build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="IDMAutomation" default="stop-server" basedir=".">
  

    <property name="sourceDir" location="src" />
    <property name="imgsDir" location="imgs" />
    <property name="buildDir" location="bin" />
    <property name="reportDir" location="reports" />
    <property name="libDir" location="lib" />
    <property name="profileDir" location="profiles" />
    <property name="testSuiteLocation" location="testSuite" />
  
  
      
    <path id="master-classpath">
        <fileset dir="${libDir}">
            <include name="*.jar"></include>
        </fileset>
        <pathelement path="${buildDir}"></
pathelement>
    </path>
  
    <taskdef resource="testngtasks" classpath="${libDir}/testng-5.10-jdk15.jar" />
  
    <target name="start-server">      
        <java jar="${libDir}/selenium-server.jar" fork="true" spawn="true" >
            <arg line="-firefoxProfileTemplate ${profileDir} -singleWindow -ensureCleanSession" />
        </java>      
    </target>
  
    <target name="clean" description="Remove the build and report directories">
        <delete dir="${buildDir}" />
        <delete dir="${reportDir}" />
        <delete dir="${imgsDir}" />
      
    </target>
  
    <target name="build" description="Creates a build of the test suite.">
    <echo>"Making directory ${buildDir}"</echo>
    <mkdir dir="${buildDir}" />
    <echo>"Making directory ${reportDir}"</echo>
    <mkdir dir="${reportDir}" />
    <mkdir dir="${imgsDir}" />

    <echo>"Doing build..."</echo>
    <javac destdir="${buildDir}" debug="true" deprecation="false" failonerror="true">
    <src path="${sourceDir}" />
    <classpath refid="master-classpath"></classpath>
    </javac>
    </target>
  
    <target name="doTest" description="Execute TestNG tests">
    <testng classpathref="master-classpath" outputdir="${reportDir}"
    sourcedir="${sourceDir}" workingDir="${buildDir}">
    <!-- Specify suites or scripts to run here -->
    <xmlfileset dir="${testSuiteLocation}" includes="*.xml" />          
    </testng>
    </target>
    <target name="stop-server" depends="clean,build,start-server,doTest">
    <get taskname="selenium-shutdown"
    src="http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer" dest=".result.txt"
    ignoreerrors="true" />
    <echo taskname="selenium-shutdown" message="DGF Errors during shutdown are expected" />
    </target>

</project>

selenium Tesng code

/*
 *
 * 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");
    }
}


From cricket scores to your friends. Try the Yahoo! India Homepage!
Reply

Forward





« Back to "Personal"
 
Remove label "Personal"
 
Report spam
 
Delete
 
Move to
 
 
Labels
 
 
More actions
 
‹ Newer 39 of 53 Older ›
You are currently using 510 MB (6%) of your 7486 MB.
Last account activity: 3 hours ago at this IP (124.123.73.71).  Details
Gmail view: standard | turn off chat | turn off buzz | older contact manager | older version | basic HTML  Learn more

selenium sample scripts using testNG suite.xml

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="MyTestSuiteName" >

    <!-- Selenium Server Details -->

    <parameter name="browser.host" value="localhost" />
    <parameter name="browser.port" value="4444" />
  
    <!-- Browser Details -->
  
    <parameter name="browser.testBrowser" value="*firefox" />
  
    <!-- Browser Set Speed -->
  
    <parameter name="browser.setSpeed" value="2000" />
  
    <!-- Wait time, used with waitForPageToLoad -->
  
    <parameter name="browser.timeout" value="30000" />
  
    <!-- IDM URL Details -->
    <parameter name="browser.url" value="https://192.168.1.215:8181/idm/login.jsp" />
  
    <!-- Language and Country Details.This will start the IDM in the language as:
    http://<host>:<port>/idm/
login.jsp?lang=browser.language,cntry=browser.country -->
  
    <parameter name="browser.language" value="fr" />
    <parameter name="browser.country" value="FR" />
  
    <!-- Provide Screenshot Path. Location to save the Screenshots taken in different TestCases.
    Leave this setting as it is.
    or in case of modifications change respectively in build.xml file
    Also Note:
    For POSIX: dir separator will follow: '/'
    For Windows: dir separator will follow: '\' -->
  
    <parameter name="browser.screenshot_path" value="./imgs/" />
  
    <!-- Used in Test Case: Create/Edit RHEL resource, Resource Name is from Configs Bundle as it may be localized -->
    <!-- Start -->
  
    <parameter name="browser.RHEL_Host" value="192.168.1.215" />
    <parameter name="browser.RHEL_TCP_Port" value="23" />
    <parameter name="browser.RHEL_Root_User" value="root" />
    <parameter name="browser.RHEL_Root_Passwd" value="smart123" />
    <parameter name="browser.RHEL_Shell_Prompt" value="#" />
    <parameter name="browser.RHEL_Connection_Type" value="Telnet" />
    <parameter name="browser.RHEL_Home_Dir" value="/home" />
      
    <!-- End -->
  
    <!-- Used in Test Case: Create LDAP resource Parameters, Resource Name is from Configs Bundle as it may be localized -->
    <!-- Start -->
    <parameter name="browser.LDAP_Host" value="192.168.1.215" />
    <parameter name="browser.LDAP_Port" value="389" />
    <parameter name="browser.LDAP_UserDN" value="cn=Manager,dc=example,dc=com" />
    <parameter name="browser.LDAP_Credentials" value="ldap123" />
    <parameter name="browser.LDAP_BaseContext" value="dc=example,dc=com" />
  
    <parameter name="browser.LDAP_TemplateName" value="uid=$accountId$,ou=People,dc=example,dc=com" />
    <!--End -->
  
    <!-- Create UserLock Parameters -->
    <!-- Start -->
  
        <parameter name="browser.max_login_attempt" value="2" />
  
    <!--End -->
  
    <!-- Create Directory Junction Parameters -->
    <!-- Start -->
    <!-- dc=example,dc=com -->
  
    <parameter name="browser.LDAP_orgname" value="example" />
  
    <!--End -->
  
    <!-- Create String Quality Policy Parameters, Quality Policy Name is from Configs Bundle as it may be localized -->
    <!-- Start -->
  
    <parameter name="browser.Password_Minimum_Length" value="3" />
    <parameter name="browser.Password_Maximum_Length" value="4" />
    <parameter name="browser.SQP_user" value="sqpuser" />
    <parameter name="browser.Min_Password" value="ab" />
    <parameter name="browser.Max_Password" value="abcde" />
  
    <!--End -->
  
    <test verbose="2" name="whatever" annotations="JDK">
    <groups>
    <run>
        <include name="functest"/>
    </run>
    </groups>
  
      
<classes>

selenium framework design

http://sourceforge.net/projects/webauthfw/