Menu

custom plugin: conf values are lost

Help
2007-04-03
2013-04-25
  • Sannie Kwakman

    Sannie Kwakman - 2007-04-03

    I'm currently trying to build a custom plug-in for Jameleon, in which database entries are backed up and rolled back before and after a certain test is executed. This is done through the usage of a <dataprepare> tag, in which all the actual test actions are placed.

    In order to make this tag function I've created a dataprepare plugin which uses both global configuration options (set by either jameleon.conf or the Configurator class) and tag-specific options. Both types of configuration values are correctly read and the plugin executes normally... except when running multiple tests after each other using <test-suite>. The first test within a <test-suite> executes fine but when the second one starts, the custom plugin seems to have lost all its global configuration values that were passed through the Configurator prior to running the <test-suite>. However, the values given at the tag level (by using <dataprepare setting="value"> for example) will still be set correctly.

    Configuration entries are read by the plug-in by using the @attribute comment annotation method, which used in the Selenium plugin. Here's an example:

    /**
    * @jameleon.attribute contextName="dataprepare-setting" default=""
    */
    protected String setting = new String("");

    As far as I know, the method above is used for tag-level value passing. I've seen the Selenium plugin use the following construct as well:

    ContextHelper.getValueAsBooleanWithConfig(context, "dataprepare-setting", "dataprepare-setting", setting);

    Both methods return an empty value when using a second test within a <test-suite>. Even retrieving the .conf value using the Configurator will return an empty value in this situation:

    Configurator configurator = Configurator.getInstance();
    configurator.getValue("dataprepare-setting");

    So my question is, how can I reliably retrieve global configuration settings when running multiple tests within a <test-suite> ? Is the above described behaviour a bug or am I doing something wrong?

     
    • Christian Hargraves

      context variables are not stored in jameleon.conf. The:

      /**
      * @jameleon.attribute contextName="dataprepare-setting" default=""
      */

      only binds instance variables with context variables.

      You shouldn't be changing values of the jameleon.conf file at runtime since that Singleton gets refreshed between every test execution.

      Please post an actual example of what you are trying to do.

       
    • Sannie Kwakman

      Sannie Kwakman - 2007-04-05

      example in it's simplest form:

      I've created a plugin, of which SessionTag class reads a global configuration value:

      public String getUsername() {
              return Configurator.getInstance().getValue("dataprepare-username");
          }

      This configuration entry is set in jameleon.conf.

      In the setupSession() method of the plug-in, the value is read:
      public void setUpSession(){
              System.out.println("dataprepare username: "+getUsername());
      }

      Then I run two tests, combined by <test-suite> :

      <?xml version="1.0" encoding="UTF-8"?>
      <test-suite xmlns="jelly:jameleon"
          xmlns:xhtml="http://www.w3.org/1999/xhtml">
          <test-script script="tests/dptest1.xml" />
          <test-script script="tests/dptest1.xml" />
      </test-suite>

      dptest1.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE testcase
        SYSTEM "testframework_entities.dtd">
      <testcase xmlns="jelly:jameleon"
          xmlns:xhtml="http://www.w3.org/1999/xhtml"
          trace="true"
          name="dptest1" csvDir="tests/">
          <test-case-summary />
          <test-case-level>ACCEPTANCE</test-case-level>
          <selenium-session browser="*chrome" beginAt=""
              baseUrl="http://localhost:8080/" beginSession="true"
              startSeleniumProxy="true" slowResourcesMode="false">
              <csv xmlns="jelly:jameleon" xmlns:xhtml="http://www.w3.org/1999/xhtml" countRow="true"  stopTestExecutionOnFailure="false" csvFileName="dptest1.csv" csvValueSeparator=";" csvDir="tests/">
                  <data-prepare tables="BACKUPTABLE">
                      <selenium-open url="http://localhost:8080/" functionId="dptest1 "/>
                  </data-prepare>
              </csv>
          </selenium-session>
      </testcase>

      When the first test in the <test-suite> is ran, the data-prepare tag returns the username. The second time, it returns null. The dataprepare plugin only reads the configuration entry, no write actions.

      I'm inclined to think that all global configuration entries are wiped when running a second test within a <test-suite>. I haven't been able to locate the offending piece of code that is responsible for this.. or is there something else going on?

       
    • Sannie Kwakman

      Sannie Kwakman - 2007-04-06

      Did some more digging and found a call to Configurator.clearInstance() in tearDown() of net.sf.jameleon.TestCaseTag. This call wipes clean all values of Configurator after the execution of a testcase. When I remove this call, the problems mentioned above are gone. Should I submit a bug + patch again or will the removal of this call break other functionality?

       
      • Christian Hargraves

        I'm sorry I have been putting in some crazy hours at work and I haven't had the time to look into this.

        I know the clearInstance in there for a reason. Oh yeah, there is a way to set the configuration file to use via
        the actual script. If we cached this between scripts, then the new configuration would not get read in.

         
        • Sannie Kwakman

          Sannie Kwakman - 2007-04-10

          I couldn't find a tag or attribute that defines a custom configuration file in the documentation.. if this isn't defined in the testcasetag, shouldn't the clearInstance() method be called in the relevant tag instead of testcase? This way clearInstance() can be called only when necessary, which helps prevent unwanted configuration-wipes.

           
          • Christian Hargraves

            The attribute is called 'jameleonConfigName'.

            However, I only see one place where it is used. I implemented that feature to make it a little easier to write acceptance tests against Jameleon. I will look into it to see any if any problems might arise from making your suggested change. Follow-up on me in a few days if you don't hear anything back.

             

Log in to post a comment.