Handling HTTP Modify Header Add on on Firefox in Selenium WebDriver(Adding SM_USER) - Bug Reaper

                  Bug Reaper

Lean about Automation Testing,Selenium WebDriver,RestAssured,Appium,Jenkins,JAVA,API Automation,TestNG,Maven, Rest API, SOAP API,Linux,Maven,Security Testing,Interview Questions

Friday 15 November 2013

Handling HTTP Modify Header Add on on Firefox in Selenium WebDriver(Adding SM_USER)

For Single Sign on Systems.
We Need to modify HTTP Header Request and Pass Id to SM_USER

The Handling of the Add on(Modify Header) on Firefox following code can be used:-

Constants File

public static WebDriver getWebDriver(Browser browser, Boolean prefMode) throws IOException {
if (browser == Browser.CHROME) {
return getChromeWebDriver();
} else if (browser == Browser.FIREFOX) {
return getFirefoxWebDriver(INDIVIDUAL_PORTAL_URL, prefMode);
}
return null;
}

private static WebDriver getFirefoxWebDriver(String portalURL, Boolean prefMode)// Boolean Pref mode to enable and disable firefox with and without Addon

WebDriver driver = null;
FirefoxProfile firefoxProfile = new FirefoxProfile(new File(FIREFOX_PROFILE_PATH));//Creation of new firefox profile
if(prefMode)// prefMode is set as Boolean 
{
try {
firefoxProfile.addExtension(new File("C:\\Users\\Neeraj.Bakhtani\\Desktop\\modify_headers-0.7.1.1-fx.xpi"));// Path of Modify Header xpi downloaded
   
} catch (IOException e) {
e.printStackTrace();
}
firefoxProfile.setPreference("modifyheaders.config.alwaysOn", true);
firefoxProfile.setPreference("modifyheaders.config.active", true);
firefoxProfile.setPreference("modifyheaders.headers.count", 1);
firefoxProfile.setPreference("modifyheaders.headers.action0", "Add");
firefoxProfile.setPreference("modifyheaders.headers.name0", "SM_USER");
firefoxProfile.setPreference("modifyheaders.headers.value0", ""+username1+"");//Pass Id to SM_USER
firefoxProfile.setPreference("modifyheaders.headers.enabled0", true);
driver = new FirefoxDriver(firefoxProfile);
} else {
driver = new FirefoxDriver();
}

We can also Set the Mode if we want to Run the Webdriver in Addon Mode or Without the addon





Main Class File


public class TestCase {
public WebDriver driver;

@Before
public void BeforeTest()throws IOException {  
driver = Constants.getWebDriver(Constants.Browser.FIREFOX, false);//For First Run we run without Addon i.e. false
}

Without Addon

driver.get(Constants.EMPLOYER_PORTAL_URL);// from Main class 'driver' object we run Firefox Webdriver without Addon

With Addon

driver = Constants.getWebDriver(Constants.Browser.FIREFOX, true);// From Constants file we use '
getWebDriver' function and set the mode as True to run with addon

No comments:

Post a Comment