Monday, August 27, 2012

Handling Multiple window or Pop-Up window using Selenium RC

Handling Multiple window or Pop-Up window using Selenium RC :

// select new window
selenium.selectWindow("Google Window"); 
//Do whatever you want to do on new window
selenium.click("link=submit");
//Close the newly opened window
Selenium.close(); 
//To choose the original window back.
selenium.selectWindow(null); 


Friday, August 3, 2012

Creating Junit test Suites in Ecplice

Retrieving all Hyperlinks on Page with Selenium

You can retrieve the all the hyperlinks on page by this way


// Initialized  the counter and get the hyperlinks (started with //a) count

int count = selenium.getXpathCount("//a").intValue();
// run the loop till  total hyper link counter
for(int i=1;i<=count;i++)
{
//Iterate the received links through getText
String links = selenium.getText("xpath=(//a)["+i+"]" );
System.out.println("link : "+links);
}

Thursday, August 2, 2012

Folder Lock


if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK
if NOT EXIST Locker goto MDLOCKER
:CONFIRM
echo Are you sure u want to Lock the folder(Y/N)
set/p "cho=>"
if %cho%==Y goto LOCK
if %cho%==y goto LOCK
if %cho%==n goto END
if %cho%==N goto END
echo Invalid choice.
goto CONFIRM
:LOCK
ren Locker "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
echo Folder locked
goto End
:UNLOCK
echo Enter password to Unlock folder
set/p "pass=>"
if NOT %pass%==type your password here goto FAIL
attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Locker
echo Folder Unlocked successfully
goto End
:FAIL
echo Invalid password
goto end
:MDLOCKER
md Locker
echo Locker created successfully
goto End
:End



Note:-New folder named 'Locker' would be formed at the same location. keep all artifacts in the lock folder

Sending Email in Selenium RC

This is function help you to send the Email to multiple stockholders with Test Report as an attachment.:


package zipQuoteNavigation;
//File Name SendFileEmail.java

import java.text.SimpleDateFormat;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import org.fest.swing.testng.listener.*;


public class SendFileEmail
{
public static void main(String [] args){
// Recipient's email ID needs to be mentioned.
String to = "utakalkar@king.com,argupta@king.com,mdeshmukh@king.com,sgainewar@king.com" ;
//String to = "sgainewar@king.com";
  // Sender's email ID needs to be mentioned
  String from = "sgainewar@king.com";

  // Assuming you are sending email from localhost  , enter the host (check in outlook)
  String host = "host";

  // Get system properties
  Properties properties = System.getProperties();

  // Setup mail server
  properties.setProperty("mail.smtp.host", host);

  // Get the default Session object.
  Session session = Session.getDefaultInstance(properties);

  try{
  System.out.println("---------------- Email Process Started.... " + System.currentTimeMillis());

// Below code in try catch method executed the batch file created in location D:\temp
  //Runtime rn =Runtime.getRuntime();
try {
//Process p1 = rn.exec("cmd /c start D:\\temp\\a.bat");

}
catch(Exception e){};

     // Create a default MimeMessage object.
     MimeMessage message = new MimeMessage(session);

     // Set From: header field of the header.
     message.setFrom(new InternetAddress(from));

     // Set To: header field of the header.
     message.addRecipients(Message.RecipientType.TO,
                              to);

     // Set Subject: header field
     message.setSubject("Whistleblower Report on Zip code navigation !");

     // Create the message part
     BodyPart messageBodyPart = new MimeBodyPart();

     // Fill the message
     messageBodyPart.setText("To find the more details on the test result find attachment ");
   
     // Create a multipar message
     Multipart multipart = new MimeMultipart();

     // Set text message part
     //multipart.addBodyPart(messageBodyPart);

     // Part two is attachment
     messageBodyPart = new MimeBodyPart();
   
     String filename = "C:\\Documents and Settings\\sgainewar\\workspace\\HQF\\test-output\\emailable-report.html";
     DataSource source = new FileDataSource(filename);
     messageBodyPart.setDataHandler(new DataHandler(source));
     messageBodyPart.setFileName(filename);
     multipart.addBodyPart(messageBodyPart);
     // Send the complete message parts
     message.setContent(multipart );

     // Send message
     Transport.send(message);
     System.out.println("Sent message successfully....");
  }catch (MessagingException mex) {
     mex.printStackTrace();
   
  }
}
}