2018-11-15day23java学习

  • 8种基本变量类型

类型 包装类 大小 举例 特殊说明
byte Byte 8位 12
short Short 16位 12345
int Integer 32位 123123123
long Long 64位 234234234324l最后一位是小写的L,标识是long类型
浮点:float Float 32位 234.232f 最后一位是小写的f,标识是float类型
浮点:double Double 64位 23423423.23423424
boolean Boolean 默认与int相同 true/false
  public void basicVarsTest(){
    //布尔类型,一般用来做标识和判断
    boolean result=true;//false
    //数字:整数
    byte b=3;//8位
    short s=1231;//16位
    int i=231231231;//32位
    long l=21312312312222l;//64位,后面带小写的L
    //数字:小数
    float f=23423.23f;//32位,后面带个小写的f
    double d=2342342.23232;//64位
    //字符
    char c='a';//16位
  }
  • 字符型:char
  • 三种容器

数组:根据下标取数据
列表
键值对

  • 引用类型

String:字符串

  • 方法使用

无参:方法()
有参:方法名(参数1,参数2)
有返回值的

        send("//input[@name='realName']",name);
        send("//input[@type='number'][1]",age);
        click("//input[@type='submit']");
        sleep(3000);
    }
    public void click(String xpath){
       driver.findElement(By.xpath(xpath)).click();
    }
    public void send(String xpath,String sendkey){
       driver.findElement(By.xpath(xpath)).clear();
       driver.findElement(By.xpath(xpath)).sendKeys(sendkey);
    }
  • testNG断言

Assert

            boolean guoya = driver.getPageSource().contains("学生查询");
            //获取页面源代码使用contains方法判断是否包含文本内容,是 true 否 false,然后用布尔变量进行存储

            System.out.println("contains判断结果"+driver.getPageSource().contains("学生查询"));
            //assert断言 判断预期结果与实际结果是否相等

            //调用Asser对象.assertEquals方法 判断 实际结果,预期结果是否相等,如果不相等 打印错误信息,抛出异常
            Assert.assertEquals(guoya ,true);         
  • java三大类型

继承:extends
封装:方法封装,类封装
多态

  • ui自动化 iframe切换

switchTo().iframe()

  • idea Debug

添加断点
断点调试
https://www.tapd.cn/tfl/pictures/201811/tapd_63882484_1542279025_46.gif

https://www.tapd.cn/tfl/pictures/201811/tapd_63882484_1542278997_82.gif

  • 总结

import com.google.common.annotations.VisibleForTesting;
import com.guoyasoft.autoUI.common.BaseUI;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.Test;

/**
 * @program: guoya-test.git
 * @description:
 * @author: Administrator
 * @create: 2018-11-13 11:34
 **/
public class GuoyaLogin extends BaseUI {

    //实例变量
    private String username = "guoya718";
    private String password = "qweasd";
    private String age = "32";
    private String realName = "asdfg";
    private String users[] = {"yee08", "yee07", "yee06", "yee05", "yee04", "yee03", "yee02",
        "yee01", "yee00", "yee009"};
//    private System
    //public 公开的方法 void 无返回 login()方法名

    //添加teseng注解用来执行测试方法
    @Test
    public void login() {
        //设置循环 起始值,最大值/最小值,增量,减量
        for (int i = 0; i <users.length; i++) {

            System.out.println("当前循环此时"+i);

            String url = "http://47.98.226.232:8080/guoya-medium/jsp/user/login.jsp";
            driver.get(url);
            //查询元素根据name查找 然后执行清除
            driver.findElement(By.name("userName")).clear();
            //查找元素根据name查找 执行输入
           // driver.findElement(By.xpath("//input[@name='userName']")).sendKeys(users[i]);
            send("//input[@name='userName']",users[i]);
            sleep(1000);
            //driver.findElement(By.id("password")).clear();
            clear("password");
           // driver.findElement(By.id("password")).sendKeys(password);
            pass("password",password);
            sleep(1000);
            driver.findElement(By.xpath("//input[@name='checkCode']")).sendKeys("12345");
            sleep(1000);
            //driver.findElement(By.xpath("//input[@id='loginBtn']")).click();
            click("//input[@id='loginBtn']");
            //String source=driver.getPageSource();
            //boolean 布尔类型 变量类型 true 真 else 假
            boolean guoya = driver.getPageSource().contains("学生查询");
            //assert断言 判断预期结果与实际结果是否相等
            Assert.assertEquals(guoya ,true);
            queryuser();

            sleep(1000);
            //切换iframe窗口至结果展示窗口
            driver.switchTo().frame("result");
            //判断切换结果展示页面是否包含查询用户
           Assert.assertEquals(driver.getPageSource().contains(users[0]),true);
            //打印新的页面源代码
            System.out.println(driver.getPageSource());
            //assert断言 判断预期结果与实际结果是否相等
            //Assert.assertEquals(guoya,true,"用户登录页面失败");
            //切换回默认窗口
            //driver.switchTo().defaultContent();
                //if (guoya==true){
                //    System.out.println("登录成功");
                //}else{
                 //   System.out.println("登录失败");
            //}

            //queryalluser();
            //queryrealname("jiyiang","20");
            //queryrealname("","");
            //queryrealname("","");

        }
    }


    @Test
    public void signup() {
        for (int i = 0; i < users.length; i++) {

            //条件成立测一直执行循环,条件不满足条件结束
            System.out.println("当前循环此时" + users.length);

            driver.get("http://47.98.226.232:8080/guoya-medium/jsp/user/signUp.jsp");

            //清除用户名
            //WebElement element = driver.findElement(By.xpath("//input[@id='userName']"));
            //element.click();
            //element.sendKeys("wzj1234");
            //element.sendKeys("");
            driver.findElement(By.xpath("//input[@id='userName']")).clear();
            driver.findElement(By.xpath("//input[@id='userName']")).sendKeys(users[i]);
            System.out.println("当前用户名为" + users[i]);
            driver.findElement(By.xpath("//input[@id='realName']")).sendKeys(realName);
            System.out.println("当前真实姓名是" + realName);
            driver.findElement(By.xpath("//input[@id='password']")).sendKeys(password);
            driver.findElement(By.xpath("//input[@id='password2']")).sendKeys(password);
            driver.findElement(By.xpath("//input[@id='phone']")).sendKeys("13460235689");
            driver.findElement(By.xpath("//input[@id='age']")).sendKeys("20");
            driver.findElement(By.xpath("//input[@id='checkCode']")).sendKeys("1234");
            driver.findElement(By.xpath("//input[@id='submitBtn']")).click();
            //弹出窗口 是否确定
            driver.switchTo().alert().accept();
            sleep(2000);
            boolean result = driver.getPageSource().contains("登录页面");
            //boolean result=driver.getPageSource().contains("登录界面");
            //如果条件为真 打印注册成功
            //if(result==true){
            //System.out.println("用户注册成功");
            //否侧就是注册失败
            //}else{
            //  System.out.println("用户注册失败");

        }

        //Alert alert = driver.switchTo().alert();
        //alert.accept();
        //alert.dismiss();
        //点击确认


    }

    public void queryalluser() {
        driver.findElement(By.xpath("//input[@type='submit']")).clear();
        driver.findElement(By.xpath("//input[@type='submit']")).click();
        // sleep(5000);
    }

    public void queryuser() {

        driver.findElement(By.xpath("//input[@name='userName']")).clear();
        driver.findElement(By.xpath("//input[@name='userName']")).sendKeys(users[0]);
        driver.findElement(By.xpath("//input[@type='submit']")).click();
        //sleep(5000);
    }

    public void queryage() {

        driver.findElement(By.xpath("//input[@name='userName']")).clear();
        driver.findElement(By.xpath("//input[@type='number'][1]")).clear();
        driver.findElement(By.xpath("//input[@type='number'][1]")).sendKeys(age);
        driver.findElement(By.xpath("//input[@type='submit']")).click();
        // sleep(5000);
    }

    public void queryrealname(String name,String age) {
        driver.findElement(By.xpath("//input[@name='userName']")).clear();
        driver.findElement(By.xpath("//input[@type='number'][1]")).clear();
        driver.findElement(By.xpath("//input[@type='number'][1]")).sendKeys(age);
        driver.findElement(By.xpath("//input[@type='submit']")).click();
    }
    public void click(String xpath){
        driver.findElement(By.xpath(xpath)).click();
    }
    public void send(String xpat,String sendkeys){
        driver.findElement(By.xpath(xpat)).clear();
        driver.findElement(By.xpath(xpat)).sendKeys(sendkeys);
    }
    public void clear(String id){
        driver.findElement(By.id(id)).clear();

    }
    public void pass(String id,String sendKeys) {
        driver.findElement(By.id(id)).sendKeys(sendKeys);
    }


}

调试

思维导图
day23java学习.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,761评论 5 460
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,953评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,998评论 0 320
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,248评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,130评论 4 356
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,145评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,550评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,236评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,510评论 1 291
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,601评论 2 310
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,376评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,247评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,613评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,911评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,191评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,532评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,739评论 2 335

推荐阅读更多精彩内容

  • 一、Java 简介 Java是由Sun Microsystems公司于1995年5月推出的Java面向对象程序设计...
    子非鱼_t_阅读 4,134评论 1 44
  • 1. 思考 因为人员有限,从去年到现在有半年多的时间,我们一直苦于怎么做好可视化运维这块。期间尝试了很多技术方案,...
    空灵一月阅读 238评论 2 0
  • 一首歌,历经多年以后,仍然能够让人常常记起,并且能够广为传唱,应该就是经典之作! 这样的歌很不容易找到。...
    金永辉煌阅读 735评论 4 4
  • 关于Anaconda的介绍百度一对,这里只记录一下自己在使用过程中碰到的坑。Anaconda主要目的是在创建一个虚...
    冰西瓜大郎阅读 1,611评论 0 0
  • 夜幕初上,灯火林立,涌上心头的更多的是思念。
    糯米团子001阅读 201评论 0 1