在 Peoplesoft 应用程序上使用 Watir:每个文本字段都会重新加载页面

发布于 2024-10-16 15:10:46 字数 626 浏览 2 评论 0原文

我正在使用 Watir 1.6.7。

我正在使用 Watir 和 Cucumber 为 PeopleSoft 应用程序开发一些回归测试。我在应用程序中遇到了一些表单问题。

首先,当在文本字段中输入值时,当用户在文本字段外部单击时页面会刷新。等待下一个 text_field 元素存在是有问题的,因为它可能会在页面重新加载之前或页面按预期重新加载之后找到该元素。增加等待时间从来都不是一个好的解决方案,尽管它“有效”。

第二个问题是,直到用户单击当前字段之外时才会触发页面刷新。在这种情况下,当脚本尝试访问下一个要填充的 text_field 时,就会发生这种情况。这里的一个解决方案是发送或击键,但我可以感觉到脚本随着每次这样的添加而变得更加脆弱。

是否有其他方法不那么脆弱,并且在每个 text_field 操作之间不需要 2-3 个额外的命令?

详细情况如下所示:

  • 浏览器导航到包含该表单的页面。
  • 浏览器填写第一个表单字段。 (修复:发送击键导致页面刷新,wait_until 第二个字段再次可见)
  • 浏览器选择要填写的第二个表单字段。 (再次,击键和 wait_until)
  • 页面刷新,脚本失败。 (已解决)
  • 浏览器选择第三个表单字段...

I'm using Watir 1.6.7.

I'm working on developing some regression tests for a PeopleSoft App using Watir and Cucumber. I have run into a few issues with forms in the application.

First, when entering a value into a text_field, the page refreshes when the user clicks outside the text_field. Waiting for the next text_field element to exist is problematic because it may locate the element before the page reloads, or after the page reloads as expected. Increasing the wait time never feels like a good solution, even though it "works".

The second issue is that the page refresh is not triggered until the user clicks outside the current field. In this case, that happens when the script tries to access the next text_field to be populated. One solution here would be to send a or keystroke, but I can feel the script becoming more brittle with every addition like this.

Are there any other approaches that would be less brittle, and not require 2-3 extra commands in between each text_field action?

The play-by-play looks like:

  • Browser navigates to page that contains the form.
  • Browser fills in first form field. (fix: send keystroke to cause page refresh, wait_until second field is visible again)
  • Browser selects the second form field to be filled out. (again, keystroke & wait_until)
  • Page refreshes, script fails. (resolved)
  • Browser selects the third form field...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

临走之时 2024-10-23 15:10:46

应用程序启动超过了 5 秒的睡眠持续时间,我不想再增加等待时间。我想看看如果我使用“element.value =”而不是使用“element.set”逐个字符更快地填充文本字段会发生什么。

这一改变彻底解决了所有的并发症。输入文本时页面不再刷新,并且不再需要 send_keys 语句来使用 TAB 或 ENTER 移动到另一个字段。即使字段之间没有刷新或状态保存,表单也会存储输入的所有数据。

以前的方法:

def enter_text(element, text)
    element.set text
    @browser.send_keys("+{TAB}")
    sleep 5
    Watir:Wait.until { element.exists? }
end

新方法:

def enter_text(element, text)
    element.value = text
end

The application started exceeding the 5 second sleep duration, and I did not want to increase the wait time any longer. I wanted to see what would happen if I populated the text field faster using "element.value =" rather than character by character with "element.set ".

This change completely resolved all complications. The page no longer refreshes when entering text, and no long requires a send_keys statement to use TAB or ENTER to move to another field. The form is storing all of the data entered even though there are no refreshes or state saves between fields.

Previous method:

def enter_text(element, text)
    element.set text
    @browser.send_keys("+{TAB}")
    sleep 5
    Watir:Wait.until { element.exists? }
end

New method:

def enter_text(element, text)
    element.value = text
end
你与清晨阳光 2024-10-23 15:10:46

首先,这里有一些有趣的等待方法:如何我应该使用 Watir::Waiter::wait_until 来强制 Chrome 等待吗?

总的来说,我不太明白你的问题。据我了解,您的脚本正在运行。如果与您已有的相比,您可以更清楚地了解您的愿望,那么将会有所帮助,一些示例源代码也是如此。

如果您正在寻找有关自定义等待的想法,您可以检查页面、表单或文本字段的 HTML 中的更改。您可以检查文本字段是否可见?。您可以尝试访问下一个文本字段(例如单击它,或设置值),然后在找不到文本字段时捕获异常并重试,直到它不中断,这将立即解决您的两个问题。

为什么单击当前字段之外是一个糟糕的解决方案?您绝对需要下一步进行文本字段访问吗?我还没有弄清楚下一个字段如何仅在您单击当前字段之外时才存在,但您可以通过访问下一个字段来导致刷新。

编辑:非常欢迎,感谢您澄清这一点,我想我现在理解得更好了。如果您允许 Watir 调用其页面等待,或强制它这样做,那么它将等待刷新,然后您可以找到新的文本字段。击键不会调用 ie.wait,因此如果您发送单个击键,然后调用等待,则脚本的其余部分将响应刷新后状态。

我强烈推荐 有关在 Watir 等待的 OpenQA 页面 。如果您正在执行的调用刷新操作没有出现在调用 Watir 页面等待的列表中,那么您需要调用自己的页面等待...但您需要在页面刷新之前执行此操作,因此原因刷新应该在刷新本身结束之前结束。

Firstly, there are interesting Wait methods here: How do I use Watir::Waiter::wait_until to force Chrome to wait?

Overall, I don't quite understand your problem. As I understand it your script is working. If you could be a bit clearer about your desires compared to what you already have that would help, as would some sample source code.

If you're looking for ideas on custom waiting you could check for changes in the HTML of your page, form or text field. You could check that the text field is .visible?. You could try accessing the next text_field (clicking it, or setting the value for example), then catch the exception if it can't find the text_field and retry until it doesn't break, which would solve both your problems at once.

Why would clicking outside the current field be a bad solution? Do you absolutely need the next step to be a text_field access? I haven't gotten my head around how the next field only exists when you click outside the current field, but you cause this refresh by accessing the next field.

Edit: Most welcome, and thank you for clearing that up, I think I now understand better. If you allow Watir to invoke its page wait, or force it to, then it will wait for the refresh and you can then find the new text_field. Keystrokes do not invoke ie.wait, so if you send a single keystroke, then invoke a wait then the rest of your script will be responding to the post-refresh state.

I highly recommend the OpenQA page on waiting in Watir. If what you're doing to invoke the refresh does not appear on the list of things that invoke Watir page waits then you need to invoke your own page wait... but you need to do it before the page refreshes, so the cause of the refresh should end before the end of the refresh itself.

抹茶夏天i‖ 2024-10-23 15:10:46

我对 peoplesoft 的应用程序不太了解,无法了解这一点,但是该应用程序在处理时是否为用户显示任何内容......比如某种小“加载”图形或任何您可能可以关闭以告知何时的内容完成了吗?

我见过执行此操作的应用程序,该项目只是一个动画 gif 或 png,它是通过更改包含图形的 div 的可见性属性来显示的。在这种情况下,您可以使用 .visible? 判断应用程序是否仍在加载。该元素上的方法并休眠一段时间(如果它仍然存在)。

对于我正在测试的应用程序(具有其中一个“图标”),我创建了一个简单的方法,称为 sleepwhileloading。它所做的就是使用一个包含在 while 循环中的一秒睡眠来查看加载图标是否可见。就像魅力一样

I don't know peoplesoft's app well enough to know this, but Does the app display anything for the user while it's processing.. like some kind of little 'loading' graphic or anything that you might be able to key off of to tell when it's done?

I've seen apps that do this, and the item is just an animated gif or png and it is displayed by altering the visibility attribute of the div that contains the graphic. In that instance you can tell if the app is still loading by using the .visible? method on that element and sleeping for a while if it's still there.

for the app I'm testing (which has one of those 'icons') I created a simple method I called sleepwhileloading. all it that is does is use a one second sleep wrapped in a while loop that looks to see if the loading icon is visible. works like a charm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文