【问题标题】:Replacing selenium with geb page in a python test automation script在 python 测试自动化脚本中用 geb 页面替换 selenium
【发布时间】:2017-05-10 14:52:11
【问题描述】:

我们可以在 python 测试自动化脚本中用 geb 替换 selenium 吗? Geb 是用 groovy java 实现的,而 python 是一门独立的语言。

示例代码:

groovy geb code 
import geb.Page

import org.openqa.selenium.By

class GooglePage extends Page {
        static at = { title == "Google" }
        static url = "http://www.google.com"
        static content = {
        searchField(wait:true) { $("input", name:"q")}
        submit(wait:true) { $("button", name:"btnG")}
    }
}

蟒蛇:

在搜索字段中输入文本

searchField = "Google"

如果可以的话,是否可以做到这一点,请评论。

【问题讨论】:

  • 基本上使用python脚本中的geb contant或geb类函数

标签: python selenium automation spock geb


【解决方案1】:

朋友,一切皆有可能。真正的问题是实施起来有多难。

第一件事是:python 使用 webdriver 吗? python 需要驱动浏览器才能工作。接下来,页面对象就像任何其他 Java 类一样。如果您通常能够与 python 中的 java 类交互,那么您应该能够做到这一点。

请参阅Calling Java from Python 了解如何从 python 调用 java。

现在我强烈建议您不要通过 python 执行此操作,因为您可以简单地调用 searchField.value("google") 从 geb 范围内执行您想要的操作,但我想每个人都有自己的操作。

请参阅 Peter Niederwieser 对此问题的回答:running a geb test from a java class

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-22
    • 2020-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-23
    • 2017-05-19
    • 1970-01-01
    相关资源
    最近更新 更多