로그인 한 사용자가 Lettuce, Selenium 및 lettuce_webdriver로 내 장고 사이트에서 로그 아웃 할 수 있는지 테스트하려고합니다.Django의 'Client'와 Selenium의 webdriver 사이에서 사용되는 html/session을 동기화하는 방법
@before.all
def setup_browser():
profile = webdriver.FirefoxProfile()
profile.set_preference('network.dns.disableIPv6', True)
world.browser = webdriver.Firefox(profile)
world.client = Client(HTTP_USER_AGENT='Mozilla/5.0')
그리고이 때 한 후 '로그인': 내 terrain.py에서
내가 가진
@step(r'I am logged in as "(\w*)"')
def log_in(step, name):
world.client.login(username=name, password=name)
그리고 나는 내 사이트로 이동 :
And I go to "localhost:8000"
I find a link called "Logout ?" that goes to "/logout"
@step(r'I find a link called "(.*?)" that goes to "(.*?)"$')
def find_link(step, link_name, link_url):
print(world.browser.page_source)
elem = world.browser.find_element_by_xpath(r'//a[@href="%s"]' % link_url)
eq_(elem.text, link_name)
하지만 내 page_source는 내가 로그인하지 않은 것을 보여줍니다.이 종류의 의미는 ... client
과 browser
은 e 기타. 그러나 이것이 가능한가, 아니면 셀레늄 등의 링크를 클릭하여 '수동으로'로그인해야합니까?
world.browser.page_source = world.client.get(world.browser.current_url).content
을하지만 page_source 변경할 수 없습니다 :
나는이 일을하고 싶습니다. 내가 어떻게 장고의 클라이언트에서 셀레늄을 먹일 수 있을까?
편집 : 아래의 Loius' 조언에 이어 '내 로그인 ...'단계가 아래에 나와 있습니다. 나는 의심을 확인하기 위해 if/else를 추가했다. 제 의뢰인은
@step(r'I am logged in as "(\w*)"')
def log_in(step, name):
world.client.login(username=name, password=name)
if world.client.cookies:
session_key = world.client.cookies["sessionid"].value
world.browser.add_cookie({'name':'sessionid', 'value':session_key})
world.browser.refresh()
else:
raise Exception("No Cookies!")
내가 본 모든 충고가 처음 로그인하는 것입니다 (위 setup_browser
단계 참조) 위와 같이 여전히 설정입니다. 내 체크하지 않고,이 얻을 :
Scenario: Logged in users can logout # \gantt_charts\features\index.feature:12
Given I am logged in as "elsepeth" # \gantt_charts\features\steps.py:25
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\lettuce\core.py", line 144, in __call__
ret = self.function(self.step, *args, **kw)
File "D:\Django_Projects\gAnttlr\gantt_charts\features\steps.py", line 27, in log_in
session_key = world.client.cookies["sessionid"].value
KeyError: 'sessionid'