Best way to execute selenium test on firefox browser

Hi Guys, I think you must be happy that you have completed your Selenium Webdriver Installation and now you are ready to execute selenium test on firefox browser. 

If you are new to Selenium and still have not completed installation part then no worry at all. Check below article which will help you with that- Install Selenium Webdriver in Windows Machine 

 

If Selenium 3 is getting used then must visit Selenium Firefox with GeckoDriver.

How to use Firefox in Selenium using geckodriver in Selenium 3

 

Before going to write our first Selenium Script, I would like to introduce some of the articles which will help you in the long run.Since you are new to Eclipse I will suggest you that you should know some of Eclipse Tips and Tricks.

Since we are going to use multiple browser and XPath very frequently throughout our learning process so you should have some plugin installed in your browser which generates XPath.

I found this awesome plugin which will generate multiple xpath even for Single Element, but the limitation of this plugin is that it works only with firefox.

Xpath plugin for Firefox browser. 

For another browser may be we have to wait but still in Chrome you will find one plugin which will detect the element based on xpath.

Xpath Checker for Chrome Browser

Now I think I have given so many different links which might confuse you so let’s get Started with first Selenium Webdriver.

I have created a video long back which will help you while designing Selenium Script so I will highly recommend you to watch this video.

It will hardly take 15 min but will give you clear picture that How we will be working once we move forward.

 

First Selenium Webdriver Script in Firefox

Now it is time to start Selenium webdriver scripting, till now we have downloaded all the required jars and plugin.

1-Open eclipse and create a new Java project as of now but once we will move forward we will be using Maven project which will give advance level functionality. 

If you want to give a try now itself it would be very good because in future we are going to use Maven project only. 

If You are working with Selenium 3 then this post is MUST

 

Below article will help you to work with maven and later on we will be integrating this withJenkins.

1- Check Maven Official site

2- Create Maven project and get Started.

But if you are getting confused now then take a deep breath and continue with below article 🙂

Here you will get project also but you can directly select Java project.

Selenium Script firefox

 

2- Enter project name depends on your requirement

Selenium Script firefox

 

3- Now you will get library section where you have to add jars, which we downloaded, earlier simply click on add external jars option

 

 

Selenium Script firefox

 

 

4- New window will open, browse your location and add all jars which we downloaded.

 

Selenium Script firefox

 

Note- If you add selenium-server-standalone- 2.X.X only then also you can write automation script

 

 

 

5-Now click on finish button

 

Selenium Script firefox

Now you can see your project listed in Project explorer

 

Selenium Script firefox

 

 

Execute selenium test on firefox browser

Step 1- Since we are working with Java so we need to create Java class.

 

Selenium Script firefox

Step 2- Please specify package name (lower case) and specify the class name and click on Finish button.

Note- you can check the public static void main checkbox so we can directly write webdriver script.

 

Selenium Script firefox

Step 3- Here will use WebDriver Interface and FireFoxDriver class

 

Note 1 :- WebDriver is an Interface(interface have only function prototype) in which by default all the method (public ,static)has to declare d.

2:- WebDriver handles all activity which is related to Browser.

 

Note 2: FireFoxDriver is a Class who has implemented all the method of WebDriver Interface.

Selenium Script firefox

Note- Eclipse comes with very good option that is same like google autosuggestion, if you use some keywords in Eclipse, it will show you the related keywords matches

 

Setup you shortcut preferences

1-  Click on Window and Click on Preferences option

 

Selenium Script firefox

2- General > keys> Search Content Assist> Bind your keys (in my case I set up Ctrl+Alt+Space by pressing respective key)> Click on Apply.

 

 

Selenium Script firefox

Type WebDriver and Press(Al+Ctrl+Space) so this will give you all the classes and interface which have WebDriver, so select WebDriver (Interface) and create a reference.

 

 

Selenium Script firefox

Step 4- Create webdriver reference

Selenium Script firefox

 

WebDriver driver=new FirefoxDriver();

Above code will initialize the firefox browser

 

Open any webpage for this we will use get methods which will accept url in String form followed by http:

Note- If you don’t provide http: in your application URL you will get some exceptions as well

Selenium Script firefox

Note:- Eclipse has this feature by default if you use Eclipse autosuggestion it will import all the necessary packages.

 

Selenium Script firefox

 

1-    To run the Program,

Right click on program and Run-As- Java-Application

 

 

execute selenium test on firefox browser

 

Now you will notice that Firefox will start and it will launch the application. If not then no worry drop a message below and I will help you.

Since we are done now it party time and now you can take rest.

Selenium Webdriver First Script with Firefox in Windows

 

But this is just a start so once you are done with party come back and let’s start with some topic.

Till now we have worked with Firefox but what about other browsers. In Automation you should make sure your Automation Script should run in all  browser so now I have a task for you.

Assignment for you- Run the same application with other browsers too like Chrome, IE, Opera, Safari and so on.

I have worked with Firefox, Chrome and IE only and I think that enough for most of the application.

I have written two more article which will help you to start with other browsers too.

This article will help you to launch for application in Chrome browser

Launch First Selenium Script in Chrome Browser

 

Once you are done with Chrome then stretch a little bit and try to run the same application in IE browser.

I don’t want to demotivate you but It is my responsibility here to tell you the facts about IE. Since IE browser is very much concerned about security you will find a couple of Issues with IE browser but again no worry  I have created a detailed article on it and very good news that you will face this question in Interviews as well.

Check below article which will help you to understand IE issues with Selenium.

Challenges with IE Browser while working with Selenium

 

 

Now you are familiar with IE issues and you must be ready now so without wasting much time let us start with IE Browser.

Launch First Selenium Script in IE Browser

Now you are done with all browser so now you must be having little bit confidence in Selenium so sit back relax.

Once you move forward you have to perform Cross Browser Testing as well but I will recommend then please don’t try this now because it includes so many high-level concepts like testng.xml.

But if you still want to see how it works then I would be happier.

 

Now its time to close this post and let’s move forward to another one. Since I have many topics in this post so you will definitely have some doubts so your doubts are always welcome.

 

If you really think this article will help others too then please share this with others too.

For More updates Learn Automation page

For any query join Selenium group- Selenium Group

 

30 Comments

  1. sid
  2. Rakhi Sharma
  3. Bharath B
  4. Phani
  5. Rachit Goyal
  6. sudhr
  7. kishore
  8. Kajal
  9. anusha
  10. Balaji
  11. sudhr
      • sudhr
  12. sudhr
  13. Sandip Parbatrao
  14. sandip

Leave a Reply