1

I am using Serenity BDD and I needed to Launch Firefox Browser with a custom profile bacause i wanted to store certs into that profile. So, i wont have any issue with Auth. However, I have added below codes to use custom Firefox Profile.

        String filePath = System.getProperty("user.dir")+"/firefoxprofile";
        Log.info("Firefox profile Path:"+ filePath);
        File firefoxProfileFolder = new File(filePath);
        FirefoxProfile firefoxProfile = new FirefoxProfile(firefoxProfileFolder);
        firefoxProfile.setAcceptUntrustedCertificates(true);
        Serenity.useFirefoxProfile(firefoxProfile); 
        Log.info("Using User profile: " + Serenity.getFirefoxProfile().getClass().getSimpleName());           
        loginPage.open();   

Serenity conf file i have added below:

webdriver.capabilities.acceptInsecureCerts=true

As well i have created a Firefox Profile where i added the root Directory to the Automation Repo "firefoxprofile" folder.

While i am executing the tests using maven command. Actually, Firefox is not using the custom profile. While it launches, I went to help > Troubleshoot > Verified the profile path which doesn't match with my provided path. How can i resolve this issue? Serenity needed to use Custom Profile which i have created.

ASM
  • 709
  • 2
  • 8
  • 27

2 Answers2

0

To ensure that Serenity BDD uses the custom Firefox profile you have created, you should try the following steps:

  1. Update the configuration file:

    • In your Serenity configuration file (usually serenity.properties or serenity.conf), add the following line:
      webdriver.driver = firefox
      
  2. Modify your code to set the Firefox profile:

    • In your code, after creating the Firefox profile, set the system property "webdriver.firefox.profile" to the name of your profile:
      String profileName = "your_profile_name"; // Replace with the name of your profile
      System.setProperty("webdriver.firefox.profile", profileName);
      
  3. Use the modified code to launch the Firefox browser:

    • Instead of Serenity.useFirefoxProfile(firefoxProfile), use the following code to launch the browser with the custom profile:
      WebDriver driver = new FirefoxDriver(firefoxProfile);
      Serenity.setWebDriver(driver);
      

Make sure that the Firefox profile you created is correctly configured with the desired settings and certificates.

I.sh.
  • 252
  • 3
  • 13
  • I am having this err at the last line: The method setWebDriver(WebDriver) is undefined for the type Serenity. No Luck yet – ASM May 31 '23 at 18:40
  • Still i am getting same err as earlier: No settings file exists, new profile?" (new NotFoundError("Could not open the file at /home/user/tmp/rust_mozprofile1IvrLe/search.json.mozlz4", (void 0))) – ASM May 31 '23 at 19:06
  • Did not work in this solution. – ASM Jun 05 '23 at 19:08
0

Mainly the FirefoxOptions are missing to configure the browser when creating the Firefox WebDriver instance. In this case it is required to configure the instance to use the custom profile.

See amendments below:

// Set the path to your custom Firefox profile directory
// Also note that it is using the File.separator to ensure 
// cross-platform compatibility.
String profilePath = System.getProperty("user.dir") + File.separator + "firefoxprofile";


// Use the setProfileDirectory() method to set the directory 
// of the custom profile for the FirefoxProfile class
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setProfileDirectory(new File(profilePath));
firefoxProfile.setAcceptUntrustedCertificates(true);


// Apply the custom profile on FirefoxOptions when creating 
// the Firefox WebDriver instance
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setProfile(firefoxprofile);


// Inform Serenity to use the provided (custom) firefoxProfile
// as the default Firefox profile to ensure that it is used by
// Serenity's WebDriver instance
Serenity.useFirefoxProfile(firefoxProfile);
Xavier Issac
  • 414
  • 1
  • 4
  • 25