gpt4 book ai didi

java - 打开 Selenium 浏览器的方法不与我当前的浏览器重叠

转载 作者:行者123 更新时间:2023-11-30 02:03:09 25 4
gpt4 key购买 nike

我有以下情况。一旦我开始 Selenium 测试,就会打开一个浏览器窗口。由于我有很多测试并且每天都会启动它们很多次,所以我不会让 Selenium 在我当前浏览器的前面(我正在工作的地方)打开新的浏览器窗口,而是在后台打开,所以它不会别打扰我。可能吗?

PS 澄清为什么我需要这个 - 一天中很多次,当我在当前浏览器中工作并且 selenium 测试正在运行时,Selenium 的浏览器窗口每个测试都会突然打开,我可以突然关闭它,输入一些内容等等。

我现在拥有的:

img

最佳答案

软件测试自动化开始是一门艺术。您的测试台应该是:

  • 配置了所有必需的软件二进制文件
  • 测试执行必须在受控环境中执行,以优化性能。
  • 当您的@Tests正在执行时,它应该不受手动干预
  • 特别是当您的@Tests基于Selenium,而测试执行正在进行测试环境不应被干预,因为:

    • At the lowest level, the behavior of actions class is intended to mimic the remote end's behavior with an actual input device as closely as possible, and the implementation strategy may involve e.g. injecting synthesized events into a browser event loop. Therefore the steps to dispatch an action will inevitably end up in implementation-specific territory. However there are certain content observable effects that must be consistent across implementations. To accommodate this, the specification requires that remote ends perform implementation-specific action dispatch steps, along with a list of events and their properties. This list is not comprehensive; in particular the default action of the input source may cause additional events to be generated depending on the implementation and the state of the browser (e.g. input events relating to key actions when the focus is on an editable element, scroll events, etc.).

  • 此外,

    • An activation trigger generated by the WebDriver API user needs to be indistinguishable from those generated by a real user interacting with the browser. In particular, the dispatched events will have the isTrusted attribute set to true. The most robust way to dispatch these events is by creating them in the browser implementation itself. Sending OS-specific input messages to the browser's window has the disadvantage that the browser being automated may not be properly isolated from a user accidentally modifying input source state. Use of an OS-level accessibility API has the disadvantage that the browser's window must be focused, and as a result, multiple WebDriver instances cannot run in parallel.

    • An advantage of an OS-level accessibility API is that it guarantees that inputs correctly mirror user input, and allows interaction with the host OS if necessary. This might, however, have performance penalties from a machine utilisation perspective.

  • 此外,

    • Robot Class is used to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed. The primary purpose of Robot is to facilitate automated testing of Java platform implementations. Using the class to generate input events differs from posting events to the AWT event queue or AWT components in that the events are generated in the platform's native input queue. For example, Robot.mouseMove will actually move the mouse cursor instead of just generating mouse move events.

  • 最后,按照Internet Explorer and Native Events :

    • As the InternetExplorerDriver is Windows-only, it attempts to use so-called "native", or OS-level events to perform mouse and keyboard operations in the browser. This is in contrast to using simulated JavaScript events for the same operations. The advantage of using native events is that it does not rely on the JavaScript sandbox, and it ensures proper JavaScript event propagation within the browser. However, there are currently some issues with mouse events when the IE browser window does not have focus, and when attempting to hover over elements.

  • 浏览器焦点:

    • The challenge is that IE itself appears to not fully respect the Windows messages we send the IE browser window (WM_MOUSEDOWN and WM_MOUSEUP) if the window doesn't have the focus. Specifically, the element being clicked on will receive a focus window around it, but the click will not be processed by the element. Arguably, we shouldn't be sending messages at all; rather, we should be using the SendInput() API, but that API explicitly requires the window to have the focus. We have two conflicting goals with the WebDriver project.

    • First, we strive to emulate the user as closely as possible. This means using native events rather than simulating the events using JavaScript.

    • Second, we want to not require focus of the browser window being automated. This means that just forcing the browser window to the foreground is sub-optimal.

结论

始终将测试环境开发环境分开,并且绝对不受手动干预

关于java - 打开 Selenium 浏览器的方法不与我当前的浏览器重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52162992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com