1
{-# LANGUAGE OverloadedStrings #-}


module Main where

import Web.Api.WebDriver.Endpoints
import Web.Api.WebDriver

main :: IO ()
main = do
  x <- execWebDriverT defaultWebDriverConfig doLogin
  print x

doLogin :: WebDriverT IO ()
doLogin = do
  fullscreenWindow
  navigateTo "http://localhost:8001/login"
  z <- findElements CssSelector "div.alert"
  assertEqual [] z "Errors found"

上面的代码导致错误:

2021-12-13 16:32:39 错误错误没有正在进行的会话(左(E NoSession),S {_httpOptions = Options { manager = Left _,proxy = Nothing,auth = Nothing,headers = [("User-Agent ","haskell wreq-0.5.3.2")], params = [], redirects = 10, cookies = Just (CJ {expose = []}) }, _httpSession = Nothing, _userState = WDState {_sessionId = Nothing, _breakpoints = BreakpointsOff}},W {unW = [LogEntry {_logEntryTimestamp = 2021-12-13 16:32:39.03282154 UTC, _logEntryUID = "", _logEntrySeverity = LogError, _logEntry = L_Error NoSession}]})

这个错误说明了什么?我错过了什么?

完整的示例项目可以在这里找到:https ://github.com/chrissound/434/commit/ea1f3d840b64093b40ebba0e3dfceaacd4b36716

4

1 回答 1

0

该错误表明没有在“webdriver”上初始化会话。

会话相当于特定用户代理的单个实例化,包括其所有子浏览器。WebDriver 为每个会话提供一个唯一的会话 ID,可用于区分一个会话与另一个会话,允许从单个 HTTP 服务器控制多个用户代理,并允许通过多路复用器(称为中间节点)路由会话。

https://www.w3.org/TR/webdriver/#sessions


可以通过以下方式创建/管理会话:

  x <- execWebDriverT defaultWebDriverConfig $
   runIsolated defaultFirefoxCapabilities doLogin

而不是x <- execWebDriverT defaultWebDriverConfig doLogin.

似乎runIsolated负责所有会话处理。

于 2021-12-13T16:50:16.443 回答