2017-11-29 13 views
-1

要素の存在を宣言しようとしています。AssertTrueがありません1必要な定位置の引数

from selenium.common.exceptions import NoSuchElementException 


def is_element_present_common(self, how, what): 
    try: 
     self.driver.find_element(by=how, value=what) 
    except NoSuchElementException as e: 
     return False 
    return True 

...と私のメインのファイル: - - :

は、私は一般的な機能のファイルを持っている

import unittest 
from Common import common_functions, initialisation, login 
from selenium.webdriver.common.by import By 
from selenium.webdriver.support import expected_conditions as ec 
from selenium.common.exceptions import NoSuchElementException 


class QuickTestPlanLogin(unittest.TestCase): 
    def setUp(self): 
     self.driver = initialisation.start_webdriver() 
     self.driver = initialisation.start_sap(self.driver) 

    def tearDown(self): 
     self.driver.close() 

    def is_element_present(self, how, what): 
     try: 
      self.driver.find_element(by=how, value=what) 
     except NoSuchElementException as e: 
      return False 
     return True 

    def test_login(self): 
     wait = initialisation.wait_for(self.driver) 
     self.driver = login.default_login(self.driver, "username", "password") 

     # self.assertTrue(self.is_element_present(By.ID, "my-projects-table_info")) 
     # self.assertTrue(common_functions.is_element_present_common(By.ID, "my-projects-table_info")) 

2つのassert文があります。私は最初の1つを実行する場合、それは正常に動作しますが、私はしたくないis_element_present関数を呼び出しています。私は、common_functionsファイルからis_element_present_common関数を呼びたいと思います。

TypeError: is_element_present() missing 1 required positional argument: 'what' 

私は、私は非常に単純な何かが欠けています知っている....

+0

引数として 'self'をとる関数はすべてメソッドであることを意図しています。したがって、クラスの内部にあるはずで、 'instance.method_name()'を介して呼び出す必要があります。もしそれがクラスに存在しないと仮定されていれば、 'self'パラメータを持つべきではありません。 – khelwood

+0

クラス内に 'is_element_present_common'を配置しようとしましたが、同じエラーが発生しています。私はすでに 'self'パラメータを削除しようとしましたが、別のエラーを出すように構文を正しく取得できません: - ' NameError:name 'driver' is not defined – Northers

+0

申し訳ありませんが、 - 'TypeError:is_element_present_common()missing 1必要な位置引数: 'what''は元のエラーメッセージと同じです...?!? – Northers

答えて

0

変更関数の定義:

def is_element_present_common(how, what): 
- :たびに私は次のエラーを取得する第二assert文を実行します

01:として is_element_present_common機能に

そして

変更は、コール

+0

これを試して、別のエラーが発生しました: - ' TypeError:is_element_present_common()2つの必須の位置引数 'how'と 'what'' – Northers

+0

@Northers私の更新されたAnswerをチェックし、ステータスを教えてください。 – DebanjanB

+0

さて、関数宣言から自分自身を削除しようとしましたが、 'self'が定義されていないと不平を言いましたので、ドライバの前からselfを削除して' driver'が定義されていないと不平を言ったので 'driver'を関数の宣言に戻り、欠落している位置引数 'what'について私に伝えました。私はassert文を書くときに、メソッドの 'how'部分として" my-projects-table_info "を見ているので、' what'部分が見つからないことに気付きました.... – Northers

関連する問題