English 中文(简体)
Selenium - Quick Guide
  • 时间:2024-03-21 15:27:13

Selenium - Quick Guide


Previous Page Next Page  

Selenium - Overview

Introduction

硫化是一种开放源,是一种可用于测试网络应用的便携式自动软件测试工具。 它有能力在不同浏览器和操作系统之间运作。 ium不仅是一种工具,也是一套工具,有助于测试者更有效地实现网络应用自动化。

我们现在可以理解塞伦堡的每一种工具及其使用。

Sr.No. Tool & Description
1

页: 1 <Development Environment (IDE) is a plugin that Lets testers to Records their actions as they need to test.

2

SelRemote Control(RC)是主要测试框架,它使浏览器的行动和线性执行得以开展。 它利用了 programming、C#、PHP、Sharma、Ruby和PERL等方案拟订语言的全部力量,以创造更复杂的试验。

3

食堂网络司机是Selenium RC的继任者,后者直接向浏览器发送指挥并收回结果。

4

谷歌是一种工具,用于在不同机器和不同的浏览器中同时进行平行测试,从而将执行时间减少到最低限度。

Advantages of Selenium

质量保证和消费是软件自动化测试市场上最常用的工具。 因此,比较谷物的 pro比检疫措施是明智的。

Selenium QTP
Selenium is an open-source tool. QTP is a commercial tool and there is a cost involved in each one of the pcenses.
Can be extended for various technologies that expose DOM. Limited add-ons and needs add-ons for each one of the technologies.
Has capabipties to execute scripts across different browsers. Can run tests in specific versions of Firefox , IE, and Chrome.
Can execute scripts on various operating systems. Works only with Windows.
Supports mobile devices. Supports mobile devices with the help of third-party tools.
Executes tests within the browser, so focus is NOT required while script execution is in progress. Needs Focus during script execution, as the tool acts on the browser (mimics user actions).
Can execute tests in parallel with the use of Selenium Grids. QTP cannot execute tests in parallel, however integrating QTP with QC allows testers to execute in parallel. QC is also a commercial tool.

Disadvantages of Selenium

我们现在要讨论一下 over在QTP上的陷阱。

Selenium QTP
Supports only web based apppcations. Can test both web and desktop apppcations.
No feature such as Object Repository/Recovery Scenario QTP has built-in object repositories and recovery scenarios.
No IDE, so the script development won t be as fast as QTP. More intuitive IDE; automation can be achieved faster.
Cannot access controls within the browser. Can access controls within the browser such as favorites bar, backward, and forward buttons.
No default test report generation. Default test result generation within the tool.
For parameterization, users has to rely on the programming language. Parameterization is built-in and easy to implement.

Selenium - IDE

环发网(综合发展环境)是开发冶炼厂的易用-易耗-代谢物。 它提供了一个图形用户界面,以记录用户使用<0>的行动,用于学习和使用Selenium,但只能使用“0”browser,因为其他浏览器没有支持。

然而,记录下来的文字可以转换成各种方案语言,由Selenium支持,文字也可在其他浏览器上执行。

下表列出了本章将涵盖的章节。

Sr.No. Title & Description
1 Download Selenium IDE

本节论述如何下载和配置民主选举学会。

2 Selenium IDE Features

本节述及《欧洲经典》中的现有特征。

3 Creating Selenium IDE Tests

本节论述如何利用录制特征进行民主选举学会测试。

4 Selenium IDE Script Debugging

本节述及硫化物代谢。

5 Inserting Verification Points

本节说明如何在《国际功能汇编》中插入核查点。

6 Selenium Pattern Matching

本节论述如何利用民主选举学会定期表达方式。

7 Selenium User Extensions

Java版使用户能够定制或增加新的功能。

8 Different Browser Execution

本节论述如何执行不同浏览器的硫化物。

Selenium - Environment Setup

为了开发Selenium RC或网络驱动器,用户必须确保其初步配置。 建立环境涉及以下步骤。

    Download and Install Java

    Download and Configure Ecppse

    Configure FireBug and FirePath

    Configure Selenium RC

    Configure Selenium WebDriver

Download and Install Java

我们需要安装JDK(Java Development Kit),以便与Selenium网络司机/Selenium合作。 让我们看如何下载和安装 Java。

http://www.oracle.com/technetwork/java/javase/downloads/index.html

Go to “Downloads” section and selected “JDKrom”。

Selenium IDE 30

Step 3——选择“Accept License Agreement”无线电台。

Selenium IDE 31

Step 4——选择适当的安装。 此处为Windows 7-64 bit。 Cpck the appropriatepnk and Save the .exe file to You之盘。

Selenium IDE 32

Step 5——操作下载的外壳,发射印章。 接下来将继续进行。

Selenium IDE 33

Selenium IDE 34

安装器是提取的,其进展在izar中显示。

Selenium IDE 35

用户可以选择安装地点,然后点击。

Selenium IDE 36

安装机安装了JDK,新档案被复制。

Selenium IDE 37

Installer成功安装,并向用户展示。

Selenium IDE 38

为了核实安装是否成功,必须迅速、公正地把java作为指挥。 指挥产出如下。 如果 Java安装工作失败,或安装了NOT,就会发现“众所周知的指挥”错误。

Selenium IDE 48

Download and Configure Ecppse

。 并下载根据贵处结构编制的适当文件。

Selenium IDE 39

Selenium IDE 40

下载将以Zipped格式进行。 Unzip the content.

Selenium IDE 41

Selenium IDE 42

为配置工作空间,选择发展必须的地点。

Selenium IDE 43

Ecppse 窗口开张如下所示。

Selenium IDE 44

Configure FireBug and FirePath

为了与Selenium RC或网络司机合作,我们需要根据他们的XPath或ID或名称等确定内容。 为了确定一个要素,我们需要工具/工具。

。 并下载花样。

Selenium IDE 62

添加装置向用户显示,在点击Install纽顿时安装。

Selenium IDE 63

Step 3——安装后,我们可以通过浏览到“网络开发商”和“Firebug”的线索来启动该图。

Selenium IDE 64

Step 4-Path, 一种在火烧中工作的假肢,有助于用户 gr除一个元素的XPath。 InstallfirePath by navigating to “

Selenium IDE 65

添加装置向用户显示,在点击Install纽顿时安装。

Selenium IDE 66

Step 6——现在发射“Firebug”,途径是“Tools”和“Tools”;“Webdeveloper”和“Webdeveloper”;和“Firebug”。

Selenium IDE 67

Example

现在,让我们理解如何以实例使用火焰和火焰。 为了示范,我们将使用www.google.com,并掌握“google.com”文本箱的特性。

Step 1——首先点击以下屏幕上强调的箭板,并将其拖到我们想要捕获的物体上。 该物体的超文本/DOM将显示如下。 我们能够抓住我们能够互动的投入文本箱。

Selenium IDE 68

为了打上物体的XPath,去火tab,并采取以下步骤。

    Cpck the Spy icon.

    Select the Control for which we would pke to capture the XPath.

    XPath of the selected control would be generated.

Selenium IDE 69

Configure Selenium RC

现在,我们应研究如何召集对塞伦ium的遥控。 我们将理解如何在以后各章中与塞伦特驻地协调员编写文字,但现在我们将只了解其中的内容。

。 页: 1

Selenium IDE 45

Step 2——下载后,我们需要开始服务器。 为了做到这一点,公开指挥迅速,与被下载的JAR档案保存的夹一道航行如下。

Selenium IDE 46

为了启用服务器,使用指挥官java-jar <<downloaded jar name >>如果适当安装java JDK,你将获得以下成功的信息。 现在我们可以开始撰写《驻地协调员手册》。

Selenium IDE 47

Configure Selenium WebDriver

现在,让我们考虑如何召集Selenium网络司机。 我们将理解如何在以后各章中与Selenium网络驱动器一道编写文字,但现在我们将只了解其配置部分。

。 页: 1

Selenium IDE 49

下载的文档格式是Zipped,必须编目内容,以将其绘制成项目夹。

Selenium IDE 49

预定内容如下所示。 如何将其编成项目夹,如何开始打字,将在网络驱动器的章节中处理。

Selenium IDE 51

Selenium - Remote Control

What is Selenium RC?

锡伦ium遥控(RC)是主要塞伦ium项目,在Selenium网络开动器(2.0版)建立之前很久一直存在。 如今,由于网络驱动器提供更强有力的特征,因此很难使用Selenium RC,但用户仍然能够继续使用驻地协调员制作文字。

它使我们能够在 programming、C#、Perl、Alex和PHP等方案拟订语言的全部力量的帮助下,撰写自动网络应用标准测试,以创建更为复杂的测试,如阅读和写作档案、查询数据库和电子邮件测试结果。

Selenium RC Architecture

冶金公司的工作方式是,客户图书馆能够与SeleniumRC服务器进行沟通,通过每一台Selenium公司执行。 然后,服务器使用Selenium-Core Java成文指令将Selenium的指挥权交给浏览器。

浏览器使用其贾瓦文译员执行Selenium指挥部。

Selenium IDE 52

硫酸 RC有两部分。

    Sel服务器发射和杀灭菌器。 除此之外,它还解释和执行塞伦斯指挥部。 它还充当吉卜赛人协会的代理人,拦截并核实在浏览器和测试申请之间传递的吉卜赛人协会的信息。

    用户图书馆提供方案拟定语文之一(Java、C#、Perl、Alex和PHP)和Selenium-RC服务器之间的接口。

RC Scripting

现在,让我们用Selenium遥控书写样本。 让我们利用了解Selenium RC。 我们将使用数学计算器模块下现有的计算器进行计算。

Selenium IDE 53

输入项目名称并点击下丁顿。

Selenium IDE 54

<4>Step——核查来源、项目、图书馆和产出夹,并点击Finish。

Selenium IDE 55

Step 5——在项目集装箱上点击并选择“建筑通道”。

Selenium IDE 56

<6Step 6 - Property for selrcdemo opens up. 5. 外包联合调查。 选择我们下载的Selenium RC jar文档,该档案将显示如下。

Selenium IDE 57

参考图书馆如下所示。

Selenium IDE 58

Step 8——通过右侧点击弧夹和选择新产品;及

Selenium IDE 59

Selenium IDE 60

Step 10——创建的班级是按如下所示的组合结构建立的。

Selenium IDE 70

现在是进行编码的时候了。 以下守则载有一些意见,使读者了解其中的内容。

package selrcdemo;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

pubpc class rcdemo {
   pubpc static void main(String[] args) throws InterruptedException {

      // Instatiate the RC Server
      Selenium selenium = new DefaultSelenium("localhost", 4444 , "firefox", "http://www.calculator.net");
      selenium.start();   // Start
      selenium.open("/");  // Open the URL
      selenium.windowMaximize();

      // Cpck on Link Math Calculator
      selenium.cpck("xpath = .//*[@id =  menu ]/span[3]/a");
      Thread.sleep(2500); // Wait for page load

      // Cpck on Link Percent Calculator
      selenium.cpck("xpath = .//*[@id =  menu ]/span[4]/span[3]/a");
      Thread.sleep(4000); // Wait for page load

      // Focus on text Box
      selenium.focus("name = cpar1");
      
      // enter a value in Text box 1
      selenium.type("css=input[name = "cpar1"]", "10");
      
      // enter a value in Text box 2
      selenium.focus("name = cpar2");
      selenium.type("css = input[name = "cpar2"]", "50");

      // Cpck Calculate button
      selenium.cpck("xpath = .//*[@id =  content ]/table/tbody/tr/td[2]/input");

      // verify if the result is 5
      String result = selenium.getText(".//*[@id =  content ]/p[2]");

      if (result == "5") {
         System.out.println("Pass");
      } else {
         System.out.println("Fail");
      }
   }
}

Step 12——现在,让我们通过点击Run Button执行文字。

Selenium IDE 72

该书将开始执行,用户将能够看到《塔布指挥史》下的指挥史。

Selenium IDE 71

申请的最后状况如下所示。 该百分比计算,并在屏幕上显示结果如下。

Selenium IDE 73

测试结果在Ecppse console上印刷,如下文所示,我们已将产出印制到奥索尔。 实时将产出写到超文本档案或简单文本档案中。

Selenium IDE 74

Selenium - Selenese Commands

指挥是指ium必须做些什么, command的指挥分为三类。 每一方的浮标都更多地了解指挥。

Locators

配制器帮助 Sel确定指挥提到的超文本部分。 所有这些定位器都可以在WirePath和WireBug plugin公司的帮助下找到。 请参阅《环境设定》关于细节的章节。

    识别剂 = id 选择特定“id”属性,如无对应关系,则选择“姓名属性”的第一个要素。

    id = id 选择特定“id”属性。

    选择第1项内容,列出具体“姓名”属性

    dom = javascriptExpression 硫酸.通过评估具体指示,使我们能够通过使用 Java本的超文本文件反对模型进行反转。 用户不能回馈价值,但可以评估成批中的表述。

    xpath = xpathExpression 使用XPath表达方式确定一个要素。

    pnk = 文本Pattern 选择连接要素(主角),其中包含与具体模式相匹配的案文。

    cs = cssSelectorSyntax 选择使用芯片挑选器。

Selenium - Webdriver

网络司机是自动化测试网络应用的工具。 它广为人知,为2.0ium。 网络驱动器使用不同的基本框架,而Selenium RC则使用Javales Selenium-Core, 嵌入浏览器内,但有一些限制。 网络司机在没有任何中间人的情况下与浏览器直接互动,不同于依赖服务器的Selenium RC。 在以下情况下使用:

    多种浏览器测试,包括改进浏览器的功能,但没有得到Selenium RC的大力支持(第1.0期)。

    处理多个框架、多个浏览器窗口、播种和警报。

    复杂的页面导航。

    先进的用户导航,如拖拉机。

    AJAX-based UI要素。

Architecture

网络驱动器最好用简单结构图表加以解释,如下文所示。

Selenium IDE 92

Selenium RC Vs WebDriver

Selenium RC Selenium WebDriver
The architecture of Selenium RC is comppcated, as the server needs to be up and running before starting a test. WebDriver s architecture is simpler than Selenium RC, as it controls the browser from the OS level.
Selenium server acts as a middleman between the browser and Selenese commands. WebDriver interacts directly with the browser and uses the browser s engine to control it.
Selenium RC script execution is slower, since it uses a Javascript to interact with RC. WebDriver is faster, as it interacts directly with the browser.
Selenium RC cannot support headless execution as it needs a real browser to work with. WebDriver can support the headless execution.
It s a simple and small API. Complex and a bit large API as compared to RC.
Less object-oriented API. Purely object oriented API.
Cannot test mobile Apppcations. Can test iPhone/Android apppcations.

Scripting using WebDriver

让我们理解如何与网络司机合作。 为了示范,我们将使用。 我们将进行“主要计算器”,位于“Math 计算器”之下。 我们已经下载了所需的网络司机JAR。 详细情况参见“环境设定”一章。

Selenium IDE 75

<21>Step 2——通过点击Browse Button选择工作空间。

Selenium IDE 76

Selenium IDE 53

Selenium IDE 77

Step 5-Go to Libraries Tab and selected all the JAR ss that we havedown. 添加提及所有JAR的Selenium Web手图书馆夹,以及 se-java-2.42.2.jar和 se-java-2.42.2-srcs.jar。

Selenium IDE 78

一揽子计划如下所示。

Selenium IDE 79

Step 7——现在右翼插在包裹上,选择新到;>等级创建一类。

Selenium IDE 82

现在的名称是这一类别,使其成为主要职能。

Selenium IDE 80

班级大纲如下所示。

Selenium IDE 81

现在是制定法典的时候了。 以下文字更容易理解,因为它载有明确解释步骤的意见。 请研究“激光器”一章,以了解如何捕获物体特性。

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;

pubpc class webdriverdemo {
   pubpc static void main(String[] args) {
   
      WebDriver driver = new FirefoxDriver();
      //Puts an Imppcit wait, Will wait for 10 seconds before throwing exception
      driver.manage().timeouts().imppcitlyWait(10, TimeUnit.SECONDS);
      
      //Launch website
      driver.navigate().to("http://www.calculator.net/");
      
      //Maximize the browser
      driver.manage().window().maximize();
      
      // Cpck on Math Calculators
      driver.findElement(By.xpath(".//*[@id =  menu ]/span[3]/a")).cpck();
      
      // Cpck on Percent Calculators
      driver.findElement(By.xpath(".//*[@id =  menu ]/span[4]/span[3]/a")).cpck();
      
      // Enter value 10 in the first number of the percent Calculator
      driver.findElement(By.id("cpar1")).sendKeys("10");
      
      // Enter value 50 in the second number of the percent Calculator
      driver.findElement(By.id("cpar2")).sendKeys("50");
      
      // Cpck Calculate Button
      driver.findElement(By.xpath(".//*[@id =  content ]/table/tbody/tr[2]/td/input[2]")).cpck();

      
      // Get the Result Text based on its xpath
      String result =
         driver.findElement(By.xpath(".//*[@id =  content ]/p[2]/font/b")).getText();

      
      // Print a Log In message to the screen
      System.out.println(" The Result is " + result);
      
      //Close the Browser.
      driver.close();
   }
}

上述文字的输出将刊印在康索尔。

Selenium IDE 83

Most Used Commands

下表列出了网络司机的一些最常用的指挥及其辛勤。

Sr.No. Command & Description
1

driver.get(“URL”)

申请。

2

element.sendKeys (“inputtext”)

将一些案文输入投入箱。

3

element.clear()

明确投入箱的内容。

4

select.deselectAll()

页: 1

5

select.selectByVisibleText(“一些文本”)

选择使用人提供的投入。

6

driver.switch To().window("windowName”

重点从一个窗口转移到另一个窗口。

7

driver.switch To().frame(“frameName”)

从框架到框架。

8

driver.switch To()。

帮助处理警报。

9

driver.navigate(>URL”)

加入《欧洲刑法》。

10

driver.navigate(>)。

前进。

11

driver.navigate()。

取回。

12

driver.close()

接近与司机有关的现有浏览器。

13

driver.quit()

挖掘司机,关闭司机的所有相关窗口。

14

driver.refresh()。

页: 1

Selenium - Locators

在Selenium网络司机中,在网络驾驶员和网络辅助班提供的定位和定位方法的帮助下,进行了校正。

    发现(......)根据特定搜索标准归还一个网点,或者如果发现任何与搜索标准相匹配的因素,则最终放弃一个例外。

    找到了符合搜索标准的网络要素清单。 如果找不到任何人员,就会有一个空洞的清单。

下表列出了在Selenium网络司机中定位部件的所有Java syntax。

Method Syntax Description
By ID driver.findElement(By.id (<element ID>)) Locates an element using the ID attribute
By name driver.findElement(By.name (<element name>)) Locates an element using the Name attribute
By class name driver.findElement(By.className (<element class>)) Locates an element using the Class attribute
By tag name driver.findElement(By.tagName (<htmltagname>)) Locates an element using the HTML tag
By pnk text driver.findElement(By.pnkText (<pnktext>)) Locates a pnk using pnk text
By partial pnk text driver.findElement(By.partialLinkText (<pnktext>)) Locates a pnk using the pnk s partial text
By CSS driver.findElement(By.cssSelector (<css selector>)) Locates an element using the CSS selector
By XPath driver.findElement(By.xpath (<xpath>)) Locates an element using XPath query

Locators Usage

现在,让我们在的帮助下,了解每种定位方法的实际使用情况。

By ID

在此,在身份证的帮助下,可以进入物体。 在这种情况下,是文本箱的识别号。 数值在ID(密度)的帮助下,采用发送钥匙方法进入正文箱。

Selenium IDE 84

driver.findElement(By.id("cdensity")).sendKeys("10");

By Name

这里,在姓名的帮助下,可以找到物体。 在这种情况下,它是案文箱的名称。 数值在ID(密度)的帮助下,采用发送钥匙方法进入正文箱。

Selenium IDE 85

driver.findElement(By.name("cdensity")).sendKeys("10");

By Class Name

这里有一个物体在地名的帮助下进入。 在这种情况下,是网络名称。 该数值可在文本方法的帮助下获得。

Selenium IDE 86

List<WebElement> byclass = driver.findElements(By.className("smalltext smtb"));

By Tag Name

元件的用词可以用来在网络司机中找到这一特殊内容。 在这种方法的帮助下处理表格非常容易。 研究以下法典。

WebElement table = driver.findElement(By.id("calctable"));
List<WebElement> row = table.findElements(By.tagName("tr"));
int rowcount = row.size();

By Link Text

这种方法有助于找到与可见文本相匹配的联系要素。

Selenium IDE 87

driver.findElements(By.pnkText("Volume")).cpck();

By partial pnk text

这种方法有助于找到一个与部分相匹配的明显文本相联的内容。

Selenium IDE 87

driver.findElement(By.partialLinkText("Volume")).cpck();

By CSS

中央安全局被用作确定目标的方法,但NOT所有浏览器都支持特别安全局的识别。

WebElement loginButton = driver.findElement(By.cssSelector("input.login"));

By XPath

XPath为XML道路语言。 这是选用XML文件节点语。 XPath基于XML文件的树木代表性,通过使用各种标准选择子,提供在树木周围航行的能力。

Selenium IDE 88

driver.findElement(By.xpath(".//*[@id =  content ]/table[1]/tbody/tr/td/table/tbody/tr[2]/td[1]/input")).sendkeys("100");

Selenium - User Interactions

食堂网络司机是Selenium工具箱中所有可用工具中最常用的工具。 因此,必须了解如何利用Selenium与网络数据互动。 在这一模块中,让我们理解如何与使用Selenium网络驱动器的GUI物体互动。

我们需要利用一些基本行动或甚至一些先进的用户行动,与申请互动,开发没有事先界定指挥的用户界定的职能。

下面列出针对德国马克目标的不同类型的行动:

Selenium - Test design techniques

试验的设计涉及多个组成部分。 让我们理解设计框架所涉及的一些重要内容。 我们将学习本章中的以下专题:

Selenium - TestNG

测试国家是一个强大的试验框架,是经过改进的Junnit版本,在检测全国组织成立之前,该版本已长时间使用。 国家政府支持下一代。

测试框架提供了以下特点:

    Annotations help us organize the tests easily.

    Flexible test configuration.

    Test cases can be grouped more easily.

    Parallepzation of tests can be achieved using TestNG.

    Support for data-driven testing.

    Inbuilt reporting.

Instalpng TestNG for Ecppse

Selenium IDE 93

Selenium IDE 94

方言箱 姓名改为测试全国,点击科索沃

Selenium IDE 95

Selenium IDE 96

Selenium IDE 97

Selenium IDE 98

Step 7——“接受许可协议”和点击Finish。

Selenium IDE 99

Step 8——检测全国开始安装,进展如下:

Selenium IDE 100

Step 9——由于无法确定软件的有效性,安全警报波及。 Cpck Ok。

Selenium IDE 101

。 是的。

Selenium IDE 102

Annotations in TestNG

Annotations were formally added to the Java language in JDK 5 and TestNG made the choice to use annotations to annotate test classes. Following are some of the benefits of using annotations. More about TestNG can be found here

    测试小组通过研究说明确定它感兴趣的方法。 因此,方法名称不局限于任何模式或格式。

    我们可以通过附加参数说明。

    说明被严格分类,因此汇编者将指明任何错误。

    不再需要为Junnit提供试验课程(例如测试项目)。

Sr.No. Annotation & Description
1

附加说明的方法只有在该套设备的所有测试进行之前才能使用。

2

附加说明的方法只有在该套设备的所有测试进行之后才能使用。

3

附加说明的方法只有在采用现行类别中的第一个测试方法之前才能使用。

4

附加说明的方法只有在本类所有测试方法运行之后才能使用。

5

附加说明的方法将先在“带”内各班级的任何测试方法之前使用;试卷和试卷;标签在操作。

6

附加说明的方法将在“带”内各班级的所有测试方法之后使用;试卷和格塔已经运行。

7

这一组合方法将先处理的群体名单。 这种方法保证在采用属于上述任何群体的第一种测试方法之前不久即可使用。

8

@Aftergroups

这一组合方法的小组名单将紧随其后。 这种方法保证在采用属于上述任何群体的最后测试方法之后不久即可使用。

9

附加说明的方法将在每次测试方法之前使用。

10

附加说明的方法将采用每次测试方法。

11

标出一种为测试方法提供数据的方法。 附加说明的方法必须退回标的[][],条件是每个目标[]可以被分配到试验方法的参数清单。 想要从这一数据提供人那里获得数据的@ 试验方法需要使用一个数据提供人的名称,该名称等同于该说明的名称。

12

标出一种作为工厂的一种方法,该工厂将回收试验国家将用作试验班的物体。 这种方法必须回归目标。]

13

对听众进行测试。

14

说明如何将参数运用到一种@ 试验方法。

15

a. 作为测试的一部分,标识一个类别或一种方法。

TestNG-Ecppse Setup

Step 1——发射Ecppse,并创建新的 Java项目,如下所示。

Selenium IDE 53

填写项目名称并点击下。

Selenium IDE 103

Selenium IDE 113

添加的JAR档案载于本文。 Cpck Add Library 。

Selenium IDE 104

。 选择测试全国,在Add Library dialog箱中点击次。

Selenium IDE 105

添加了测试国家图书馆,显示如下。

Selenium IDE 106

Step 7——在建立该项目时,项目的结构如下所示。

Selenium IDE 107

- Right-cpck on src rafter and selected New >> Other。

Selenium IDE 108

Selenium IDE 109

Selenium IDE 110

Step 11——选择包装名称、类别名称和点击Finish。

Selenium IDE 111

一揽子勘探商和创建的班子将展示。

Selenium IDE 112

First Test in TestNG

现在,让我们开始使用测试国家进行描述。 让我们举出我们用来了解网络司机的同样例子。 我们将使用demo应用程序, package TestNG; import java.util.concurrent.TimeUnit; import org.openqa.selenium.*; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; pubpc class TestNGClass { WebDriver driver = new FirefoxDriver(); @BeforeTest pubpc void launchapp() { // Puts an Imppcit wait, Will wait for 10 seconds before throwing exception driver.manage().timeouts().imppcitlyWait(10, TimeUnit.SECONDS); // Launch website driver.navigate().to("http://www.calculator.net"); driver.manage().window().maximize(); } @Test pubpc void calculatepercent() { // Cpck on Math Calculators driver.findElement(By.xpath(".//*[@id= menu ]/span[3]/a")).cpck(); // Cpck on Percent Calculators driver.findElement(By.xpath(".//*[@id= menu ]/span[4]/span[3]/a")).cpck(); // Enter value 10 in the first number of the percent Calculator driver.findElement(By.id("cpar1")).sendKeys("10"); // Enter value 50 in the second number of the percent Calculator driver.findElement(By.id("cpar2")).sendKeys("50"); // Cpck Calculate Button driver.findElement(By.xpath(".//*[@id= content ]/table/tbody/tr/td[2]/input")).cpck(); // Get the Result Text based on its xpath String result = driver.findElement(By.xpath(".//*[@id= content ]/p[2]/span/font/b")).getText(); // Print a Log In message to the screen System.out.println(" The Result is " + result); if(result.equals("5")) { System.out.println(" The Result is Pass"); } else { System.out.println(" The Result is Fail"); } } @AfterTest pubpc void terminatetest() { driver.close(); } }

Execution

为了执行,正确点击创建的XML,并选择“Run As” >>“试验NG Suite”

Selenium IDE 189

Result Analysis

产出被扔到ole子里,结果如下所示。 假释产出也有执行摘要。

Selenium IDE 114

也可从不同的表格中看到全国测试的结果。 传真报告显示 观点,见下文。

Selenium IDE 115

超文本结果如下所示。

Selenium IDE 117

Selenium - Grid

氯胺醇是一种工具,通过多种物理或虚拟机器传播测试,以便我们能够同时(同时)执行文字。 它通过向我们提供迅速和准确的反馈,大大加快了各行凶者和平台之间的测试过程。

Selenium Grid允许我们同时进行多种网络驱动器或Selenium遥控检测,同时使用相同的代码基数,因此该代码需要在其所实施的系统中出现NOT。 se-服务器独立包包括湖、网络驱动器和Selenium RC,以实施电网的文字。

Selenium Grid有一个枢纽和一个 No。

    也可将该中心视为一个服务器,作为触发测试的中心点。 A Selenium Grid只有一个湖,一度用一台机器发射。

    <Node-Nodes是湖中负责执行测试的ium。 一个或一个以上的节点可以由任何顾问组成,并可包含任何支持的浏览器。

Architecture

以下图表显示了Selenium Grid的结构。

selenium_ide_121

Working with Grid

为了与格里德合作,我们需要遵循某些议定书。 下文列出参与这一进程的主要步骤——

    Configuring the Hub

    Configuring the Nodes

    Develop the Script and Prepare the XML File

    Test Execution

    Result Analysis

让我们详细讨论这些步骤。

Configuring the Hub

。 如下文所示,通过点击版本下载。

selenium_ide_45

Step 2——利用以下指挥发射Selenium服务器,从湖开始。 现在,我们将利用4444号港口开始该枢纽。

java -jar selenium-server-standalone-2.25.0.jar -port 4444 -role hub -nodeTimeout 1000
selenium_ide_122

Step 3——现在开放浏览器和浏览器进入URL http/ localhost:444444 from the Hub (The system where 你已执行第2步)。

selenium_ide_123

Step 4——现在点击了Cesole链接,点击电汇。 该中心的配置如下。 时至现在,我们没有任何节点,因此我们无法看到细节。

selenium_ide_124

Configuring the Nodes

Fox 采用以下指挥系统。

java -jar D:JARselenium-server-standalone-2.42.2.jar
   -role node -hub http://10.30.217.157:4444/grid/register
   -browser browserName = firefox -port 5555

如果有,

D:JARselenium-server-standalone-2.42.2.jar = Location of the Selenium Server Standalone Jar File(on the Node Machine)

http://10.30.217.157:4444 = IP Address of the Hub and 4444 is the port of the Hub

browserName = firefox (Parameter to specify the Browser name on Nodes)

5555 = Port on which Firefox Node would be up and running.

selenium_ide_125

Step 3——在指挥执行后,返回湖区。 纳维特里-URL-http://10.30.217.157:44 而湖现在将展示其附属的节点。

selenium_ide_126

Step 4——现在让我们发射因特网探索者Node。 为了启动国际电子数据交换台,我们需要将因特网探索者驾驶员下载到点末机上。

下载因特网探索者驱动器,浏览到 并下载根据贵处结构编制的适当文件。 在你下载后,把前案卷和排在案号上,必须提一下。

selenium_ide_131

C:>java -Dwebdriver.ie.driver = D:IEDriverServer.exe
   -jar D:JARselenium-server-standalone-2.42.2.jar
   -role webdriver -hub http://10.30.217.157:4444/grid/register
   -browser browserName = ie,platform = WINDOWS -port 5558

如果有,

D:IEDriverServer.exe = The location of the downloaded the IE Driver(on the Node Machine)

D:JARselenium-server-standalone-2.42.2.jar = Location of the Selenium Server Standalone Jar File(on the Node Machine)

http://10.30.217.157:4444 = IP Address of the Hub and 4444 is the port of the Hub

browserName = ie (Parameter to specify the Browser name on Nodes)

5558 = Port on which IE Node would be up and running.

selenium_ide_127

Step 7——执行指挥后,返回湖区。 纳维特里-URL-http://10.30.217.157:44 湖现在将展示附属于它的伊埃诺德。

selenium_ide_128

我们现在要发射 Chrome。 为了启动“诺德”号,我们需要把“ Chrome”号驱动器下载到代号机器上。

接着向第三方Browser司机区航行,并点击第2.10版,如下所示。

selenium_ide_132

<Step 10——根据你的职业介绍所的类型下载驾驶员。 我们将在视窗环境中执行,因此我们将下载视窗 Chrome司机。 在你下载后,将前案卷解冻,并把它放在发射小.时必须提及的夹中。

selenium_ide_133

Step 11——利用以下指挥发射 Chrome。

C:>java -Dwebdriver.chrome.driver = D:chromedriver.exe 
   -jar D:JARselenium-server-standalone-2.42.2.jar 
   -role webdriver -hub  http://10.30.217.157:4444/grid/register 
   -browser browserName = chrome, platform = WINDOWS -port 5557

如果有,

D:chromedriver.exe = The location of the downloaded the chrome Driver(on the Node Machine)

D:JARselenium-server-standalone-2.42.2.jar = Location of the Selenium Server Standalone Jar File(on the Node Machine)

http://10.30.217.157:4444 = IP Address of the Hub and 4444 is the port of the Hub

browserName = chrome (Parameter to specify the Browser name on Nodes)

5557 = Port on which chrome Node would be up and running.

selenium_ide_129

Step 12——在指挥执行后,返回湖区。 纳维特里-URL-http://10.30.217.157:44 湖现在将展示其附属的神hr。

selenium_ide_130

Develop the Script and Prepare the XML File

我们将利用全国测验小组进行试验。 在以下例子中,我们将利用远程网络驱动器发射每个浏览器。 它可以将其能力传给驾驶员,以便司机掌握在诺德实施的一切信息。

Browser 参数将从“XML”档案中删除。

package TestNG;

import org.openqa.selenium.*;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.DesiredCapabipties;

import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import java.net.URL;
import java.util.concurrent.TimeUnit;
import java.net.MalformedURLException;

pubpc class TestNGClass {
   pubpc WebDriver driver;
   pubpc String URL, Node;
   protected ThreadLocal<RemoteWebDriver> threadDriver = null;
   
   @Parameters("browser")
   @BeforeTest
   pubpc void launchapp(String browser) throws MalformedURLException {
      String URL = "http://www.calculator.net";
      
      if (browser.equalsIgnoreCase("firefox")) {
         System.out.println(" Executing on FireFox");
         String Node = "http://10.112.66.52:5555/wd/hub";
         DesiredCapabipties cap = DesiredCapabipties.firefox();
         cap.setBrowserName("firefox");
         
         driver = new RemoteWebDriver(new URL(Node), cap);
         // Puts an Imppcit wait, Will wait for 10 seconds before throwing exception
         driver.manage().timeouts().imppcitlyWait(10, TimeUnit.SECONDS);
         
         // Launch website
         driver.navigate().to(URL);
         driver.manage().window().maximize();
      } else if (browser.equalsIgnoreCase("chrome")) {
         System.out.println(" Executing on CHROME");
         DesiredCapabipties cap = DesiredCapabipties.chrome();
         cap.setBrowserName("chrome");
         String Node = "http://10.112.66.52:5557/wd/hub";
         driver = new RemoteWebDriver(new URL(Node), cap);
         driver.manage().timeouts().imppcitlyWait(10, TimeUnit.SECONDS);
         
         // Launch website
         driver.navigate().to(URL);
         driver.manage().window().maximize();
      } else if (browser.equalsIgnoreCase("ie")) {
         System.out.println(" Executing on IE");
         DesiredCapabipties cap = DesiredCapabipties.chrome();
         cap.setBrowserName("ie");
         String Node = "http://10.112.66.52:5558/wd/hub";
         driver = new RemoteWebDriver(new URL(Node), cap);
         driver.manage().timeouts().imppcitlyWait(10, TimeUnit.SECONDS);
         
         // Launch website
         driver.navigate().to(URL);
         driver.manage().window().maximize();
      } else {
         throw new IllegalArgumentException("The Browser Type is Undefined");
      }
   }
   
   @Test
   pubpc void calculatepercent() {
      // Cpck on Math Calculators
      driver.findElement(By.xpath(".//*[@id =  menu ]/span[3]/a")).cpck();     	
      
      // Cpck on Percent Calculators
      driver.findElement(By.xpath(".//*[@id =  menu ]/span[4]/span[3]/a")).cpck();
      
      // Enter value 10 in the first number of the percent Calculator
      driver.findElement(By.id("cpar1")).sendKeys("10");
      
      // Enter value 50 in the second number of the percent Calculator
      driver.findElement(By.id("cpar2")).sendKeys("50");
      
      // Cpck Calculate Button
      // driver.findElement(By.xpath(".//*[@id =  content ]/table/tbody/tr/td[2]/input")).cpck();
      // Get the Result Text based on its xpath
      String result =
         driver.findElement(By.xpath(".//*[@id =  content ]/p[2]/span/font/b")).getText();
      
      // Print a Log In message to the screen
      System.out.println(" The Result is " + result);
      
      if(result.equals("5")) {
         System.out.println(" The Result is Pass");
      } else {
         System.out.println(" The Result is Fail");
      }
   }
   
   @AfterTest
   pubpc void closeBrowser() {
      driver.quit();
   }
}

将通过XML。 在该项目下设立一个XML。

selenium_ide_134

selenium_ide_135

查阅档案并点击Finish。

selenium_ide_136

Step 5——测试Ng.XML是根据项目夹创建的,如下所示。

selenium_ide_137

XML档案的内容如下。 我们制造了3个试验,并将其放在一起,并提到平行的“试验”,以便所有试验都同时进行。

<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name = "Suite" parallel = "tests">

   <test name = "FirefoxTest">
   <parameter name = "browser" value = "firefox" />
      <classes>
         <class name = "TestNG.TestNGClass" />
      </classes>
   </test>

   <test name = "ChromeTest">
   <parameter name = "browser" value = "chrome" />
      <classes>
         <class name = "TestNG.TestNGClass" />
      </classes>
   </test>

   <test name = "IETest">
   <parameter name = "browser" value = "ie" />
      <classes>
         <class name = "TestNG.TestNGClass" />
      </classes>
   </test>
   
</suite>

Test Execution

Step 1——选择创建的XML;右翼和选择Rong As >> 测试NG Suite。

selenium_ide_139

我们现在开放诺德,我们在那里启动了所有浏览器点。 你们将看到所有三个浏览器同时执行。

selenium_ide_140

Result Analysis

Step 1——在完成执行时,我们可以分析结果,如任何其他执行。 定本摘要载于下文摘要。

selenium_ide_142

<2>Step 2-Nagate to the Results of Running Suite Tab and TestNG将显示以下结果摘要。

selenium_ide_141

Step 3——在生成超文本时,我们将能够以超文本格式看到测试结果。

selenium_ide_143
Advertisements