Appium basic UI check cases_from sample

@Test

public void testUIComputation() throws Exception {

// populate text fields with values

populate();

// trigger computation by using the button

//点击控件计算两个数的和

WebElement button = driver.findElement(By.className("UIAButton"));

button.click();

// is sum equal ?

//判断得到的数是否和正确的和相等

WebElement texts = driver.findElement(By.className("UIAStaticText"));

assertEquals(String.valueOf(values.get(0) + values.get(1)), texts.getText());

}

@Test

public void testBasicAlert() throws Exception {

//点击alert控件,弹出提示框

driver.findElement(By.xpath("//UIAButton[2]")).click();

Alert alert = driver.switchTo().alert();

//check if title of alert is correct

//验证提示框文字是否正确

assertEquals("Cool title this alert is so cool.", alert.getText());

alert.accept();

}

@Test

public void testBasicButton() throws Exception {

// 验证求和 button文字显示是否正确

WebElement button = driver.findElement(By.xpath("//UIAButton[1]"));

assertEquals("Compute Sum", button.getText());

}

@Test

public void testClear() throws Exception {

//验证编辑框输入清空后编辑框内容是否为空

WebElement text = driver.findElement(By.xpath("//UIATextField[1]"));

text.sendKeys("12");

text.clear();

assertEquals("", text.getText());

}

@Test

public void testHideKeyboard() throws Exception {

//编辑框输入文字

driver.findElement(By.xpath("//UIATextField[1]")).sendKeys("12");

//确认键盘是否弹出

WebElement button = driver.findElement(MobileBy.AccessibilityId("Done"));

assertTrue(button.isDisplayed());

//点击隐藏键盘

button.click();

}

@Test

public void testFindElementByClassName() throws Exception {

Random random = new Random();

//通过classname定位控件测试

WebElement text = driver.findElementByClassName("UIATextField");

int number = random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM;

text.sendKeys(String.valueOf(number));

driver.findElementByClassName("UIAButton").click();

// is sum equal ?

//验证是否相等

WebElement sumLabel = driver.findElementByClassName("UIAStaticText");

assertEquals(String.valueOf(number), sumLabel.getText());

}

@Test

public void testFindElementsByClassName() throws Exception {

Random random = new Random();

//通过classname定位控件测试

WebElement text = (WebElement) driver.findElementsByClassName("UIATextField").get(1);

int number = random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM;

text.sendKeys(String.valueOf(number));

driver.findElementByClassName("UIAButton").click();

// is sum equal ?

WebElement sumLabel = (WebElement) driver.findElementsByClassName("UIAStaticText").get(0);

assertEquals(String.valueOf(number), sumLabel.getText());

}

@Test

public void testAttribute() throws Exception {

Random random = new Random();

WebElement text = driver.findElement(By.xpath("//UIATextField[1]"));

//编辑框输入文字

int number = random.nextInt(MAXIMUM - MINIMUM + 1) + MINIMUM;

text.sendKeys(String.valueOf(number));

//验证控件的name,label,value等属性是否和设定的相同,name为IntegerA

assertEquals("IntegerA", text.getAttribute("name"));

assertEquals("TextField1", text.getAttribute("label"));

assertEquals(String.valueOf(number), text.getAttribute("value"));

}

@Test

public void testSlider() throws Exception {

//get the slider

//进度条控件

WebElement slider = driver.findElement(By.xpath("//UIASlider[1]"));

// 查看初始数据是否为50%

assertEquals("50%", slider.getAttribute("value"));

Point sliderLocation = getCenter(slider);

//拖动控件,从中心拖到初始位置

driver.swipe(sliderLocation.getX(), sliderLocation.getY(), sliderLocation.getX()-100, sliderLocation.getY(), 1000);

//验证控件是否归0,不归0?

assertEquals("0%", slider.getAttribute("value"));

}

@Test

public void testLocation() throws Exception {

//验证控件的位置是否为94,122?

WebElement button = driver.findElement(By.xpath("//UIAButton[1]"));

Point location = button.getLocation();

assertEquals(94, location.getX());

assertEquals(142, location.getY());

}

@Test

public void testSessions() throws Exception {

// ?

HttpGet request = new HttpGet("http://localhost:4723/wd/hub/sessions");

@SuppressWarnings("resource")

HttpClient httpClient = new DefaultHttpClient();

HttpResponse response = httpClient.execute(request);

HttpEntity entity = response.getEntity();

JSONObject jsonObject = (JSONObject) new JSONParser().parse(EntityUtils.toString(entity));

String sessionId = driver.getSessionId().toString();

assertEquals(jsonObject.get("sessionId"), sessionId);

}

@Test

public void testSize() {

//验证两个编辑框控件大小是否一致

Dimension text1 = driver.findElement(By.xpath("//UIATextField[1]")).getSize();

Dimension text2 = driver.findElement(By.xpath("//UIATextField[2]")).getSize();

assertEquals(text1.getWidth(), text2.getWidth());

assertEquals(text1.getHeight(), text2.getHeight());

}

时间: 2024-10-11 18:22:43

Appium basic UI check cases_from sample的相关文章

(appium+python)UI自动化_07_UI自动化实例【拼多多搜索商品为例】

前言 初学UI自动化的小伙伴,在配置好appium+python自动化环境后,往往不知道如何下手实现自动化.小编在初期学习的时候也有这种疑惑,在此以拼多多搜索为实例,展示下appium是如何实现自动化的. 前提:已安装配置好appium+python自动化环境 一.连接手机启动app 1,连接手机 -手机USB连接电脑 -手机打开开发者模式.USB调试功能 2,基础信息配置 基础连接信息如下(以微信app为例): 'platformName': 操作平台'deviceName': 设备名称'pl

Basic linux command-with detailed sample

Here I will list some parameters which people use very ofen, I will attach the output of the command with one parameters as well. 1.   Create a new user:useradd Parameter:                                                                               

RobotFramework+Appium实现UI自动化默认清除APP登录状态

这是由于appium启动APP时会自动清除APP本地数据导致的,需要添加一个属性值来控制 noReset=True 原文地址:https://www.cnblogs.com/lv1up/p/11719411.html

(appium+python)UI自动化_10_adb常用命令

前言 adb(Android Debug Bridge)工具是android-sdk里的一个工具,是一个命令行窗口,用于通过电脑端与模拟器或者真实设备交互.在app自动化测试过程中,有时要用到adb命令,但是每次都要百度感觉很是繁琐,故总结了下app自动化过程中几个常用的adb命令. adb常用命令 获取设备号 $ adb devices  下载apk 前提:需下载apk至电脑 $ adb install <电脑apk路径> 卸载apk $ adb uninstall <apk包名>

Entity Framework Tutorial Basics(43):Download Sample Project

Download Sample Project: Download sample project for basic Entity Framework tutorials. Sample project includes SchoolDB.mdf for SQL Server 2012. It also includes SchoolDB.sql script if you are using a different version of SQL Server.

`cocos2dx 非完整` UI解析模块

昨天在cocos2dx的一个群里,遇到一位匿名为x的朋友询问的问题,是关于ui的.他使用c++写了不少的ui封装节点,用来实现游戏中的各种不同效果.然后现在想改用lua,于是尝试使用最小代价去复用自己的代码.当然这个是可以做到的,相信很多人都是知道方法的.今天的这篇文章就来谈谈ui部分的处理以及个人的见解. 我们都知道,cocos2dx引擎提供了ui工具cocostudio.后来改名为cocos engine.这些就不赘述了,很多人都会使用这款工具.新版本的工具我没有使用过,不过我承认是方便了很

ethereumjs/ethereumjs-wallet

Utilities for handling Ethereum keys ethereumjs-wallet A lightweight wallet implementation. At the moment it supports key creation and conversion between various formats. 轻量级钱包实现.目前,它支持各种格式之间的key的创建和转换 It is complemented by the following packages: et

KDE Frameworks 5.14.0 发布

KDE,K桌面环境(Kool Desktop Environment)的缩写.一种著名的运行于 Linux.Unix 以及FreeBSD 等操作系统上的自由图形桌面环境,整个系统采用的都是 TrollTech 公司所开发的Qt程序库(现在属于Digia公司).KDE Linux 操作系统上最流行的桌面环境之一.KDE 是一个网络透明的现代化桌面环境,支持Linux. FreeBSD.Unix.其它类Unix.Mac OS X和微软的Windows.KDE Frameworks 5.14.0 发布

10 Quality Free Flat Icon Sets for Your Designs

Subscribe It’s clear that flat design has gained great popularity in recent years. This is hardly surprising as flat designbrings quite a few artistic and even technical advantages. If you have embraced flat design as a concept, then you are very lik