When we start chrome browser using webdriver then by default it will load with out any extensions. But we can also load chrome browser with some default extensions if we need . To do this we need to know .crx file path of chrome extension. Here are the steps to find out the .crx file path :
1.Open chrome browser and type chrome://extensions/ . Now note down the extension id that you would like to be loaded when your browser starts.
2.Check the "Developer Mode" checkbox.Now you will see "Pack Extension" button .
3.Go to Extenstion folder of chrome .You will see the list of other folders with unique id's. Go to folder with the id , which you got in Step 1. Go deep into the folder until you find the manifest.json file and then copy the location .
3.Click on "Pack Extension" button and enter the path of folder in which extension manifest.json file is located.
4.We will get confirmation alert which displays the path of .crx file of extension. Copy that path and use it in your script
Thats it. Now we are done with the .crx file path . Use that path in the below code to load chrome browser with the default extension.
Referenes:
http://developer.chrome.com/extensions/packaging.html
http://www.chromium.org/user-experience/user-data-directory
1.Open chrome browser and type chrome://extensions/ . Now note down the extension id that you would like to be loaded when your browser starts.
2.Check the "Developer Mode" checkbox.Now you will see "Pack Extension" button .
3.Go to Extenstion folder of chrome .You will see the list of other folders with unique id's. Go to folder with the id , which you got in Step 1. Go deep into the folder until you find the manifest.json file and then copy the location .
3.Click on "Pack Extension" button and enter the path of folder in which extension manifest.json file is located.
Click on Pack Extension button.
Thats it. Now we are done with the .crx file path . Use that path in the below code to load chrome browser with the default extension.
import java.io.File; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.testng.annotations.Test; @Test public class Chrome { WebDriver driver; public void start(){ ChromeOptions options = new ChromeOptions(); options.addArguments("start-maximized"); options.addExtensions(new File("CRX FILE PATH")); System.setProperty("webdriver.chrome.driver","PATH of chromedriver.exe"); ChromeDriver driver = new ChromeDriver(options); driver.get("http://mythoughts.co.in"); } }
Referenes:
http://developer.chrome.com/extensions/packaging.html
http://www.chromium.org/user-experience/user-data-directory
No comments:
Post a Comment