Pages

Monday, April 2, 2012

Browser not shown while executing Selenium tests in Hudson

While executing the Selenium tests in Hudson, you might have noticed following:

1) Browser window is not shown
2) Execution is halted while performing an action like a click event
3) Execution halts due to unexpected pop-ups which needs user interaction

The solution for this is to launch the Hudson Slave in console mode i.e.. from command prompt.

Here are the steps:

SOLUTION1:

1) Stop Hudson Slave service
2) Change the Hudson Slave service to Manual
3) Restart the machine
4) From Command prompt, go to hudson home directory and execute following command

java.exe -Xrs -jar "slave.jar" -tcp port.txt

SOLUTION2:

Launch the slave as JNLP slave:

1) Go to the slave machine.
2) Execute following command:
java -jar slave.jar -jnlpUrl http://&lt;<url_to_master>&gt;/computer/&lt;<name_of_slave>&gt;/slave-agent.jnlp
ex: java -jar slave.jar -jnlpUrl http://machine1:8080/computer/machine1/slave-agent.jnlp

restorecon command: fixes the corrupted files in linux

SOme times some files may get corrupted and may shows errors as shown below: Cannot load /etc/httpd/modules/mod_jk.so into server: /etc/httpd/modules/mod_jk.so: failed to map segment from shared object: Permission denied The only and easiest way to solve this problem is to use the restorecon command Ex: [root@mulmu01-VM6783 httpd]# apachectl start Syntax error on line 4 of /etc/httpd/conf.d/tomcat.conf: Cannot load /etc/httpd/modules/mod_jk.so into server: /etc/httpd/modules/mod_jk.so: failed to map segment from shared object: Permission denied [root@mulmu01-VM6783 httpd]# restorecon -v /etc/httpd/modules/mod_jk.so restorecon reset context /usr/lib/httpd/modules/mod_jk.so:root:object_r:usr_t->system_u:object_r:httpd_modules_t [root@mulmu01-VM6783 httpd]# apachectl start [root@mulmu01-VM6783 httpd]#

Saturday, March 31, 2012

How to automate Email testing

If you are looking for a solution to automate the email testing i.e.. sending an email and verifying the reception, I prefer using WISER a dummy email server:

Wiser:


Wiser is a simple SMTP server that you can use for unit testing applications that send mail. It accepts all messages and stores them in an internal ArrayList. Your unit test code can then examine the messages (or lack thereof) and verify their validity.
WISER IS NOT A MAIL SERVER. If you want to receive email and then "do something" with the mail, simply implement the MessageHandler or MessageListener interfaces. Look at the (very short) Wiser code as an example.

How To Use It

Include the following jars on your classpath:
  • subethasmtp.jar
  • slf4j-api-X.X.X.jar
  • One of the slf4j connectors such as slf4j-simple-X.X.X.jar
  • JavaMail (mail.jar and activation.jar) 
Start the WISER server using below code. Now send the email from your application to the below address. Example: username@localhost.com.

Sample code:


package com.ca.example;

import org.junit.*;
import org.subethamail.wiser.Wiser;
import org.subethamail.wiser.WiserMessage;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
 public class WiserJUnitTest {

    private Wiser wiser;

    @Before
    public void setup() {
        wiser = new Wiser(2500);
        wiser.setHostname("localhost");
        wiser.setPort(2500);
        wiser.start();
        System.out.println("Wiser SMTP server started.");

    }

    @Test
    public void sendTest() throws Exception {
      
    /**
     * Creating and sending an email using Java Mail API
     */
        Properties props = new Properties();
        props.put("mail.smtp.host", "localhost");
        props.put("mail.smtp.port", "2500");
        props.put("mail.smtp.user", "username");
        props.put("mail.smtp.password", "password");

        Session session = Session.getInstance(props);
        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress("from@company.com"));
        message.setRecipients(Message.RecipientType.TO,
        InternetAddress.parse("to@company.com"));
        message.setSubject("Testing Subject");
        message.setText("This is just a test e-mail! ");
        message.setHeader("Organization", "company.com");
    
//        Transport.send(message);
        System.out.println("Done sending this email :" + message);
      
        System.out.println("Wiser messages count:"+wiser.getMessages().size());
        Assert.assertEquals("No mail messages found", 1, wiser.getMessages().size());

       if (wiser.getMessages().size() > 0) {
        WiserMessage wMsg = wiser.getMessages().get(0);
       
        MimeMessage msg = wMsg.getMimeMessage();
        System.out.println( msg.getSubject() );
        }

Good Luck!!!