Now a days almost all web applications have mobile applications and hence testers prefer to write test suits in one common place. We can setup selenium in Android Studio so that we can write and run our mobile application plus web application test suits at one place.The management and execution of test cases becomes very efficient.
If you agree with me and want to know how to setup Selenium in Android Studio then this blog post is for you. Please fallow the steps one by one and you will be able to complete your setup quickly.
Video Tutorial -
Pre-requisites -
2. Java
3. Set ANDROID_HOME and JAVA_HOME
Selenium WebDriver Setup in Android Studio -
1. Download Selenium Webdriver Java Client from This Link. Extract the folder and store all the jars in c:\seleniumjars\
2. Open your Andriod Studio and Click on Create new project
3. Enter Application Name and Click on Next
4. Then click on Next after selecting Minimum SDK version.
5. Select Blank Activity and click Next
6. Click on Finish.
7. Change project structure from Android to Project.
8. Copy the selenium jars to libs folder
9. Select all jars and right click -> click on Add as Library and let it complete the gradle sync successfully.
10. Go to app -> src -> main -> java . Then right click on the package and click on New -> Java class
Give the class name and click OK
11. Below is the basic selenium test case to open the website in the browser. Copy this code in your java class.
package com.selenium.tests; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class BrowserTests { public static void main(String[] args) throws Exception { WebDriver driver=new FirefoxDriver(); driver.get("http://qaautomated.blogspot.in"); Thread.sleep(3000); driver.quit(); } }
12. Click on Build Variants on the left side and change Test Artifacts to Unit Test and we are going to are going to write and run junit test.
13. Then right click on your javaclass and click on run.
You can see that Test Case launches firefox browser and opens the given link. Now you have sucessfully configured Android Studio with Selenium WebDriver and ran your first Test case.
In case if you have any questions or doubts do post in comments. I will try my level best to answer your queries.
Note - Learn More About Android Studio Functionality Usage HERE.











