2016-06-23 6 views
0

私はPythonでテストするためにセレンとレタスを扱っています。 私は、従業員表の行Python関数(レタスステップ)は常にretrurn True

@step('I count employee table rows') 
def i_count_emp_table_rows(step): 
    try: 
     elems = world.driver.find_elements_by_xpath(".//*[@id='myTable']/tr") 
     sum = 0 
     for item in elems: 
      sum= sum+1 
     return sum 
    except Exception, e: 
     print e 
     return None 

をカウントするため、このステップを持っていると私は、このステップでは、私は後に次のページに移動する前に(ステップ上使用)employeeテーブル内の従業員の数を保存したい、別のステップを持っています従業員ボタンの追加をクリックします。

しかし面白いことに、私は常にリストカウントの代わりに "True"を取得することです。私も使用されましたlen()しかし成功しません
ここではprint文の結果です。表中の
今すぐ右総行:真

+0

'step.given'が' True'を返しています。あなたは 'step.given'を見せてもらえますか? –

+1

@MosesKoledoyeはい私はすでにやりました。上記の関数はここで呼び出されています。 –

+0

@AdilMalikこのステップを呼び出すと、ステップが正常に実行された場合にTrueを返します。つまり、この場合return文は無意味です。 –

答えて

1

あなたはいくつかのグローバル変数に数を配置する必要があります。下記の更新された手順をご覧ください。

@step('I count employee table rows') 
def i_count_emp_table_rows(step): 
    try: 
     elems = world.driver.find_elements_by_xpath(".//*[@id='myTable']/tr") 
     world.count = len(elems) 
    except Exception, e: 
     print e.message 
     world.count = None 

@step('I click the Add Employee Button') 
def i_click_the_add_employee_button(step): 
    step.given('I count employee table rows') 
    print "Right Now total rows in table: " + str(world.count) 
    done, world.driver = click_page_element(admin_add_employee_button_xpath, world.driver, wait=10) 
関連する問題