Set firefox profile with annotation or in pom.xml

228 views
Skip to first unread message

Radostina Radi

unread,
Aug 30, 2017, 12:11:02 PM8/30/17
to Selenium Users
Hello,

Is there a way to set firefox profile with annotation or in pom.xml? I tried adding this to pom.xml :
<webdriver.firefox.profile>C:\Users\radost\AppData\Roaming\Mozilla\Firefox\Profiles\myprofile.radost</webdriver.firefox.profile>
But it's not working.
I am adding webdriver with :
@Managed
WebDriver browser;

Does anyone know I way to solve this? Thank you.
Message has been deleted

Krishnan Mahadevan

unread,
Aug 30, 2017, 12:40:58 PM8/30/17
to seleniu...@googlegroups.com

 

You don’t need any annotation for this. Relying on an annotation driven approach complicates things, because it’s not easy to alter an annotation’s value.

Annotation’s are meant to represent meta data that can be read by the code, and not essentially altered during runtime by your java code.

 

The only advantage of resorting to using annotations is being able to control on the application of a Firefox profile on a per use case basis. But then again, if it needs to be altered, you would have to fall back to a JVM argument way of doing it.

 

If you are interested, you can take a look at this blog post of mine to learn how to change annotation values at runtime.

 

https://rationaleemotions.wordpress.com/2016/05/27/changing-annotation-values-at-runtime/

 

You can instead rely on JVM arguments for this. Here’s a sample that shows how to do this:

 

import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.remote.RemoteWebDriver;

public class DynamicFirefoxProfile {
   
public static void main(String[] args) {
        RemoteWebDriver driver =
null;
        ProfilesIni profilesIni =
new ProfilesIni();
       
//Pass a new value via the JVM argument -Dprofile
       //For e.g., to load a profile named "selenium" use -Dprofile=selenium
       
String profileName = System.getProperty("profile", "IdontExist");
        FirefoxProfile profile = profilesIni.getProfile(profileName);
        FirefoxOptions options =
new FirefoxOptions();
       
if (profile != null) {
            options.setProfile(profile);
        }
       
try {
            driver =
new FirefoxDriver(options);
            driver.get(
"http://www.google.com");
        }
finally {
           
if (driver != null) {
                driver.quit();
            }
        }
    }
}

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/148af861-d2fa-4b0a-8fa1-59da1ca8c682%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Radostina Radi

unread,
Aug 31, 2017, 5:51:40 AM8/31/17
to Selenium Users
Hello Krishnan,

Thank you very much for your reply. Unfortunately I still can't make it work, getting net.thucydides.core.webdriver.UnsupportedDriverException: Could not instantiate class org.openqa.selenium.firefox.FirefoxDriver.
I am using selenium-firefox-driver-2.53.1 and Firefox version is 52.3.0 (64-bit). are these two not matching? thank you very much.

⇜Krishnan Mahadevan⇝

unread,
Aug 31, 2017, 6:46:09 AM8/31/17
to Selenium Users
Can you please add a bit more context to your problem ?

Perhaps show some code that you are using, along with the Maven dependencies with which you are working ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/05827987-f22f-446e-b3da-114ee890ef85%40googlegroups.com.

Radostina Radi

unread,
Aug 31, 2017, 6:58:28 AM8/31/17
to Selenium Users
Yes. So I am working in a governmental organization and I need to use my profile created in firefox to perform the tests. Usually every time I open firefox I need to authenticate with user and pass.
so, I am using selenium 3.3.1 now (upgraded since the previous email I wrote) and firefox 52.3.0 (64-bit).

I am writing a Unit test, runing it with @RunWith(SerenityRunner.class) .This is how I am trying to open FF:

RemoteWebDriver driver = null;
        ProfilesIni profilesIni = new ProfilesIni();
        
        FirefoxProfile profile = profilesIni.getProfile("MyProfile");
        FirefoxOptions options = new FirefoxOptions();
        if (profile != null) {
            options.setProfile(profile);
            options.setBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
            options.addPreference("log", "{level: trace}");
        }
        try {
       
        DesiredCapabilities capabilities = DesiredCapabilities.firefox();
        capabilities.setCapability("marionette", true);
        capabilities.setCapability("moz:firefoxOptions", options);
       
            driver = new FirefoxDriver(capabilities);
            driver.get("http://mysite/mysite");
        } finally {
            if (driver != null) {
                driver.quit();
            }
        }

My pom.xml:

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<serenity.version>1.1.42</serenity.version>
<serenity.maven.version>1.1.34</serenity.maven.version>
<webdriver.driver>firefox</webdriver.driver>
</properties>

<!-- Define the Bintray repos for convenience -->
<repositories>
<repository>
<id>serenity</id>
<name>bintray</name>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>serenity</id>
<name>bintray-plugins</name>
</pluginRepository>
</pluginRepositories>

<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>${serenity.version}</version>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-junit</artifactId>
<version>${serenity.version}</version>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-rest-assured</artifactId>
<version>${serenity.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.lambdaj</groupId>
<artifactId>lambdaj</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<parallel>classes</parallel>
<threadCount>5</threadCount>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<includes>
<include>**/When*.java</include>
</includes>
<parallel>methods</parallel>
<threadCount>2</threadCount>
<reuseForks>true</reuseForks>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
<systemPropertyVariables>
<tags>${tags}</tags>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.maven.version}</version>
<dependencies>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>1.1.25-rc.3</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>serenity-reports</id>
<phase>post-integration-test</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

I have also set the path to gecko driver in jvm arguments: webdriver.gecko.driver="C:\work\cfg\functional-testing\tests\drivers\geckodriver.exe"

And the error I am getting currently:

org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. 
desired capabilities = Capabilities [{firefox_binary=/Program Files/Mozilla Firefox/firefox.exe, moz:firefoxOptions={binary=Optional[FirefoxBinary(C:\Program Files\Mozilla Firefox\firefox.exe)], 
args=[], legacy=null, logLevel=null, prefs={}, profile=org.openqa.selenium.firefox.FirefoxProfile@6f44a157}, firefox_profile=org.openqa.selenium.firefox.FirefoxProfile@6f44a157}], 
required capabilities = Capabilities [{firefox_binary=/Program Files/Mozilla Firefox/firefox.exe, moz:firefoxOptions={binary=Optional[FirefoxBinary(C:\Program Files\Mozilla Firefox\firefox.exe)], 
args=[], legacy=null, logLevel=null, prefs={}, profile=org.openqa.selenium.firefox.FirefoxProfile@6f44a157}, firefox_profile=org.openqa.selenium.firefox.FirefoxProfile@6f44a157}]

Build info: version: '3.3.1', revision: '5234b325d5', time: '2017-03-10 09:10:29 +0000'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_77'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:218)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)
at ec.digit.essnex.serenity.search.WhenUsingEssnexSearch.performSimpleSearch(WhenUsingEssnexSearch.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at net.serenitybdd.junit.runners.SerenityStatement.evaluate(SerenityStatement.java:24)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at net.serenitybdd.junit.runners.SerenityRunner.runChild(SerenityRunner.java:427)
at net.serenitybdd.junit.runners.SerenityRunner.runChild(SerenityRunner.java:52)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at net.serenitybdd.junit.runners.SerenityRunner.run(SerenityRunner.java:241)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)


Thank you very much for your help.
Radostina

Radostina Radi

unread,
Aug 31, 2017, 10:08:16 AM8/31/17
to Selenium Users
Hello again,

I have solved this. It was a mixture of wrong dependencies. I am setting up for the first time this environment. Thanks for help.

Best regards,
Radostina
Reply all
Reply to author
Forward
0 new messages