Showing posts with label Selenium RC - code snippets. Show all posts
Showing posts with label Selenium RC - code snippets. Show all posts

Thursday, July 11, 2013

Assertions in Selenium



package com.softwaretesting_guru.help;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestCase;

@SuppressWarnings("deprecation")
public class Assertions extends SeleneseTestCase{

       @SuppressWarnings("deprecation")
       @Before
       public void setUp() throws Exception {
              //Starting the server
              SeleniumServer ss=new SeleniumServer();
              ss.start();
              selenium=new DefaultSelenium("localhost",4444,"firefox","http://www.gmail.com");
              selenium.start();
       }

       @After
       public void tearDown() throws Exception {
       }

       @SuppressWarnings("deprecation")
       @Test
       public void test() throws InterruptedException {
              selenium.open("/");
              selenium.waitForPageToLoad("70000");
              Thread.sleep(4000);
              selenium.windowMaximize();
              //Verifying the signin button
              assertTrue(selenium.isElementPresent("id=signIn"));
              //Click on the signin button
              //the below line will pause for 4000 seconds for each line from here
              selenium.setSpeed("4000");
             
              selenium.click("id=signIn");
              //Verifying the warning message displayed when username is not given.
              assertEquals("Enter your email address.",selenium.getText("id=errormsg_0_Email"));
              //Verifying whether the username control is present or not..
              assertTrue(selenium.isElementPresent("id=Email"));
              //Entering the username to username field
              selenium.type("id=Email","selenium");
              //verify whether entered username has been displayed or not by getting the username
              assertEquals("selenium",selenium.getValue("id=Email"));
              //Click on sigin button
              selenium.click("id=signIn");
              //Verifying the warning message displayed when password is not given.
              assertEquals("Enter your password.",selenium.getText("id=errormsg_0_Passwd"));
              //Verifying whether the password control is present or not..
              assertTrue(selenium.isElementPresent("id=Passwd"));
              //Entering the password to password field
              selenium.type("id=Passwd","selenium");
              //verify whether entered password has been displayed or not by getting the password
              assertEquals("selenium",selenium.getValue("id=Passwd"));
             
             
             
       }

      
       }



Monday, June 17, 2013

Selenium server start up problems: Failed to start: SocketListener0@0.0.0.0:4444

If the below appear while running the selenium scripts, Failed to start: SocketListener0@0.0.0.0:4444 you need to kill the process "javaw.exe" by going to the task manager If this is a routine case then you can write a reusable function and call it wherever required

Tuesday, April 23, 2013

Handling alert in Selenium RC


package com.softwaretesting_guru.help;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestCase;


public class AlertTest extends SeleneseTestCase {
      SeleniumServer ss;

      @Before
      public void setUp() throws Exception {
            // Start Selenium Server
            SeleniumServer ss = new SeleniumServer();
            ss.start();
            // Start Selenium
            selenium = new DefaultSelenium("localhost", 4444, "firefox",
                        "https://irctc.co.in");
            selenium.start();

      }

      @After
      public void tearDown() throws Exception {

      }

      @Test
      public void test() throws InterruptedException {
            // open the browser
            selenium.open("/");
            // maxmize the browser
            selenium.windowMaximize();
            // click on login button
            selenium.click("id=button");
            // expected result user should get alert using selenium verify alert and
            // handel the alert
            // verifying the alert
            if (selenium.isAlertPresent()) { // handel the alert
                  selenium.getAlert();
                  System.out.println("Alert Present");

            } else {
                  System.out.println("There is no alert present test case fail");
            }
            // enter username
            selenium.type("name=userName", "selenium");
            // enter password
            selenium.type("name=password", "selenium");

            Thread.sleep(5000);
            // getting the alert text use below code
            // Store the alert text
            String str = selenium.getAlert();
            // print alert text
            System.out.println(str);
            // compare the str text and alert text
            String alert = "Enter Value for  UserName";
            if (alert.equals(str)) {
                  // handel alert
                  System.out.println("Alert Present");

            } else {
                  System.out.println("There is no alert");
            }

            Thread.sleep(5000);
      }

}
 
By: Manoj Kumar

                                

AI in Software Testing: How Artificial Intelligence Is Transforming QA

For years, software testing has lived under pressure: more features, faster releases, fewer bugs, smaller teams. Traditional QA has done her...