2018-11-19ui自动化

@DataProvider参数化注解

  • 配合csv使用批量数据参数化, 通过通过@DataProvider(name=""数据集名称) 注解方法提供数据, 通过 @Text(dataProvider="数据集名称关联配对").
  • 操作步骤


    14245353-217177d8df6d6c63.jpg

    14245353-513097f4823cd602.jpg

    14245353-586a09778ee438ab.jpg

    14245353-8f37410bf1319997.jpg

    14245353-a03e3cfaeeee14ec.jpg

    14245353-c2deaaa3d14f8b97.jpg

    14245353-f27b01e7b29a3d4a.jpg

    14245353-0da5adb429a3472e.jpg

    14245353-da116a6018d86b75.jpg

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

  • 数据与脚本做分离,通过@parameters注解传参,通过xml配置执行脚本
  • xml配置


    
        
        
        
        
        
        
        
        
                
            
                
                    
                
            
        
    

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

  • 打开路径 file-setting-live templates

  • 创建模板组,模板


    14245353-3d5bbc57e1fcee32.png
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

你可能感兴趣的:(2018-11-19ui自动化)