Tuesday, October 8, 2013

BIRT FAQ's

1.] How to remove decimal point and the digits after decimal on report?

-- Select the field of number value. Go to its properties section, select Format Number in it. 
Select Format as field as Custom and Format Code as ##,##,##0 instead of ##,##,##0.00

2.] The BIRT report shows year as 2014 even though the value is 2013.

-- Change the date format from YYYY to yyyy.

Friday, September 27, 2013

Installing BIRT in STS



1) Install STS 

2) Click on help -
Install New Software --> Click on Add
-> give the URL (http://download.eclipse.org/birt/update-site/4.2/)

3) Select the BIRT components you want to install--> click Next and follow the instructions such as accept terms and conditions.

4) Click on Finish, it will start installing the BIRT components.

5) It is getting installed successfully and we can see the version details on the following path: Help-
About STS
-> click on Eclipse BIRT Project

Thursday, September 26, 2013

Cookies using JSP / Servlet

Login.jsp

<form action="rem" method="POST">
Enter Value: <input type="text" name="val" value=""/>
<input type="submit" value="Submit" />
</form>

----------------------------------------------------------------------------------
RemController.java

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    String myValue = request.getParameter("val");


    Cookie userCookie = new Cookie("u", myValue);
        userCookie.setMaxAge(60*60*24);
        response.addCookie(userCookie);


    request.getRequestDispatcher("Remember.jsp").forward(request, response);
    }
----------------------------------------------------------------------------------
Remember.jsp

<html>
 <%
        Cookie[] cookies=request.getCookies();
        Cookie cookie=null;
        if(cookies != null){
            for(int i=0; i<cookies.length; i++){
                cookie = cookies[i];
                System.out.print(cookie.getName()+": ");
                System.out.println(cookie.getValue());
            }
        }
        %>
</html>
----------------------------------------------------------------------------------

Wednesday, September 25, 2013

Login Page using Servlet / JSP

1. Servlet Mapping in web.xml

Transfering control from JSP (Login.jsp) file to a servlet (RemController.java) file.
 ----------------------------------------------------------------------------------------------------------------------------
Login.jsp

<form action="rem" method="POST">
Username: <input type="text" id="username" name="username" value=""/><br/>
Password: <input type="password" id="password" name="password" value=""/><br/>
<input type="submit" id="submit" value="Submit" /><br/>

</form>
----------------------------------------------------------------------------------------------------------------------------
web.xml

 <servlet>
    <servlet-name>RemController</servlet-name>
    <servlet-class>myPkg.RemController</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>RemController</servlet-name>
    <url-pattern>/rem</url-pattern>
  </servlet-mapping>
----------------------------------------------------------------------------------------------------------------------------
RemController.java

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setAttribute("result", "hello!");
      
        String name = request.getParameter("username");
        String password = request.getParameter("password");
      
        System.out.println(name+" "+password);
      
    //    response.sendRedirect("Remember.jsp");
        request.getRequestDispatcher("Remember.jsp").forward(request, response);
        }
----------------------------------------------------------------------------------------------------------------------------
Remember.jsp

<html>
<body>
        <h1>Remember.jsp</h1>
        <p>The result is ${result}</p>
</body>
</html>
----------------------------------------------------------------------------------------------------------------------------

Wednesday, September 4, 2013

Database FAQ's

Finding Non-unique rows.

SELECT LIC_NO, count(LIC_NO) AS cnt FROM LM_LICENSE GROUP BY LIC_NO HAVING cnt>1;

Wednesday, August 14, 2013

JAVA FAQ's

1. Rounding of a double value to 2 digits.

-- Double TempTentSec = 0.0;
    TempTentSec = 111.0;
    TempTentSec = Math.round(TempTentSec * 100.0) / 100.0;

(Similarly to round of at 0 places:- Multiply & divide by 1.0)

2. Removing decimals without rounding off the double value.

-- TempTentSec = (double)Math.floor(TempTentSec);

Thursday, July 18, 2013

Oracle Synonym


Following query is to automatically update table data in one database based on changes in another database.

sql>create public synonym AMM_PRODUCTS_PHARMA for ALAB.AMM_PRODUCTS_PHARMA;

sql>create or replace
TRIGGER AMM_PRODUCTS_TRIGGER
after insert on APHARMA.AMM_PRODUCTS for each row
begin
insert into AMM_PRODUCTS_PHARMA
(PRD_ID,
PRD_GENERIC_NAME,
PRD_SHORT_DESC,
PRD_DESC
) values
(:new.PRD_ID,
:new.PRD_GENERIC_NAME,
:new.PRD_SHORT_DESC,
:new.PRD_DESC
);
end;

sql>create public synonym AMT_PROD_STOCK_DETAILS_PHARMA for ALAB.AMT_PROD_STOCK_DETAILS_PHARMA;

sql>create or replace trigger amm_prod_stock_details_trigger
after insert  on APHARMA.AMT_PROD_STOCK_DETAILS for each row
begin
 insert into AMT_PROD_STOCK_DETAILS_PHARMA
 (PRS_SEQ_NO,
PRS_DOC_DATE,
PRS_PER_ID,
PRS_CPY_ID
) values
(:new.PRS_SEQ_NO,
:new.PRS_DOC_DATE,
:new.PRS_PER_ID,
:new.PRS_CPY_ID
);
end;

-- By Mr. Nitesh Ghosalkar

Thursday, July 11, 2013

Entering sequence no in column of table already having data in SQL


  alter table AMM_PROD_DRUG_LICENCE add pdl_seq_no NUMBER(19,0);

update AMM_PROD_DRUG_LICENCE set pdl_Seq_no=1;

CREATE SEQUENCE pdl_sequence_no_seq
  START WITH 1
  INCREMENT BY 1
  CACHE 50;

UPDATE AMM_PROD_DRUG_LICENCE
   SET pdl_seq_no = pdl_sequence_no_seq.nextval;

Wednesday, July 3, 2013

Spring Roo Files



There are many different types of files used in Spring Roo project having various code to perform task:-

1.] .java files - These can be the domain class files, controller files, service files, Exception class files.

2.] .aj files - These are aspect java files and are automatically created by Spring Roo project for a particular domain class after running 'web mvc all <pkg_name>' command in Roo Shell.

3.] .jspx files - These are the view components of MVC framework for the project. These files can be used to create report search screens as well.

4.] .properties files -
(a.) database.properties - It contains the username, password, database name, IP address etc.,
(b.) ReportDS.properties - We can write information about the IP address, database, tables to connect to retrieve data to display on reports.
(c.) application.properties - We can put error codes with messages in this file. It also consists of label name for various labels in .jspx pages.

5.] .tagx -

6.] .tld - birt.tld file is used to integrate BIRT reporting tool in STS. It's full form is Tag library descriptor.

7.] .xml -

8.] .rptdesign files - These are the report design files. It has information of columns datatypes and validations with queries for BIRT reports.


Tuesday, March 19, 2013

Installing IP messenger in FEDORA OS


Steps to install IP messenger on Fedora terminal:-

tar -xzvf g2ipmsg-0.9.5.tar.gz

It is important to install the dependencies before we proceed.  On your terminal, as a root user, type:

yum install perl-XML-Parser libgnomeui-devel libpanelappletmm-devel gettext intltool

then type the following series of (familiar) commands to build and install ipmsg.

cd g2ipmsg-0.9.5

./configure --disable-applet

make

make install

then run it

g2ipmsg

You can download the IP messenger from following site:-
http://www.codeforge.com/dlpre/4510/7988031f22bb.tar.gz__.html 

Thursday, March 14, 2013

XPath



-- XPath, the XML Path Language, is a query language for selecting nodes from an XML document.

Example:-
<input name="username"/>
<input name="password"/>
<input name="submit" and @type="submit" and @value="submit"/>

XPaths of above fields are as follows
//input[@name='username']
//input[@name='password']
//input[@name='submit' and @type='submit']

Use sendKeys() for setting values to textboxes.
Use click() to perform click action on any control on webpage.

Following is the WebDriver Java code to use the above XPaths to login:-
WebDriver driver = new InternetExplorerDriver();
WebElement element;
driver.get("http://www.dummyUrl.com");
element = driver.findElement(By.xpath("//input[@name='username']"));
element.setText("admin");
element = driver.findElement(By.xpath("//input[@name='password']"));
element.setText("pass@123");
element = driver.findElement(By.xpath("//input[@name='submit' and @type='submit']"));
element.click();

VSS


Microsoft Visual SourceSafe (VSS) is a source control software package oriented towards small software development projects. Like most source control systems, SourceSafe creates a virtual library of computer files.

-- Install .Net Framework and VSS (Visual SourceSafe).

-- Create users who want to access & be allowed to edit these files in VSS & assign passwords to them.

-- Create a project in VSS & folders.

-- Add files in the respective folders by choosing working folders.

-- Right-click on file & select 'Get latest version' to get the read-only copy of latest version of a file.

-- Right-click on file & select 'Check-out' to get the writable copy of latest version of a file.

-- Right-click on file & select 'Check-in' to upload the copy of latest version of a file.

-- Files not required can be deleted from VSS & then can be removed from local working folder also.

-- It is not possible for multiple users to check-out copy of same file at a time.

Link to download VSS:-
http://www.microsoft.com/en-us/download/details.aspx?id=291

Qualitia FAQ



-- License is required for each Qualitia server PC.

-- Client machines can use the same license of the server.

-- Install Qualitia.exe server & client executables on server machine.
    (a) Create 'admin' user with a password say 'root'.

-- The database 'qualitiaserver' is created in MySQL database on Qualitia server PC.

-- Default password or when the password is reset, the password is 'qualitia123'.

-- Create a project with the name, say 'ABC_Project'.

-- Assign users for this project with respective passwords & duration of project.
    [Users can be assigned various roles.]

-- Two database is required to be installed in MySQL for the project, for example with name 'ABC_project_projectdb' and 'ABC_project_resultdb'.

-- The latest patch of qualitia 'Patch Qualitia_V3.5.64.1083.txt' has to be installed on qualitia server as well as qualitia client machines.
    (a) First rename the .txt file to .zip file, extract it & then install the QualitiaPatchUI.exe.
    [This patch helps us to use 'Double-Click' and 'StoreText' actions in testcases.]

-- There has to be some values to be set in C:\Program Files\Qualitia\Qualitia 3.5\qualitia.exe.config file.
    (a) Set DBPassword: root, DBUserName: root (MySQL login)
    (b) Set 'ProjectName' as 'Prognocis_Project'.
    (c) Set 'UserName' as 'meena_user'.
    (d) Set 'myjava' as 'C:\Program Files\Java\jre6\bin\java.exe'.
    (e) Set 'SServer' as 'localhost', if the Qualitia server PC & MySQL server is in same PC.
    (f) Set 'QualitiaProjectPath' as 'C:\Qualitia'.
    (g) Set 'xmlPath' as 'c:\Xml'.
    (h) Set 'CustomActionRepositoryPath' as 'D:\Selenium\February2013\12Feb2013\JavaCode\bin;'.
    [This is for attaching the java code for any additional features (actions) created to be used in Qualitia.]
    (i) Set 'Server' as 'localhost'.
    (j) Set 'SBrowserType' as 'iexplore'.
    (k) Set 'ServerPort' as '3306'.
    (l) Set 'SServerPath' as 'D:\software\selenium-server-standalone-2.21.0.jar'.
    (m) Set 'LogPath' as 'C:\Qualitia\log'.
    (n) Set 'MasterDB' as 'QualitiaServer'.

-- To attach java code for custom actions in Qualitia, perform the following steps:-
    (a) Create a Java project in Eclipse.
    (b) Add mysql-connector-java-5.1.6-bin.jar, selenium-java-2.3.0.jar,
selenium-server-standalone-2.25.0.jar, junit-4.8.1.jar, log4j-1.2.15.jar in Libraries of Eclipse.
    [Add selenium-firefox-driver-2.26.0.jar if test-case is to be executed on FF browser.]
    (c) Create a class (say with name 'CustomGeneral') & a method within it (with name say 'StoreMyWindowHandles'). The method name is the action name & the parameters defined for it is the parameter for the action to be used in Qualitia.
    (d) The class may extend some pre-defined class created by Qualitia, in case it has to use its methods for current custom action class.
    [for eg: class MovingScrollBar extends WebObject. WebObject class has exist(locator, locatorType) method.]
    (e) Once code is written & saved, the bin path of the project folder has to be mentioned in qualitia.exe.config file.
    (f) In Qualitia, Objects -> Custom section, select custom object category (say for example, General)
    (g) Right-Click on 'General' category & Add new class.
    (h) Select base class as per the object type, Object class name (say, CustomGeneral) & Qualitia class name (say, Custom.CustomObjects.CustomGeneral).
    (i) Add custom action for it & define parameters for it.

-- To enable repetition of tasks in Qualitia, add multiple data records in datasheet. Also do mention the TCIteration -> Selection value as 'true' to enable repetition.

-- In Qualitia, variables can be given value & can be used later for the test-case using {}.

-- The XPath required for creating reusable objects & tasks can be found using IE Dev tool or FireBug IDE.

-- While creating objects we can mention variable name for xpath so that it can take variable XPaths based on test-case required.

Official Qualitia site:-
http://www.qualitiasoft.com/ 

Wednesday, March 13, 2013

WebDriver Java code for testing

package prognocis_pkg;


import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Set;


import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;


import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.Actions;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;


class CommonActions{
    public static WebElement element;
    public static WebDriver driver=new InternetExplorerDriver();
    public static String alertText="";
   
    public void OpenURL(String url) throws InterruptedException{
        driver.get(url);
        synchronized(driver){
            driver.wait(5000);
            }
        System.out.println("Current URL: "+driver.getCurrentUrl());
    }
   
    public static void initElem(String elem, String by){
        if(by.equals("id"))
            element=driver.findElement(By.id(elem));
        else if(by.equals("xpath"))
            element=driver.findElement(By.xpath(elem));
        else if(by.equals("name"))
            element=driver.findElement(By.name(elem));
        else if(by.equals("css"))
            element=driver.findElement(By.cssSelector(elem));
        else if(by.equals("tag"))
            element=driver.findElement(By.tagName(elem));
        else if(by.equals("link"))
            element=driver.findElement(By.linkText(elem));
        else if(by.equals("partialLink"))
            element=driver.findElement(By.partialLinkText(elem));
        else if(by.equals("class"))
            element=driver.findElement(By.className(elem));
       
        System.out.println("Element "+element.getAttribute("id")+" "+element.getAttribute("name")+" initialized.");
        return;
    }
   
    public void Click(String elem, String by)throws InterruptedException{       
        initElem(elem, by);
        System.out.println(element.getAttribute("id")+" clicking.");
        element.click();   
        synchronized(driver){
            driver.wait(8000);
            }
    }
   
    public void ClickAndHold(String elem, String by) throws InterruptedException{
        initElem(elem, by);
        new Actions(driver).clickAndHold(element).perform();
        synchronized(driver){
            driver.wait(2000);
            }
    }
   
    public void Release(String elem, String by) throws InterruptedException{
        initElem(elem, by);
        new Actions(driver).release(element).perform();
        synchronized(driver){
            driver.wait(5000);
            }
    }
   
    public void SetText(String elem, String by, String text)throws InterruptedException{
        initElem(elem, by);
        element.sendKeys(text);
        synchronized(driver){
            driver.wait(5000);
            }
        System.out.println("Entered "+text+" in element "+element.getAttribute("id"));
    }
   
    public void MouseOver(String elem, String by)throws InterruptedException{
        initElem(elem, by);       
        new Actions(driver).moveToElement(element).build().perform();
        synchronized(driver){
            driver.wait(5000);
            }
        System.out.println("MouseHovered on element "+element.getAttribute("id"));
    }
   
    public void SwitchToFrame(String frameName)throws InterruptedException{
        driver.switchTo().frame(frameName);
        synchronized(driver){
            driver.wait(10000);
            }
        System.out.println("Switched to Frame: "+frameName);
    }
   
    public void SwitchToWindow(String winTitle)throws InterruptedException{
        String parentWinID = driver.getWindowHandle();
        Set<String> winIDs = driver.getWindowHandles();
               
        for(String winID : winIDs){
            if(driver.switchTo().window(winID).getTitle().equals(winTitle)){
                driver.switchTo().window(winID);
            }else{
                driver.switchTo().window(parentWinID);
            }
        }
       
        synchronized(driver){
            driver.wait(10000);
            }
       
        System.out.println("Switched to window: "+driver.getTitle());
    }
   
    public void Select(String elem, String by, String selectOption) throws InterruptedException{
        initElem(elem, by);   
        List<WebElement> optionsDoc = element.findElements(By.tagName("option"));
       
        for (WebElement option : optionsDoc) {
            if(selectOption.equals(option.getText()))
                option.click();
        }
       
        synchronized(driver){
            driver.wait(5000);
            }
    }
   
    public String SwitchToAlert() throws InterruptedException{
        Alert alert = driver.switchTo().alert();   
        alertText = alert.getText();
        System.out.println(alertText);
        synchronized(driver){
            driver.wait(1000);
            }
        alert.accept();
        return alertText;
    }
   
    public int CountOfElements(String xpathVal){
        List<WebElement> lstElems = driver.findElements(By.xpath(xpathVal));
        System.out.println(lstElems.size());
        return lstElems.size();
    }
   
    public String GetAttributeValue(String elem, String by, String attribute){
        initElem(elem, by);
        String attributeValue = "";
       
        if(attribute.equals("text")){
             attributeValue=element.getText();
        }else{       
        attributeValue = element.getAttribute(attribute);
        }
       
        System.out.println("attributeValue: "+attributeValue);
        return attributeValue;
    }
   
    public boolean VerifyExistence(String elem, String by) throws InterruptedException{
        initElem(elem, by);
        try{
            new Actions(driver).moveToElement(element).build().perform();
            synchronized(driver){
                driver.wait(1000);
                }
        }catch(Exception e){
            return false;
        }
        return true;
    }
   
    public String XMLreader(String xmlPath, String elementName)
    {
        String elementValue = null;
        try
        {
            File file = new File(xmlPath);
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document document =  db.parse(file);
            document.getDocumentElement().normalize();
            NodeList node = document.getElementsByTagName("TestData");
           
            for (int i = 0; i < node.getLength(); i++)
            {
                Node currentNode = node.item(i);
                if (currentNode.getNodeType() == Node.ELEMENT_NODE)
                {
                    Element elemnt = (Element) currentNode;
                    NodeList emailElemntList = elemnt.getElementsByTagName(elementName);
                    Element logindetails = (Element) emailElemntList.item(0);
                    NodeList mailServer1 = logindetails.getChildNodes();
                    elementValue =((Node)mailServer1.item(0)).getNodeValue();
                }
            }
        }
        catch(Exception e)
        {
            System.out.println("The Element Name " + elementName + " is not present.");
            e.printStackTrace();
        }
       
        return elementValue;
    }
   
    public void WriteLog(String logFileName, String str){   
        File file = new File("D:\\Selenium\\"+logFileName);
       
        try {
            if (!file.exists()) {
                file.createNewFile();
            }
            FileWriter fw = new FileWriter("D:\\Selenium\\"+logFileName,true);
            BufferedWriter out = new BufferedWriter(fw);
            out.append(str);
        //    out.write(str);
            out.close();
        } catch (IOException e) {
            System.err.println("Error: " + e.getMessage());           
            e.printStackTrace();           
        }
    }
}
class CommonTasks{
   
    public void Login(CommonActions objCA) throws InterruptedException{
        objCA.OpenURL("https://www.dummyUrl.com");
        objCA.SetText("username", "id", "user1");
        objCA.SetText("password", "id", "pass@123");
        objCA.Click("//button[@type='submit' and @class='button']", "xpath");       
    }
   
    public void GoToHomePg(CommonActions objCA) throws InterruptedException{
        objCA.SwitchToWindow("WindowTitle1");
        objCA.SwitchToFrame("topFrame");
        objCA.MouseOver("//img[@name=,'home')]", "xpath");
        objCA.Click("//img[@name=,'home')]", "xpath");
    }
   
    public void Navigate_Menu_Submenu(CommonActions objCA, String menu, String submenu) throws InterruptedException{
        objCA.SwitchToWindow("WindowTitle1");
        objCA.SwitchToFrame("topFrame");
        objCA.MouseOver("//img[@name='"+menu+"']", "xpath");
        objCA.Click("//span[contains(.,'"+submenu+"')]", "xpath");
    }
   
    public void ClickTimeSlot(CommonActions objCA, String KeyHrSlot, String KeyMinSlot, String AmOrPm) throws InterruptedException{       
        objCA.Click("//td[@class='apptschbg']//tr/td[text()='"+AmOrPm
                +"']//following::td[text()='"+KeyHrSlot
                +"']//following::tr//following::td[text()='"+KeyMinSlot+"']"
                ,"xpath");
    }
   
    public void ScheduleAppt(CommonActions objCA, String patLName, String patFName) throws InterruptedException{
        objCA.SwitchToWindow("Appointment Schedule");
        objCA.SwitchToFrame("ifViewdoc");
        objCA.SwitchToFrame("mainFrame");       
        objCA.SetText("PatientName", "id", patLName+" "+patFName);
        objCA.MouseOver("ok", "id");
        objCA.ClickAndHold("ok", "id");
        objCA.Release("ok", "id");
    }
   
    public String CurrentDateInFormat(String dtFormat){
        DateFormat dateFormat= new SimpleDateFormat();
        Date todaysDate= new Date();
        String dateString= dateFormat.format(todaysDate);
        return dateString;
    }
   
    public void MassSchedule(CommonActions objCA, String patLName, String patFName) throws InterruptedException{
        objCA.SwitchToWindow("WindowTitle1");
        objCA.SwitchToFrame("SchedulerFrame");
        objCA.Click("//input[@title='Mass Scheduling']", "xpath");
       
        objCA.SwitchToWindow("Mass Scheduling");
        objCA.SwitchToFrame("ifViewdoc");
        objCA.SwitchToFrame("mainFrame");
        objCA.Click("cbSelectAll", "id");
        boolean patExists = objCA.VerifyExistence("//td[text()='"+patLName+", "+patFName+"']", "xpath");
        String exists = patExists ? "Patient "+patLName+", "+patFName+" exists." : "Patient "+patLName+", "+patFName+" does not exist." ;
        System.out.println(exists);
        objCA.MouseOver("//table[@id='apptData']//td[contains(text(),'"+patLName+", "+patFName+"')]//preceding::td[2]/input//following::td[1]/input","xpath");
        objCA.Click("//table[@id='apptData']//td[contains(text(),'"+patLName+", "+patFName+"')]//preceding::td[2]/input//following::td[1]/input","xpath");
        objCA.Click("//input[@title='Calendar']", "xpath");
        int days=1;
        objCA.MouseOver("//span/div/div[2]/div/div[@class='boxMainCellsContainer']/div[@isToday='1']/following-sibling::div["+days+"]", "xpath");
        objCA.Click("//span/div/div[2]/div/div[@class='boxMainCellsContainer']/div[@isToday='1']/following-sibling::div["+days+"]", "xpath");
        objCA.MouseOver("ok", "id");
        objCA.ClickAndHold("ok", "id");
        objCA.Release("ok", "id");
    }
   
    public String DateAdd(String dateString, int days) throws ParseException{
        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
        Calendar c = Calendar.getInstance();
        c.setTime(sdf.parse(dateString));
        c.add(Calendar.DATE, days); 
        String tomorrowsDate = sdf.format(c.getTime());
        return tomorrowsDate;
    }
   
    public void LogOut(CommonActions objCA) throws InterruptedException{
        objCA.SwitchToWindow("WindowTitle1");
        objCA.SwitchToFrame("topFrame");
        objCA.Click("//a/img[@name='logout']", "xpath");
    }
}


public class MassSch {   
   
    @SuppressWarnings("deprecation")
    public static void main(String[] args) {
        try{
        CommonActions objCA = new CommonActions();
        CommonTasks objTask = new CommonTasks();
       
        objTask.Login(objCA);
        objTask.Navigate_Menu_Submenu(objCA, "appmnt", "Schedule");               
       
        objCA.SwitchToFrame("SchedulerFrame");
        String SelectedDoctor="JohnDsouza";
        String SelectedLocation="John";
        objCA.Select("selectDoc", "id", SelectedDoctor);
        objCA.Select("selectLoc", "id", SelectedLocation);       
      
        objTask.ClickTimeSlot(objCA, "01", "15", "pm");           
       
        String patFName="Jane";
        String patLName="Test";
        objTask.ScheduleAppt(objCA, patLName, patFName);
       
        String dateString = objTask.CurrentDateInFormat("MM-dd-yyyy");
       
        objTask.GoToHomePg(objCA);
        objCA.SwitchToFrame("mainFrame");
        String locName=objCA.GetAttributeValue("//table[@id='ApptTab']/tbody/tr/td","xpath","text");
       
        objTask.Navigate_Menu_Submenu(objCA, "appmnt", "Schedule");   
       
        objCA.SwitchToWindow("WindowTitle1");
        objCA.SwitchToFrame("SchedulerFrame");
        int countPatients=objCA.CountOfElements("//div[@class='apptdivbooked']");
       
        String strText = dateString+" "+SelectedDoctor+" "+locName+" Count #"+countPatients;
        System.out.println("strText: "+strText);   
       
        objCA.SwitchToWindow("WindowTitle1");
        objCA.SwitchToFrame("ApptBottom");
        objCA.Click("//input[@value='count...' and @name='Legend']", "xpath");       
        String alertText=objCA.SwitchToAlert();
       
        if(!strText.equals(alertText)){
            System.out.println("The count alert shows invalid information.");
        }else{
            System.out.println("The count alert shows valid information.");
        }
       
        objTask.MassSchedule(objCA, patLName, patFName);
       
        objCA.SwitchToWindow("WindowTitle1");
        objCA.SwitchToFrame("CalendarFrame");
        String tomorrowsDate = objTask.DateAdd(dateString,1);
       
        @SuppressWarnings("deprecation")
        Date tomDt = new Date(tomorrowsDate);
        int currentDay=tomDt.getDay();
      
        objCA.Click("//input[@class='date' and @value='"+currentDay+"']", "xpath");
        objCA.SwitchToWindow("WindowTitle1");
        objCA.SwitchToFrame("SchedulerFrame");       
     
        objTask.LogOut(objCA);
       
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}

Sunday, February 3, 2013

Selenium - Automation Testing


Selenium WebDriver is used to automate browsers. We can code in Java using Eclipse IDE to automate testing web applications in various browsers.

package org.openqa.selenium.example;
 import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

 
public class Example  {
   
public static void main(String[] args) {
       
 WebDriver driver = new HtmlUnitDriver();
       
 driver.get(http://www.google.com); 
        WebElement element = driver.findElement(By.name("q"));        
element.sendKeys("Selenium!");        
 element.submit();        
System.out.println("Page title is: " + driver.getTitle());
   
} 
}

We can use Qualitia tool to make this automation task easier. It is an application created in java to help with the testing purpose.