Forum Discussion

em_qdx's avatar
em_qdx
Occasional Contributor
3 years ago

Multiple data sources in sequence

Question: Is it possible to run multiple Data Sources in sequence in one test case, and use a value from the current iteration from the first Data Source result set that runs earlier in sequence to retrieve records from a second Data Source that runs later in the sequence using a single, matching value?

I have attempted to do this but the functional test always fails.
1. These two Data Sources are currently the only two steps in this functional process.
2. It seems as if the second Data Source is using not only data from the current record/iteration from the first Data Source, but rather trying to run the select query in the second Data Source using the entire result set from the first Data Source.  I assumed the second Data Source would only use values from the current record/iteration from the first Data Source.
3. I am directly referencing the key value field Property from the first Data Source in the select query in the second Data Source as part of the "Where" clause.
4. There is currently only one entry in each table and the key values in each record are the same value.

Query:
Data Source 1:
Select AutomationTest.AutomationTestId As AutomationTest_AutomationTestId,
AutomationTest.TestName As AutomationTest_TestName
From AutomationTest

Data Source: AutomationTest_Select
Property: AutomationTest_AutomationTestId

DataSource 2:
Select AutomationTestInput.AutomationTestInputId As AutomationTestInput_AutomationTestInputId,
AutomationTestInput.AutomationTestId As AutomationTestInput_AutomationTestId,
AutomationTestInput.InputModel As AutomationTestInput_InputModel,
From AutomationTestInput
Where AutomationTestInput.AutomationTestId = ${AutomationTest_Select#AutomationTest_AutomationTestId}

Error message:
Test Case [EwR - Test Case 1] failed [java.lang.Exception: Failed to prepare the test step [AutomationTestInput_Select]; com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '='.:java.lang.Exception: Failed to prepare the test step [AutomationTestInput_Select]; com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '='.], time taken = 714

  • richie's avatar
    richie
    Community Hero

    Hey em_qdx 

     

    I kindof struggled with your question - the more I think about it - the more confused I get I'm afraid.

     

    Can you clarify where you say "and use a value from the current iteration from the first Data Source result set that runs earlier in sequence to retrieve records from a second Data Source that runs later in the sequence using a single, matching value?"

     

    When you say "current iteration" - does this mean you're using looping with this?

     

    Also when you say "first Data Source result set that runs earlier in sequence to retrieve records from a second Data Source" - I read this like the first Data source retrieves records from the second data source.....  I must be getting that wrong, surely?

     

    Looking at your numbered points, my assumption is that you have a testcase object with ONLY 2 DataSource teststep items in it - is that correct?

     

    Where you state "4. There is currently only one entry in each table and the key values in each record are the same value." - this sounds like there is only 1 record in each table - but surely that cant be correct - otherwise you wouldn't need two queries???

     

    Your queries are as follows  - note - I've stripped out the table name prefix cos you're only hitting one table in each query - so it's not necessary - I've also stripped out the aliasing just to make it a little easier to read.

     

    GetId DataSource TestStep

    SELECT AutomationTestId, TestName

    FROM AutomationTest;

     

    DataSourceName = GetId

    Property: AutomationTestId

     

    DataSource 2:
    Select AutomationTestInputId, AutomationTestId, InputModel,
    From AutomationTestInput
    Where AutomationTestId = ${GetId#AutomationTestId}

     

    you can have multiple DataSource test steps in your test case, however I'm not sure if you can use them together as I think you are using them.

     

    HOWEVER - depending on what you're trying to do - I think you have a couple of possibilities - but I'm gonna need the above questions answered and especially the following two

     

    1.  Whatever you're actually trying to do - rather than have 2 DataSource(JDBC type) steps - have you tried replacing the SECOND DataSource step with a JDBC step instead?  I use parameterised JDBC steps all the time and they work fine

     

    So you're test object hierarchy would be 

     

    TestSuite

    ---TestCase

    ------DataSource(JDBC type)_1

    ------JDBC TestStep

     

    2.  Why not just use an inner join in only one DataSource(JDBC type) step instead of having 2 separate queries?

     

    i.e. something like as follows:

     

    SELECT
    AT.AutomationTestId AS AT_AutomationTestId,
    AT.TestName AS AT_TestName,
    ATI.AutomationTestInputId AS ATI_AutomationTestInputId,
    ATI.AutomationTestId AS ATI_AutomationTestId, ATI.InputModel AS ATI_InputModel
    FROM Automation_Test AS AT
    INNER JOIN AutomationTestInput AS ATI WHERE AT.TestId = ATI.TestId;

     

     

    I keep changing my mind on the possible solutions cos I keep changing my mind what you actually need - hence this reply is just a bit of an unorganised ramble.

     

    If you can answer the 7 questions I've asked - that will nail everything down and I'll be able to give you an answer that'll work for you!

     

    Or - the other forum users don't get confused as easily as I do - they might answer without all my questions - but Im afraid I cant help without those answers.

     

    Cheers!

     

    Rich