Archive for August 22nd, 2013

Using *safari for Running our Tests on Safari Browser

Using *safari for Running our Tests on Safari Browser

After a lot of research I’ve found that only the following combination works for running our tests on Safari Browser:

Mac OS + Safari Browser -> This will work without any problems.
Windows 7 + Safari Browser -> This may run the tests but the final result will fail though the test executed without any fails. Hence not suggested.
What happened when I tried Running Selenium RC Tests on Windows 7 OS + Safari Browser:
1. I disabled the Pop-Up blocker in Safari Browser as  shown below:
2. Copied the Safari Folder path in C:/Program files as shown below:
3. Click on ‘Start’ Button, Right Click on the ‘Computer’ option in the start Menu and select ‘Properties’ option as shown below:
4. Click on ‘Advanced System Settings’ option and ensure that the ‘System Properties’ dialog is displayed.  In the ‘Advanced’ tab of ‘System Properties’ dialog select ‘Environment Variables’ button as shown below:
5. Ensure that ‘Environment Variables’ sub dialog is displayed, select the Path variable and click on ‘Edit’ button as shown below:
6. Ensure ‘Edit User Variable’ sub dialog is displayed and add a semi colon at the end of the existing statements followed by pasting the above copied path in step 2 into the Variable Value field and click on ‘OK’ button as shown below:
7.  Click on ‘OK’ buttons on the remaining ‘Environment Variables’ and ‘System Properties’ dialog.
8.  In Eclipse IDE, I’ve replaced *iexplore with *safari and Ran the Selenium RC Test using JUnit Test option. Unfortunately the Test didn’t Run.
9. So I have then replaced *safari with *safariproxy as shown below:
 10. Start the Selenium Standalone Server
11. Run the Test using JUnit Test option and observe that the Test Ran this Time in Safari.
12. Though the Selenium Test executed successfully, the Test has resulted as Fail though there are no failures as shown below (i.e. com.thoughtworks.selenium.SeleniumException: ‘undefined’ is not an object is displayed as error )
 Watch the below video:

Click here to watch the video.

Download this Project:

Click here to download this project and import into Eclipse IDE  on your machine.

NOTE : After lots of research activity its found that Running Selenium RC Tests on Safari Browser of MAC OS X machine will work without any errors. I am not going to explain this practically on MAC machine. Please try yourself.

Using *iexplore for running the Selenium RC Automation tests on Internet Explorer Browser

Using *iexplore for running the Selenium RC Automation tests on Internet Explorer Browser

*iexplore is used to run the Selenium RC Automation Tests on Google Chrome Browser.

Lets Implement This:

1. Replace *firefox with *iexplore in the project explained in our previous post as shown below:

2. Start the Selenium Standalone Server
3. Save and Run the ‘Class15.java’ file by selecting the ‘JUnit Test’ option
4. Observe that the following Script Error is displayed as shown below:

5. We got this Script Error as we are not running the Eclipse IDE in Administrator mode. How to resolve this Script error and Run the Selenium RC Automation Test on Internet Explorer will be explained in the  next steps. In order to run the Eclipse IDE in Administrator mode please follow the below steps.
6. Close the Eclipse IDE by clicking on ‘X’ button as shown below:

7. Ensure that the Eclipse IDE is closed and open the Folder where you have downloaded the Eclipse IDE as shown below:

8. Right click on the ‘eclipse.exe’ file and select ‘Run As Administrator’ option as shown below:

9. Click  ‘Yes’ button if the User Account Control dialog asking the User “Do you want to allow the following program …”  is displayed as shown below:

10. Click ‘Ok’ on the ‘Workspace Launcher’ dialog as shown below:

11. Ensure that the Eclipse IDE is now launched (i.e. in Administrator mode this time).
12. Start the Selenium Standalone Server
13. Save and Run the ‘Class15.java’ file by selecting the ‘JUnit Test’ option and observe that the Test is Run in Internet Explorer without any Script errors this time as shown below:


Watch the below video:

Click here to watch the video.

Download this Project:

 Click here to download this project and import into Eclipse IDE  on your machine.

Using *googlechrome for running the Selenium RC Automation Tests on Google Chrome Browser

Using *googlechrome for running the Selenium RC Automation Tests on Google Chrome Browser

*googlechrome is used to run the Selenium RC Automation Tests on Google Chrome Browser.

Lets Implement This:

1. Replace *firefox with *googlechrome in the project explained in our previous post as shown below:

2. Start the Selenium Standalone Server
3. Save and Run the ‘Class15.java’ file by selecting the ‘JUnit Test’ option and ensure that Selenium RC Automation Test is Run in Chrome Browser as shown below:

Watch the below video:

Click here to watch the video.

Download this Project:

Click here to download this project and import into Eclipse IDE  on your machine.

Using *firefox for running Selenium RC Automation Tests on Firefox Browser

Using *firefox for running Selenium RC Automation Tests on Firefox Browser

Pre-requisites:  Go through “Ensure Compatible Firefox Browser is Installed”

*firefox is used to run the Selenium RC Automation Tests on Firefox Browser.

Lets Implement This:

Pre-requisites:

1. Create a new Project say ‘RC-Project15’ in Eclipse IDE
2. Configure the Project to work with Selenium RC
3. Configure the Selenium Standalone Server to run from Eclipse IDE
4. Start the Selenium Standalone Server
5. Create a package say ‘package_Fifteen’ under the newly created project.
6. Create a Java Class file say ‘Class15’ under the newly created package as shown below:


Actual Steps:

1. Write the following code into the newly created Java Class file as shown below and make sure that you resolve all the errors before going to next step:

2. Start the Selenium Standalone Server
3. Save and Run the ‘Class15.java’ file by selecting the ‘JUnit Test’ option and ensure that Selenium RC Automation Test is Run in Firefox Browser as shown below:

Watch the below video:

Click here to watch the video.

Download this Project:

 Click here to download this project and import into Eclipse IDE  on your machine.

Writing Selenium RC Test on our own

Writing Selenium RC Test on our own

Earlier in order to create a JUnit Selenium RC Test, we have performed the following steps:
  1. Recorded a Test Scenario using Selenium IDE
  2. Copied the Selenium  RC code generated by the Selenium IDE
  3. Pasted the code into the Eclipse IDE
  4. Resolved few errors and warnings
  5. Run the Selenium RC test using JUnit in Eclipse IDE
Please refer to “Create a JUnit Selenium RC Test using Selenium IDE”
But how not to use Selenium IDE and write Selenium RC Test on our own. In order to understand how to write Selenium RC Tests on our own, we’ve to start writing the code from Scratch.
Writing Selenium RC Tests on our own (i.e. without using Selenium IDE )
Please follow the below steps:
1. Create a Java Project named “Selenium143” in Eclipse IDE as shown below:
2. Configure the above created Project “Selenium143” to work with Selenium RC ( Please refer to Configure Projects in Eclipse IDE to work with Selenium RC)3. Create a Package named “home_page” under the “Selenium143” project as shown below:
4. Create a Java Class named “OpenURL” under the “home_page” package as shown below:
5. Inside the “OpenURL” class, create a method named “openSelenium143” as shown below:

6. Specify  the “openSelenium143” method with @Test annotation as shown below and ensure that an error is displayed:

7. In order to resolve this error, hover your mouse cursor on this error and select ” Import Test (org.junit) ” option as shown below:

8. Ensure that the import org.junit.Test; import statement got added and the error got resolved on import as shown below:

Note: We are importing a predefined class “Test” from “org.junit” package into our “Selenium143” Class. i.e. The functionality of the @Test annotation is predefined in Test Class as part of JUnit framework.

9. As we already know that Selenium RC server  executes our Selenium RC tests on the specified browser,   we’ve to create a Selenium object in our Selenium RC tests to communicate or connect with Selenium RC Server as shown below:

10. After looking at the above screenshot, its very clear that we have an error displayed on adding Selenium object creation statement. Hover your mouse cursor over this error message and select “Import Selenium (com.thoughtworks.selenium) ” option as shown below to resolve the error:

Note: We are importing a predefined class “Selenium” from “com.thoughtworks.selenium” package into our “Selenium143” Class. i.e. We can now use the Selenium Class in our “Selenium143” Class for creating objects and performing operations on the created object.

11. Ensure that the Selenium error got resolved after adding the selected import statement as shown below:

12. But if you have observed correctly , we’ve one more error displayed for ‘DefaultSelenium’ in the above screenshot unresolved. Hover your mouse cover over this error and select “Import DefaultSelenium (com.thoughtworks.selenium) ” option as shown below to resolve this error:

Note: We are importing a predefined class “DefaultSelenium” from “com.thoughtworks.selenium” package into our “Selenium143” Class. i.e. We can now use the DefaultSelenium Class functionality in our “Selenium143” Class.

13. Ensure that the selected import statement got added and also the error got resolved as shown below:

14. Before going to the next steps, lets understand the below statement:

Selenium object1 = new DefaultSelenium(“localhost”, 4444, “*firefox”, “http://selenium143.blogspot.com”);

  1. Selenium is a predefined Class
  2. object1 is the object name I have given. In this example object1 is an object of Selenium Class.
  3. new is the java keyword used to create an object for the specified class (i.e. object1 object for Selenium class in this example)
  4. DefaultSelenium( ) is a predefined constructor calling statement.
  5. localhost is the first parameter which gets passed to the DefaulSelenium( ) predefined constructor. This argument is specified as localhost as I’m going to run the Selenium RC test in the same system where I’m writing this code. If you want to run the written Selenium RC test on a different machine, you have to mention the IP Address of the machine on which you want to run this test.
  6. 4444 is the default communication TCP/IP protocol. If you have specified any other protocol say 8888 while starting the Selenium Standalone Server then you have to use 8888 instead of 4444, else if you have not specified any protocol to start the Selenium Standalone Server then you will be using 4444 as this is the default communication protocol. (i.e. If you don’t provide any protocol while starting the Selenium Standalone Server, it will take the default protocol i.e. 4444)
  7. *firefox is the parameter which tells the Selenium Server which browser to use. As we have mentioned it as *firefox it will use Firefox browser to run the Selenium Test. For chrome and IE browsers we have to specify *googlechrome  and *iexplore respectively.
  8. http://selenium143.blogspot.com is the last paramater, which specifies the base URL of the site we are testing.
We can also break the above single statement into two separate statements as shown below:
Selenium object1;    // Declaring the object1 as an instance object of Selenium Class
 
object1 = new DefaultSelenium(“localhost”, 4444, “*firefox”, “http://selenium143.blogspot.com”);   // Assigning the reference to the object1 and calling the DefaultSelenium( ) constructor while the object is getting created.
15. Lets add few more statements inside the openSelenium143( ) method, which uses the ‘object1’ object created by the first statement to 1) starts the Selenium Server Driver in a new Firefox Browser session, 2) open the home page of the base URL specified in the first statement, 3) close the test application and 4) finally to close the Firefox Browser session.
16. First lets start the new Firefox Browser session. Type object1 followed by dot i.e ‘.’ and wait for the selenium commands to appear as shown below:
17. While the selenium commands box is open, type ‘st’ letters and observe that the selenium commands got filtered to four commands from many commands as shown below:

18. Select ‘start( )’ command from the filtered commands as shown below:

19. Ensure that the selected command got added to the code and add a ‘;’ to end the statement as shown below:

20. Save the Selenium RC Test and Run the Test using JUnit as shown below:

21. Ensure that the Test got failed as shown below as we’ve not started the Selenium Standalone Server before running the test using JUnit:

22. Start the Selenium Standalone Server as explained in Start the Selenium Standalone Server and Run the test using JUnit as shown below:

23. Observe that the Firefox has started the  Selenium Server driver as shown below and also observe that the Test got Passed :

24. As we’ve seen in the above steps that object1.start( ); selenium command has opened  Selenium Server Driver which actually Runs the selenium Automation tests in a new Firefox Browser Session, now lets see the   next command which opens the URL of  our Application i.e. object1.open(“http://www.selenium143.blogspot.com”); as shown below:

25. Save and Run the Test using JUnit and observe that the specified URL got opened in Firefox Browser as shown below:

26. Lets write the next command object1.windowMaxmize( ); to maximize the opened Browser as shown below:

27. Save and Run the Test using JUnit and observe that the specified URL got opened in Firefox Browser and the Firefox Browser got maximized as shown below:

28. Lets write the next command object1.close( ); which closes the open Browser having our Application URL as shown below:

29. Save and Run the Test using JUnit and observe that the following Browser Window having the specified URL gets closed as shown below:

30. Lets write the next command object1.stop( ); to stop  the Selenium Server Driver as shown below:

31. Save and Run the Test using JUnit and observe that the Firefox Browser Window which has Selenium Server Driver running gets closed as shown below:

32. As I explained the commands step by step, it will be more clear for you if you can watch the following video of what we have done till the previous step:

Click here to watch the video

33. The selenium commands explained in this post will be used in my next upcoming posts also. So please remember the above commands.

In this post we’ve only used @Test JUnit annotation. We can actually categorize the Selenium Commands used in this post to fall under different JUnit annotations i.e. @Before @Test @After Annotations.

Download this Project:

Click here to download the project used in this post and import into Eclipse IDE on your machine.

%d bloggers like this: