2017-11-29 16 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")) 

이 어설 션 문이 있습니다. 내가 첫 번째 하나를 실행하면 잘 작동하지만, 원하지 않는 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): 
- : 때마다 나는 다음과 같은 오류가 두 번째 어설 션 문을 실행

01 : 같은 is_element_present_common 기능

그리고

변경 호출

+0

이걸 시도해보고 다른 오류가 나옵니다 : - TypeError : is_element_present_common() 2 개의 필수 위치 인수가 있습니다 : 'how'와 'what'' – Northers

+0

@Northers 내 업데이트 된 답변을 확인하고 상태를 알려주십시오. – DebanjanB

+0

좋아, 나는 함수 선언에서 자기를 제거하려고 시도했다. 그리고 나서'self'가 정의되지 않는다고 불평했다. 그래서 나는 드라이버 이전에 스스로를 제거하고 정의되지 않은'driver'에 대해 불평했다. 그래서 나는'driver'를 함수 선언을하고 나에게 '무엇'이라는 누락 된 위치 인수에 대해 말해주었습니다. 나는 assert 문을 작성할 때 "my-projects-table_info"를 메서드의'how '부분으로보고 있으므로'what' 부분이 누락되어 있음을 알 수있다. – Northers