- Selenium - Grid
- Selenium - TestNG
- Selenium - Test Design Techniques
- Selenium - User Interactions
- Selenium - Locators
- Selenium - WebDriver
- Selenium - Selenese Commands
- Selenium - Remote Control
- Selenium - Environment Setup
- Selenium - IDE
- Selenium - Overview
- Selenium - Home
Selenium Useful Resources
- Selenium - Discussion
- Selenium - Automation Practice
- Selenium - Useful Resources
- Selenium - Quick Guide
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Selenium - Quick Guide
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 | 本节论述如何下载和配置民主选举学会。 |
2 | 本节述及《欧洲经典》中的现有特征。 |
3 | 本节论述如何利用录制特征进行民主选举学会测试。 |
4 | 本节述及硫化物代谢。 |
5 | 本节说明如何在《国际功能汇编》中插入核查点。 |
6 | 本节论述如何利用民主选举学会定期表达方式。 |
7 | Java版使用户能够定制或增加新的功能。 |
8 | 本节论述如何执行不同浏览器的硫化物。 |
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
Step 3——选择“Accept License Agreement”无线电台。
Step 4——选择适当的安装。 此处为Windows 7-64 bit。 Cpck the appropriatepnk and Save the .exe file to You之盘。
Step 5——操作下载的外壳,发射印章。 接下来将继续进行。
为了与Selenium RC或网络司机合作,我们需要根据他们的XPath或ID或名称等确定内容。 为了确定一个要素,我们需要工具/工具。 Step 3——安装后,我们可以通过浏览到“网络开发商”和“Firebug”的线索来启动该图。 Step 4-Path, 一种在火烧中工作的假肢,有助于用户 gr除一个元素的XPath。 InstallfirePath by navigating to “ Step 6——现在发射“Firebug”,途径是“Tools”和“Tools”;“Webdeveloper”和“Webdeveloper”;和“Firebug”。 现在,让我们理解如何以实例使用火焰和火焰。 为了示范,我们将使用www.google.com,并掌握“google.com”文本箱的特性。 Step 1——首先点击以下屏幕上强调的箭板,并将其拖到我们想要捕获的物体上。 该物体的超文本/DOM将显示如下。 我们能够抓住我们能够互动的投入文本箱。 Cpck the Spy icon. Select the Control for which we would pke to capture the XPath. XPath of the selected control would be generated. 现在,我们应研究如何召集对塞伦ium的遥控。 我们将理解如何在以后各章中与塞伦特驻地协调员编写文字,但现在我们将只了解其中的内容。 Step 2——下载后,我们需要开始服务器。 为了做到这一点,公开指挥迅速,与被下载的JAR档案保存的夹一道航行如下。 现在,让我们考虑如何召集Selenium网络司机。 我们将理解如何在以后各章中与Selenium网络驱动器一道编写文字,但现在我们将只了解其配置部分。 锡伦ium遥控(RC)是主要塞伦ium项目,在Selenium网络开动器(2.0版)建立之前很久一直存在。 如今,由于网络驱动器提供更强有力的特征,因此很难使用Selenium RC,但用户仍然能够继续使用驻地协调员制作文字。 它使我们能够在 programming、C#、Perl、Alex和PHP等方案拟订语言的全部力量的帮助下,撰写自动网络应用标准测试,以创建更为复杂的测试,如阅读和写作档案、查询数据库和电子邮件测试结果。 冶金公司的工作方式是,客户图书馆能够与SeleniumRC服务器进行沟通,通过每一台Selenium公司执行。 然后,服务器使用Selenium-Core Java成文指令将Selenium的指挥权交给浏览器。 浏览器使用其贾瓦文译员执行Selenium指挥部。 硫酸 RC有两部分。 Sel服务器发射和杀灭菌器。 除此之外,它还解释和执行塞伦斯指挥部。 它还充当吉卜赛人协会的代理人,拦截并核实在浏览器和测试申请之间传递的吉卜赛人协会的信息。Download and Configure Ecppse
Configure FireBug and FirePath
Example
Configure Selenium RC
Configure Selenium WebDriver
Selenium - Remote Control
What is Selenium RC?
Selenium RC Architecture
用户图书馆提供方案拟定语文之一(Java、C#、Perl、Alex和PHP)和Selenium-RC服务器之间的接口。
RC Scripting
现在,让我们用Selenium遥控书写样本。 让我们利用
<4>Step——核查来源、项目、图书馆和产出夹,并点击Finish。
Step 5——在项目集装箱上点击并选择“建筑通道”。
<6Step 6 - Property for selrcdemo opens up. 5. 外包联合调查。 选择我们下载的Selenium RC jar文档,该档案将显示如下。
Step 8——通过右侧点击弧夹和选择新产品;及
Step 10——创建的班级是按如下所示的组合结构建立的。
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 - Selenese Commands
指挥是指ium必须做些什么, command的指挥分为三类。 每一方的浮标都更多地了解指挥。
Locators
配制器帮助 Sel确定指挥提到的超文本部分。 所有这些定位器都可以在WirePath和WireBug plugin公司的帮助下找到。 请参阅《环境设定》关于细节的章节。
识别剂 = id 选择特定“id”属性,如无对应关系,则选择“姓名属性”的第一个要素。
id = id 选择特定“id”属性。
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 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
让我们理解如何与网络司机合作。 为了示范,我们将使用
<21>Step 2——通过点击Browse Button选择工作空间。
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。
Step 7——现在右翼插在包裹上,选择新到;>等级创建一类。
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(); } }
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(密度)的帮助下,采用发送钥匙方法进入正文箱。
driver.findElement(By.id("cdensity")).sendKeys("10");
By Name
这里,在姓名的帮助下,可以找到物体。 在这种情况下,它是案文箱的名称。 数值在ID(密度)的帮助下,采用发送钥匙方法进入正文箱。
driver.findElement(By.name("cdensity")).sendKeys("10");
By Class Name
这里有一个物体在地名的帮助下进入。 在这种情况下,是网络名称。 该数值可在文本方法的帮助下获得。
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
这种方法有助于找到与可见文本相匹配的联系要素。
driver.findElements(By.pnkText("Volume")).cpck();
By partial pnk text
这种方法有助于找到一个与部分相匹配的明显文本相联的内容。
driver.findElement(By.partialLinkText("Volume")).cpck();
By CSS
中央安全局被用作确定目标的方法,但NOT所有浏览器都支持特别安全局的识别。
WebElement loginButton = driver.findElement(By.cssSelector("input.login"));
By XPath
XPath为XML道路语言。 这是选用XML文件节点语。 XPath基于XML文件的树木代表性,通过使用各种标准选择子,提供在树木周围航行的能力。
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
Step 7——“接受许可协议”和点击Finish。 Step 8——检测全国开始安装,进展如下: Step 9——由于无法确定软件的有效性,安全警报波及。 Cpck Ok。 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
测试小组通过研究说明确定它感兴趣的方法。 因此,方法名称不局限于任何模式或格式。 我们可以通过附加参数说明。Annotations in TestNG
说明被严格分类,因此汇编者将指明任何错误。
不再需要为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项目,如下所示。
Step 7——在建立该项目时,项目的结构如下所示。 Step 11——选择包装名称、类别名称和点击Finish。 现在,让我们开始使用测试国家进行描述。 让我们举出我们用来了解网络司机的同样例子。 我们将使用demo应用程序, <Node-Nodes是湖中负责执行测试的ium。 一个或一个以上的节点可以由任何顾问组成,并可包含任何支持的浏览器。First Test in TestNG
Architecture
以下图表显示了Selenium Grid的结构。
Working with Grid
为了与格里德合作,我们需要遵循某些议定书。 下文列出参与这一进程的主要步骤——
Configuring the Hub
Configuring the Nodes
Develop the Script and Prepare the XML File
Test Execution
Result Analysis
让我们详细讨论这些步骤。
Configuring the Hub
Step 2——利用以下指挥发射Selenium服务器,从湖开始。 现在,我们将利用4444号港口开始该枢纽。
Step 3——现在开放浏览器和浏览器进入URL http/ localhost:444444 from the Hub (The system where 你已执行第2步)。 Step 4——现在点击了Cesole链接,点击电汇。 该中心的配置如下。 时至现在,我们没有任何节点,因此我们无法看到细节。 如果有, 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. Step 3——在指挥执行后,返回湖区。 纳维特里-URL-http://10.30.217.157:44 而湖现在将展示其附属的节点。 Step 4——现在让我们发射因特网探索者Node。 为了启动国际电子数据交换台,我们需要将因特网探索者驾驶员下载到点末机上。 如果有, 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. Step 7——执行指挥后,返回湖区。 纳维特里-URL-http://10.30.217.157:44 湖现在将展示附属于它的伊埃诺德。 <Step 10——根据你的职业介绍所的类型下载驾驶员。 我们将在视窗环境中执行,因此我们将下载视窗 Chrome司机。 在你下载后,将前案卷解冻,并把它放在发射小.时必须提及的夹中。 Step 11——利用以下指挥发射 Chrome。 如果有, 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. Step 12——在指挥执行后,返回湖区。 纳维特里-URL-http://10.30.217.157:44 湖现在将展示其附属的神hr。 Browser 参数将从“XML”档案中删除。 Step 5——测试Ng.XML是根据项目夹创建的,如下所示。 Step 1——选择创建的XML;右翼和选择Rong As >> 测试NG Suite。 Step 1——在完成执行时,我们可以分析结果,如任何其他执行。 定本摘要载于下文摘要。 <2>Step 2-Nagate to the Results of Running Suite Tab and TestNG将显示以下结果摘要。 Step 3——在生成超文本时,我们将能够以超文本格式看到测试结果。
java -jar selenium-server-standalone-2.25.0.jar -port 4444 -role hub -nodeTimeout 1000
Configuring the Nodes
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
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
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
Develop the Script and Prepare the XML File
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 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
Result Analysis