Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameters of nested test suites are overriden #581

Closed
chillinPanda opened this issue Dec 18, 2014 · 3 comments · Fixed by #2923 or testng-team/testng-team.github.io#46
Closed

Parameters of nested test suites are overriden #581

chillinPanda opened this issue Dec 18, 2014 · 3 comments · Fixed by #2923 or testng-team/testng-team.github.io#46
Labels
Milestone

Comments

@chillinPanda
Copy link

Github Demo Project with bug

I wrote a little demo project to show you this problem and that you can play and interact with it. There are also more information on the readme.md.
Check out https://github.com/chillinPanda/testng-parameter-error

Problem

If I nest two test suites into one and use parameter in the nested suite-file definition, those are overriden by following same-name-parameters. In the following example "www.wikipedia.org" will be overriden to "www.google.com" and then the tests at src/test/testng_xmls/testng_wiki.xml get a wrong parameter (the one from below)

<suite name="Demo" parallel="tests">
  <suite-files>

    <suite-file path="src/test/testng_xmls/testng_wiki.xml">
      <parameter name="url" value="www.wikipedia.org" />
    </suite-file>

    <suite-file path="src/test/testng_xmls/testng_google.xml">
      <parameter name="url" value="www.google.com" />
    </suite-file>

  </suite-files>
</suite>
@chillinPanda chillinPanda changed the title Parameters of nested test suites is overriden Parameters of nested test suites are overriden Dec 18, 2014
@chillinPanda
Copy link
Author

I am looking through the testng source and perhaps this is the problem:

Class: XmlSuite.java

this is in the git repo:

  /**
   * @return The parameters defined in this suite and all its XmlTests.
   */
  public Map<String, String> getAllParameters() {
    Map<String, String> result = Maps.newHashMap();
    for (Map.Entry<String, String> entry : m_parameters.entrySet()) {
      result.put(entry.getKey(), entry.getValue());
    }

    for (XmlTest test : getTests()) {
      Map<String, String> tp = test.getLocalParameters();
      for (Map.Entry<String, String> entry : tp.entrySet()) {
        result.put(entry.getKey(), entry.getValue());
      }
    }

    return result;
  }

I did not have the time to test it. But perhaps something like this would resolve the problem:

  /**
   * @return The parameters defined in this suite and all its XmlTests.
   */
  public Map<String, String> getAllParameters() {
    Map<String, String> result = Maps.newHashMap();
    for (Map.Entry<String, String> entry : m_parameters.entrySet()) {
      result.put(entry.getKey(), entry.getValue());
    }

    for (XmlTest test : getTests()) {
      Map<String, String> tp = test.getLocalParameters();
      for (Map.Entry<String, String> entry : tp.entrySet()) {

        // check if key already exists and use priority. local test keys are more important
        if (result.containsKey(entry.getKey())) {
          // assumption for next if statement: this determines that the currently running test is the test we iterate through and test names are distinct.
          if (test.getName().equals(getTest())) { 
            result.put(entry.getKey(), entry.getValue());
          }
        }

      }
    }

    return result;
  }

@krmahadevan krmahadevan added this to the 7.9.0 milestone Jun 7, 2023
krmahadevan added a commit to krmahadevan/testng that referenced this issue Jun 7, 2023
Closes testng-team#581

TestNG does not have any logic that would
honour parameter tags specified within suite-files
tag. But due to a parsing bug, we end up reading
parameters that were specified within
`<suite-file>` tag.
This tag by definition is NOT meant to have any
child tags inside of it.

Fixed this discrepancy by adding a warning when
this anomaly is detected and skipping of reading
the `<parameter>` tag inside it as if it were
specified within `<suite>` tag.
@krmahadevan
Copy link
Member

<parameter> is not supposed to be passed from within the <suite-file>. But there's a parsing bug in TestNG owing to which TestNG ends up reading the parameter (which it should never have).

That has been fixed as part of this PR #2923

krmahadevan added a commit to krmahadevan/testng that referenced this issue Jun 7, 2023
Closes testng-team#581

TestNG does not have any logic that would
honour parameter tags specified within suite-files
tag. But due to a parsing bug, we end up reading
parameters that were specified within
`<suite-file>` tag.
This tag by definition is NOT meant to have any
child tags inside of it.

Fixed this discrepancy by adding a warning when
this anomaly is detected and skipping of reading
the `<parameter>` tag inside it as if it were
specified within `<suite>` tag.
krmahadevan added a commit to krmahadevan/testng-team.github.io that referenced this issue Jun 7, 2023
krmahadevan added a commit to krmahadevan/testng that referenced this issue Jun 7, 2023
Closes testng-team#581

TestNG does not have any logic that would
honour parameter tags specified within suite-files
tag. But due to a parsing bug, we end up reading
parameters that were specified within
`<suite-file>` tag.
This tag by definition is NOT meant to have any
child tags inside of it.

Fixed this discrepancy by adding a warning when
this anomaly is detected and skipping of reading
the `<parameter>` tag inside it as if it were
specified within `<suite>` tag.
krmahadevan added a commit to krmahadevan/testng that referenced this issue Jun 7, 2023
Closes testng-team#581

TestNG does not have any logic that would
honour parameter tags specified within suite-files
tag. But due to a parsing bug, we end up reading
parameters that were specified within
`<suite-file>` tag.
This tag by definition is NOT meant to have any
child tags inside of it.

Fixed this discrepancy by adding a warning when
this anomaly is detected and skipping of reading
the `<parameter>` tag inside it as if it were
specified within `<suite>` tag.
krmahadevan added a commit to krmahadevan/testng-team.github.io that referenced this issue Jun 7, 2023
krmahadevan added a commit to krmahadevan/testng that referenced this issue Jun 7, 2023
Closes testng-team#581

TestNG does not have any logic that would
honour parameter tags specified within suite-files
tag. But due to a parsing bug, we end up reading
parameters that were specified within
`<suite-file>` tag.
This tag by definition is NOT meant to have any
child tags inside of it.

Fixed this discrepancy by adding a warning when
this anomaly is detected and skipping of reading
the `<parameter>` tag inside it as if it were
specified within `<suite>` tag.
krmahadevan added a commit that referenced this issue Jun 8, 2023
Closes #581

TestNG does not have any logic that would
honour parameter tags specified within suite-files
tag. But due to a parsing bug, we end up reading
parameters that were specified within
`<suite-file>` tag.
This tag by definition is NOT meant to have any
child tags inside of it.

Fixed this discrepancy by adding a warning when
this anomaly is detected and skipping of reading
the `<parameter>` tag inside it as if it were
specified within `<suite>` tag.
@krmahadevan
Copy link
Member

Also we have tightened the dtd file via testng-team/testng-team.github.io#46 and released a new version of it at http://testng.org/testng-1.1.dtd

We have also enriched the codebase to now refer to the tighthened DTD testng-1.1.dtd as an embedded DTD within the TestNG codebase as part of the PR #2923

@krmahadevan krmahadevan added the xml label Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants