0

I have function that have For loop and return for each iteration True or False

def testcase(x,testType=""):
        parameter_list = open("Parameter_List.csv")
        Parameters = csv.reader(parameter_list)
        if x =='compagne' :
            for row in Parameters :
                param = row[0].split(";")
                if param == ["Name","Format","Arraysize","MinVal","MaxVal","Default Val"] :
                    pass
                else :
                    parameter = Parameter(param[0], param[1], param[2], param[3], param[4], param[5])
                    return parameter.robotALLtest()
    
        elif x == 'one test' and testType in ["Min Value", "Max Value", "Lower Min", "Greater Max", "Persistence ON", "Persistence OFF", "Rset"] :
            for row in Parameters:
                param = row[0].split(";")
                if param == ["Name", "Format", "Arraysize", "MinVal", "MaxVal", "Default Val"]:
                    pass
                else:
                    parameter = Parameter(
                    param[0], param[1], param[2], param[3], param[4], param[5])
                    return parameter.robotTestParameter(testType)
        else :
            for row in Parameters:
                param = row[0].split(";")
                if x == param[0] :
                    parameter = Parameter(param[0], param[1], param[2], param[3], param[4], param[5])
                    break
            return parameter.robotTestParameter(testType)

I used RobotFreamwork to test the output

*** Settings ***
Library  test_cases.py

*** Test Cases ***
Test Parameter
    
    ${value}  test_cases.testcase   ${'one test'}   ${'Lower Min'}
    SHOULD BE EQUAL     ${value}    ${True}

But i have just the result for the first iteration. What can i do to get all the results?

1 Answer 1

1

In the example you gave:

        elif x == 'one test' and testType in ["Min Value", "Max Value", "Lower Min", "Greater Max", "Persistence ON", "Persistence OFF", "Rset"] :
            for row in Parameters:
                param = row[0].split(";")
                if param == ["Name", "Format", "Arraysize", "MinVal", "MaxVal", "Default Val"]:
                    pass
                else:
                    parameter = Parameter(
                    param[0], param[1], param[2], param[3], param[4], param[5])
                    return parameter.robotTestParameter(testType)

your code looks like "lets read this csv file, if the row looks like a header, lets skip that but if its actual test data, it goes to the else branch.

And that else branch will return parameter.robotTestParameter(testType) from the testcase(), thus, you only loop 2 rows from the Parameters and first non-header row is the only that is applied.

So, essentially, your code works exactly how you wrote it.

On python side, you could do something like

result = True
for row in Parameters:
   param = row[0].split(";")
   if param == ["Name", "Format", "Arraysize", "MinVal", "MaxVal", "Default Val"]:
       pass
   else:
       parameter = Parameter(
       param[0], param[1], param[2], param[3], param[4], param[5])
       if parameter.robotTestParameter(testType) == False:
           result = False
return result

BUT this is not very good approach to solve the situation .. I'd start looking and learning on how to use Datadriver library / https://github.com/Snooz82/robotframework-datadriver

Sign up to request clarification or add additional context in comments.

3 Comments

i think you don't understand me , for each row the script return True or False i have more than 100 rows i want to test the result from looping all the rows for example : row 1 i have parameter 1 , parameter.robotTestParameter(testType) return True or False then row 2 parameter 2 , parameter.robotTestParameter(testType) return True or False then all the parameters in the csv file. i want to have general test review to all the test
Either you dont understand what i tried to say or you where not very clear about the issue and my assumption was wrong. For the first part: because you call return from inside the for loop, you do not have a loop, you just run the testcase against the first non-header in the csv file. If this is not the case, then the issue is in your Parameter class. Maybe you could share how the Parameter_list.csv looks like ?
When i run the script and print(parameter.robotTestParameter(testType)) the script is running well and i have for each row the returned value from parameter.robotTestParameter(testType) which is could be True or False so i don't have a problem in the code. my problem is how to how to impliment that in robot freamwork , i want to test each returned value and get general report of test , if the returned value = True the test get the status passed and if returned value = False the test get the status failed. i hope that is clear.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.