Switcher in python with Get

Asked

Viewed 52 times

-1

I created a function in Python to return me a name of an object.

Before trying to use Switcher I did several variables as below:

name_case_1 = poco("Content").child("CaseItem(Clone)")[0].offspring("CaseName")

name_case_2 = poco("Content").child("CaseItem(Clone)")[1].offspring("CaseName")

name_case_3 = poco("Content").child("CaseItem(Clone)")[2].offspring("CaseName")

Then I created this function: case = 'THE TEACHER'

def validate_case_name(case):
switcher = {
case: 0,
case: 1,
case: 2,
}
 return poco('Content').child("CaseItem(Clone)")[switcher.get(case)].offspring("CaseName").get_text()

case: 0 = THE TEACHER case: 1 = THE TEST case: 2 = THE CAR

But he always returns what is in [2] or 'THE CAR'. Could someone tell me how I could make this my function check if inside Switcher has the in "THE TEACHER"?

today my statement is like this:

assert_equal(context.cases.validate_case_name(case), 'THE TEACHER', 'OK')

2 answers

1

will not work because a dictionary does not have repeated keys, try so

op = {1 : 'teste',
      2 : 'outro teste',
      3 : 'mais um teste'}

escolha = 1
print(op.get(escolha))

0


Got it bro, got it like this:

def validate_case_name(context, case):
switcher = {
    "THE TEACHER": 0,
    "THE ARTIST": 1,
    "THE DRIVER": 2
}
name = context.poco("Content").child("CaseItem(Clone)")[int(switcher.get(case))].offspring("CaseName").get_text()
if name == case:
    assert_equal(name, case, 'Pass')
elif name != case:
    assert_equal(name, case, 'fail')

Browser other questions tagged

You are not signed in. Login or sign up in order to post.