测试类

1
@Parameters("browser") 定义browser参数。 在测试执行过程中,browser参数具体值由XML文件进行传递。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
......
public class TestNGClass
{
  private WebDriver driver;
  private String URL = "http://www.calculator.net";
     
  @Parameters("browser")
  @BeforeTest
  public void beforeTest(String browser)
  {    
       
   if (browser.equalsIgnoreCase("firefox"))
   {
     System.out.println(" Executing on FireFox");
     //Firefox不需要设置驱动。 webdriver无法打开Firefox时,增加此行代码设定Firefox浏览器的所在路径即可
     System.setProperty("webdriver.firefox.bin""C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
     driver = new FirefoxDriver();
     
   }
   else if (browser.equalsIgnoreCase("chrome"))
   {
     System.out.println(" Executing on CHROME");
     System.setProperty("webdriver.chrome.driver""D:\\chromedriver.exe");
     driver = new ChromeDriver();
 
   }
   else if (browser.equalsIgnoreCase("ie"))
   {
     System.out.println("Executing on IE");
     System.setProperty("webdriver.ie.driver""D:\\IEDriverServer.exe");
     driver = new InternetExplorerDriver();
 
   }
   else
   {
      throw new IllegalArgumentException("The Browser Type is Undefined");
   }
    
     driver.get(URL);
     driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
     driver.manage().window().maximize();  
 }
      
     
  @Test
......
 
  @AfterTest
......
}

  

XML文件

1
parallel:是否多线程并发运行测试。可选项目:false/methods/tests/classes/intances
1
thread-count<br><br><br>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<suite name="TestNGSuite" parallel="tests" thread-count="2">   <!--suite name 自定义的测试集合名称 -->
    <test name="IETest">        <!--test name 定义测试名称 -->
        <parameter name="browers" value="ie">
            <classes>                <!--test name 定义被运行的测试类 -->
                <class name="cn.gloryroad.NewTest" />
            </classes>
        </parameter>
    </test>
 
    <test name="ChromeTest">       
        <parameter name="browers" value="ie">
            <classes>             
                <class name="cn.gloryroad.NewTest" />
            </classes>
        </parameter>
    </test>
 
</suite>

  

通过对XML文件进行右键点击执行脚本,然后选择 'Run As' >> 'TestNG' 方式,如下图所示。

输出

所有的浏览器将平行展开,结果将被打印在控制台上。

如果执行不成功,直接输出 Skips Failures 。可以查看下 测试类文件中的URL、 @Parameters参数 、方法参数  是否写错了

注:对于我们在IE浏览器执行成功确保复选框“启用保护模式”下的“IE选项中的安全选项卡中选中或未在所有区域中未检查。

2.6.2 XML配置:使用testNG进行并发多浏览器测试的更多相关文章

  1. testng.xml 配置大全

    1.TestNG的运行方式如下: 1 With a testng.xml file 直接run as test suite 2 With ant 使用ant 3 From the command li ...

  2. Maven 配置 Selenium + testNG + reportNG 运行环境

    .markdown-preview:not([data-use-github-style]) { padding: 2em; font-size: 1.2em; color: rgb(56, 58, ...

  3. Bean的基于XML配置方式

    基于XML配置 Beans.xml <?xml version="1.0" encoding="UTF-8" ?> <beans xmlns= ...

  4. 基于@AspectJ注解配置切面与基于XML配置切面

    1. Waiter目标类 package com.smart.aop.advice.pointcut; public class Waiter { public void greetTo(String ...

  5. Mybatis XML配置

    Mybatis常用带有禁用缓存的XML配置 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE ...

  6. SpringMvc的xml配置与annotation配置的例子的区别

    1.导入jar包时,要在xml配置基础上加 spring-aop-4.2.2.RELEASE.jar (注解的时候需要) 2.编写controller的时候要annotation需要做相关配置即红色部 ...

  7. Hibernate实现有两种配置,xml配置与注释配置

    hibernate实现有两种配置,xml配置与注释配置. (1):xml配置:hibernate.cfg.xml (放到src目录下)和实体配置类:xxx.hbm.xml(与实体为同一目录中) < ...

  8. java web.xml配置详解

    1.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<context-param>两个结点. 2.紧急着,容创建一个Servl ...

  9. 关于xml配置实现AOP的小知识

    除了前面介绍的基于JDK1.5的注解方式来定义切面,切入点和增强处理外,Spring AOP也允许直接使用XML配置文件来管理它们.在JDK1.5之前,只能使用配置文件的方式来管理,在Spring2. ...

随机推荐

  1. Scala学习六——对象

    一.本章要点 用对象作为但例或存放工具的方法 类可以拥有一个同名的伴生对象 对象可以扩展类或特质 对象的apply方法通常用来构造伴生类的新实例 如果不想显示定义main方法,可以扩展App特质的对象 ...

  2. Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Chinese_PRC_CI_AI" in the equal to operation.

    Executed as user: NT AUTHORITY\SYSTEM. Cannot resolve the collation conflict between "Chinese_P ...

  3. 手把手教你搭建FastDFS集群(下)

    手把手教你搭建FastDFS集群(下) 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/u0 ...

  4. vue中ref-父主动取值值;

    多用月input标签 定义的时候 直接写ref=“id” <el-input placeholder="请输入内容" style="width: 150px&quo ...

  5. HTML的学习2(注释)

    <!--链接标签--> <!--核心属性就是href 属性值可以是一个跳转的地址--> <a href="">可点击的文本</a> ...

  6. 【转】tar命令详解

    原文:http://www.cnblogs.com/qq78292959/archive/2011/07/06/2099427.html tar -c: 建立压缩档案-x:解压-t:查看内容-r:向压 ...

  7. UNetbootin安装linux

    用u盘安装linux系统,最好的方法莫过于用UNetbootin,网址:http://unetbootin.github.io/ UNetbootin allows you to create boo ...

  8. 解决myeclipse没有代码提示的问题

    今天和室友安装了一样的myeclipse版本,结果室友的自动提示功能有,我的输入“.”后却不能提示,这对我们敲代码简直来说是一个折磨,不能自动提示,本来还以为是系统问题,一个是win7,一个是win1 ...

  9. 给Eclipse安装MinGW

    @2019-06-30 [小记] 安装完Eclipse后Toolchains只有Cross GCC,下载安装MinGW后添加系统环境变量即可

  10. 离线(不联网)安装gcc4.8.5

    1 楔子 原来机器gcc版本是4.4.6,不支持cpp11,很麻烦需要升级,但是机器不能连外网,只能离线安装,十分麻烦: 2 gcc4.8.5离线安装,通过rpm包: 资源链接: https://pa ...