学习 GEB 和 Spock [英] Learning GEB and Spock

查看:10
本文介绍了学习 GEB 和 Spock的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名手动测试员,正在尝试学习 GEB 和 Spock.要学习这些,我是否必须具备 Java 或 groovy 的先验知识?我一直在看GEB的书,有什么先决条件,书籍或学习资源?请帮忙.谢谢.

I am a manual tester trying to learn GEB and Spock. To learn these do I have to have prior knowledge of java or groovy? I have been reading the book of GEB, What are the prerequisites, books or learning resources? Please help. Thanks.

推荐答案

我尝试编写一些必需品和一些有用的东西",当我拿起 Geb 时发现它们很有帮助.

I tried compiling some essentials and some 'good-to-haves' that I found very helpful when I picked up Geb.

  1. 一些Groovy Magic.本手册涵盖了学习 Groovy 所需的大部分内容,但出于显而易见的原因,如果您沉迷于可能想要考虑的语言 Groovy 在行动.虽然学习 Groovy 不需要 Java,但如果您来自 Java(闭包除外)甚至 Python 背景,您可能可以浏览本教程 15 分钟,并且您已经在那里了).

  1. Some Groovy Magic. Most of all that you need to learn Groovy is covered in this manual but for obvious reasons if you get obsessed with the language you might want to consider Groovy in Action. While Java is not needed to pick up Groovy, If you are from a Java (except for closures) or even a Python background, you could probably skim through the tutorial for 15 minutes and you are there already).

一点硒.越多越好但不要害怕,这个单页告诉你所有你需要知道的关于您通常会使用的 Selenium Webdriver.但要强调,越多越好.

A little Selenium. The more, the better but fear not, this single page tells you all that you need to know about the Selenium Webdriver that you would generally use. But to stress, the more the better.

jQuery 选择器(每个人都说这很容易,但坦率地说,我每小时至少参考手册两次.我很笨,所以......).如果您不熟悉 jQuery,您可能希望从 基本选择器 并单击左侧导航菜单以获取更多信息.请注意,并非所有 jQuery 选择器都适用于 Geb,但 Geb 教程的选择器部分并不是很详尽和引人入胜.

jQuery selectors (everybody says that it is easy but frankly, I refer to the manual at least twice per hour. I am dumb, so…). If you are new to jQuery, you would want to start from basic selectors and click on the left navigation menu for more. Please note that not all jQuery selectors are applicable for Geb but the selectors section of Geb tutorial wasn't very exhaustive and engaging.

在我的测试用例结束时,我需要生成一个跨越多个测试用例的奇特报告,并且我在测试用例之间存在依赖关系.所以,我选择了 TestNG 而不是 Spock.坦率地说,我没有给 Spock 太多机会.

At the end of my testcases, I need to generate a fanciful report which stretches across multiple testcases and I had dependencies among testcases. So, I went for TestNG instead of Spock. Frankly, I didn't give Spock a lot of chance.

PageObjects 实际上不是 Geb 的先决条件,但 PageObjects 是如此真棒,你从来不想在它之外考虑 Geb.PageObjects 是一个可爱的小模式,它表示您将 HTML 页面的结构包装到一个对象中,这样实际的测试就不必处理它.哈.得到你.让我用简单的英语说一下.

PageObjects is actually not a prerequisite for Geb but PageObjects are so awesome that you never wanted to think about Geb outside of it. PageObjects is a cute little pattern which says that you wrap the structure of your HTML page into an Object so that the actual test does not have to deal with it. Hah. Got you. Let me put that in plain English.

假设您有一个带有输入文本框的注册表单,其 ID 为nametext".你将如何获得文本框的句柄?在 DOM 术语中,在 javascript 中,您只需执行

Say, you have a registration form with input textbox which has an id of "nametext". How would you get the handle of the textbox? In DOM terms, in javascript, you would just do a

 document.getElementById("nametext")

在 Selenium 中,你会做一个非常相似的事情

In Selenium, you would do a very similar thing

 driver.findElement(By.id("nametext"))

因此,如果您想在 Selenium 的文本框中填充 Jason,您可以执行

So, if you would want to populate Jason in your text box in Selenium, you would do a

driver.findElement(By.id("nametext")).sendKeys("Jason"); 

如果你对所有输入字段都这样做,很快你的测试用例就会变得丑陋和可恨.取而代之的是,在面向对象的术语中,您进行了封装.您创建一个新类,例如 RegistrationPage 并包装您的 findElementsendKeys ,如下所示:

If you do that for all your input fields, very soon your testcases become ugly and hateful. Instead of that, in OO terms, you encapsulate. You create a new class, say RegistrationPage and wrap your findElement and sendKeys as in :

public class RegistrationPage{

    …

    public RegistrationPage fillRegistrationForm(String name, String email){

        driver.findElement(By.id("nametext")).sendKeys(name); 
        driver.findElement(By.id("emailtext")).sendKeys(email); 

    }

}

从你的测试用例中,你会说

and from your testcase, you would say

  RegistrationPage regPage=new RegistrationPage();
  regPage.fillRegistrationForm("Jason","jason@bourne.com");

(更好的想法是将您的输入值包装到一个类中并将其传递给fillRegistrationForm)

事实上,Geb 以更好的方式利用 PageObjects - jQuery 选择器来拯救

In fact, Geb leverages PageObjects in a much better way - jQuery selectors to the rescue

class InputFormPage extends Page{

    …

    static content={
        name {$("input", id:"entry_0")}
        emailAddress {$("input", id:"entry_1")}
    }
 }

在您的测试用例中,您只需说

and in your testcase, you would just say

 name.value ("Jason")
 emailAddress.value ("jason@bourne.com")

这篇关于学习 GEB 和 Spock的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆