package com.guoyasoft.autoUI.guoya_1810;
//引入 java代码路径
import com.guoyasoft.autoUI.common.BaseUI;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
import org.testng.Assert;
import org.testng.annotations.Test;
public class GuoyaLogin extends BaseUI {
//public 公开的方法 void 无返回 login() 方法名
//实例变量/全局变量 或者用private私有的
public String username="guoya295";
public String password="qweasd";
public String realname="黄哈哈";
public String phone="18916968152";
public String age="25";
public String users []={
"ye008",
"ye007",
"ye006",
"ye005"
};
//添加testng 注解用来执行测试方法
@Test
public void login(){
//设置循坏 起始值,最大值/最小值 增量,减量
// for(int i=0; i<users.length; i++ ) {i
//System.out.println("当前循环次数" );
sleep(1000);
//打开登录网页
//driver.get("http://47.98.226.232:8080/guoya-medium/jsp/user/login.jsp");
driver.get("http://47.98.226.232:8080/guoya-medium/jsp/user/login.jsp");
//线程休眠
sleep(1000);
//查找元素根据name查找 然后执行清除
driver.findElement(By.name("userName")).clear();
//查找元素根据name查找 执行输入
driver.findElement(By.name("userName")).sendKeys(users[0]);
//查找元素根据id查找 然后执行清除
driver.findElement(By.id("password")).clear();
//查找元素根据id查找 执行输入
driver.findElement(By.id("password")).sendKeys(password);
//查找元素根据xpath查找验证码 执行输入
//driver.findElement(By.xpath("//input[@name='checkCode']")).sendKeys("12345");封装写法
send("//input[@name='checkCode']","12345");
//查找元素根据xpath查找 点击登录
click("//input[@id='loginBtn']");
//queryalluser();
//调用自定义方法
//queryuser();
//queryage();
queryeducation("大专");
//boolean 布尔类型 true真 false假
//boolean guoya =driver.getPageSource().contains("学生查询");
//assert断言 判断预期结果与实际结果是否相等
//Assert.assertEquals(guoya,true,"用户登录页面失败");
queryuser(users[0]);
//切换iframe窗口至结果展示窗口
//driver.switchTo().frame("result");
//判断切换结果展示页面是否包含查询用户
// Assert.assertEquals(driver.getPageSource().contains(users[0]),true);
//打印新的页面代码
//System.out.println(driver.getTitle());
//切换回默认窗口
//driver.switchTo().defaultContent();
// }
}
@Test
public void signup() {
//最小值,最大值,增量,判断条件
int i = 0;
//条件成立则一直执行循环,条件不满足结束
while (i < 10){
//boolean result;
//while (result=true) {
//打开注册网页
driver.get("http://47.98.226.232:8080/guoya-medium/jsp/user/signUp.jsp");
sleep(1000);
WebElement element = driver.findElement(By.id("userName"));
element.clear();
element.sendKeys(username);
driver.findElement(By.id("realName")).sendKeys(realname);
driver.findElement(By.id("password")).sendKeys(password);
driver.findElement(By.id("password2")).sendKeys(password);
driver.findElement(By.id("phone")).sendKeys(phone);
driver.findElement(By.id("age")).sendKeys(age);
driver.findElement(By.xpath("//input[@id='checkCode']")).sendKeys("1234");
//点击注册
driver.findElement(By.xpath("//input[@id='submitBtn']")).click();
//弹出弹窗 是否确定
Alert alert = driver.switchTo().alert();
alert.accept();
//alert.dismiss();
//boolean result = driver.getPageSource().contains("登录界面");
//如果条件为真 打印注册成功
// if (result == true) {
// System.out.println("用户注册成功");
//否则就是注册失败
// } else {
// System.out.println("用户注册失败");
// }
// result=driver.getPageSource().contains("登录界面");
//System.out.println("注册成功");
//}
i++;
System.out.println("当前循环次数" + i);
}
}
//全部查询
public void queryalluser(){
driver.findElement(By.xpath("//input[@type='submit']")).click();
sleep(3000);
}
public void queryuser(String name){
driver.findElement(By.xpath("//input[@name='userName']")).sendKeys(name);
driver.findElement(By.xpath("//input[@type='submit']")).click();
sleep(3000);
}
public void queryage(){
driver.findElement(By.xpath("//input[@name='userName']")).clear();
driver.findElement(By.xpath("(//input[@type='number'])[1]")).sendKeys(age);
driver.findElement(By.xpath("(//input[@type='submit'])")).click();
sleep(3000);
driver.findElement(By.xpath("//input[@name='userName']")).clear();
driver.findElement(By.xpath("(//input[@type='number'])[1]")).sendKeys(age);
driver.findElement(By.xpath("(//input[@type='submit'])")).click();
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)).sendKeys(sendkey);
}
public void queryage(String age){
driver.findElement(By.xpath("(//input[@type='number'])[1]")).clear();
driver.findElement(By.xpath("(//input[@type='number'])[1]")).sendKeys("28");
driver.findElement(By.xpath("//input[@type='submit']")).click();
}
public void queryeducation(String education){
//使用findelement查找select元素 使用Webelement 对象声明的变量进行保存
WebElement element= driver.findElement(By.xpath("//select[@name='education']"));
//新建一个selenium 下拉框处理对象 Select进行处理下拉框 使用需要传参 传参为 定位的select下拉框
Select select=new Select(element);
select.selectByVisibleText(education);
click("//input[@type='submit']");
}
//public void id(String id,String realname){
// driver.findElement(By.id(id)).sendKeys(realname);
//}
@Test
//加减乘除法
public void demol(){
sum(8,10);
sub(20,5);
mult(10,10);
div(100,5);
}
public static void sum(int a,int b){
int c=0;
c=a+b;
System.out.println("加法计算结果是"+c);
}
public static void sub(int a, int b){
int c=0;
c=a+b;
System.out.println("减法的计算结果是"+c);
}
public static void mult(int a,int b){
int c=0;
c=a*b;
System.out.println("乘法计算结果是"+c);
}
public static void div(int a,int b){
int c=0;
c=a/b;
System.out.println("除法计算结果是"+c);}
}
package com.guoyasoft.autoUI.guoya_1810;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.testng.annotations.Test;
/**
* @program: guoya-test
* @description:
* @author: Administrator
* @create: 2018-11-16 15:58
**/
public class Deom {
public String users [] []={
{"ye008","qwe129"},
{"ye007","qwe128"},
{"ye006","qwe127"},
{"ye005","qwe167"}
};
@Test
public void demol (){
System.out.printf(users[0][1]);
}
@Test
public void list(){
//创建一个list列表
List<String> list=new ArrayList<String>();
//列表添加数据 list.add();
list.add("某某某");
list.add("哈哈哈");
System.out.println(list.get(1));
System.out.println(list.get(2));
}
@Test
public void map(){
//Map 用来存储键值对数据 去数据通过键来取值
Map<String,Integer> m= new HashMap<String,Integer>();
m.put("张飞",22);
m.put("呼呼",21);
System.out.println("呼呼的年龄是"+m.get("呼呼"));
}
}