2018-11-19ui自动化

2018-11-20  本文已影响0人  凡星点点5

@DataProvider参数化注解

@Parameters通过xml配置文件参数化

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="suite1"><!-- 测试套件,里面允许有多个测试集-->
    <test name="test0"  enabled="true"><!-- 测试集-->
        <parameter name="url" value="http://47.98.226.232:8080/guoya-medium/jsp/user/login.jsp"/>
        <!-- 传参格式通过添加<parameter name="变量名" value="变量值">节点传参给类-->
        <parameter name="username" value="zhouA031"/>
        <parameter name="password" value="qweasd"/>
        <parameter name="realname" value="周周"/>
        <parameter name="userpath" value="//input[@name='userName']"/>
        <parameter name="passpath" value="//input[@name='password']"/>
        <parameter name="submitpath" value="//input[@id='loginBtn']"/>
                <classes>
            <class name="com.guoyasoft.autoUI.GuoyaTest1810.parameter">
                <methods>
                    <include name="parameter" />
                </methods>
            </class>
        </classes>
    </test>
</suite>

parameter配置

package com.guoyasoft.autoUI.GuoyaTest1810;


import com.guoyasoft.autoUI.common.BaseUI;
import org.openqa.selenium.By;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class parameter  extends BaseUI {
    @Test
    @Parameters({"url","username","password","realname"})

    public  void parameter(String url,String username,String password,String realname){
      //"http://47.98.226.232:8080/guoya-medium/jsp/user/login.jsp"
      driver.get(url);
      driver.findElement(By.xpath("//input[@name='userName']")).sendKeys(username);
      driver.findElement(By.xpath("//input[@name='password']")).sendKeys(password);
      driver.findElement(By.xpath("//input[@id='checkCode']")).sendKeys("1234");
      driver.findElement(By.xpath("//input[@id='loginBtn']")).click();
      driver.findElement(By.name("realName")).clear();
      driver.findElement(By.name("realName")).sendKeys(realname);
      driver.findElement(By.xpath("//input[@value='查询']")).click();
      sleep(1000);
    }

}

live templates

14245353-dba1dbbf6e80cefd.png

return

@Test
  public  void  deomeo(){
    int result;
    result=sum(10,15);
    System.out.println("计算a+b的返回值"+result);
    int sum2;
    sum2=result+10;
    System.out.println("计算result+10的结果"+sum2);
    int sub;
    sub=sub(50,10);
    System.out.println("减法计算结果"+sub);
    int chengfa;
    chengfa=Double(10,20);
    System.out.println("乘法计算结果"+chengfa);
    int chufa;
    chufa=chufa(10,2);
    System.out.println("除法计算结果"+chufa);
    int jiacheng;
    jiacheng=bbb(10,10,10);
    System.out.println("加法和乘法"+jiacheng);
    int hunhe;
    hunhe=ccc(10,10,10,2);
    System.out.println("加法,乘法,除法"+hunhe);
  }
  
  public  static int sum (int a,int b){
    int c=0;
    c=a+b;
    System.out.println("加法计算结果"+c);
    return c;
  }
  public  static int  sub(int a,int b){
    int c=0;
    c=a-b;
    System.out.println("减法计算结果"+c);
    return  c;
  }
  public  static  int   Double(int a,int b){
    int c=0;
    c=a*b;
    System.out.println("乘法计算结果"+c);
    return c;
  }
  public  static  int  chufa(int a,int b){
  int c=0;
  c=a/b;
    System.out.println("除法计算结果"+c);
    return  c;
  }
  public  static  int  bbb(int a,int b,int c){
  int d=0;
  d=(a+b)*c;
    System.out.println("(a+b)再乘以c的结果"+d);
    return d;
  }
  public  static  int ccc(int a,int b,int c, int d){
  int e=0;
  e=((a+b)*c)/d;
    System.out.println("(a+b)的结果乘以c,再除以d的结果"+e);
    return e;
  }
14245353-05399395e591c03b.png
上一篇下一篇

猜你喜欢

热点阅读