2018-11-13UI自动化

day21UI自动化.png
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<!--suite 代表软件-->
<suite name="suit1">
        <!--test 代表测试用例集-->
    <test name="test0" preserve-order="true" enabled="true">
            <!--classes 代表类集合可以执行多个类-->
        <classes>
                <!--class 代表单个类-->
            <class name="com.guoyasoft.autoUI.guoya_1810.GuoyaLogin">
                    <!--methods 代表方法集-->
                <methods>
                        <!--include 代表方法名-->
                    <include name="signup" />
                    <include name="login" />
                </methods>
            </class>
        </classes>
    </test>
</suite>
package com.guoyasoft.autoUI.guoya_1810;
 //引入 jave代码路径
import com.guoyasoft.autoUI.common.BaseUI;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;
                        //'继承'
public class GuoyaLogin extends BaseUI {
       //public 公开的方法 void 无返回 login() 方法名
       //添加testng注解用来执行测试范方法
      @Test
     public void login (){
        //打开网页
        driver.get("http://47.98.226.232:8080/guoya-medium/jsp/user/login.jsp");
        sleep(5000);
        //查询元素根据name查找 然后执行清除
        driver.findElement(By.name("userName")).clear();
        //查找元素根据name查找 执行输入
        driver.findElement(By.name("userName")).sendKeys("guoya888");
        sleep(5000);
        //查找元素根据id查找 然后执行清除
        driver.findElement(By.id("password")).clear();
        //查找元素根据id查找 执行输入
        driver.findElement(By.id("password")).sendKeys("qweasd");
        sleep(5000);
        //查找元素根据xpath查找 执行输入
        driver.findElement(By.xpath("//input[@name='checkCode']")) .sendKeys("12345");
        sleep(5000);
        //查找元素根据xpath查找 执行点击
        driver.findElement(By.xpath("//input[@id='loginBtn']")).click();
      }
      @Test
  public void signup(){
        driver.get("http://47.98.226.232:8080/guoya-medium/jsp/user/signUp.jsp");
        driver.findElement(By.name("userName")).clear();
        driver.findElement(By.name("userName")).sendKeys("guoya458");
        driver.findElement(By.name("realName")).sendKeys("王胖子");
        driver.findElement(By.id("password")).sendKeys("qweasd");
        driver.findElement(By.id("password2")).sendKeys("qweasd");
        driver.findElement(By.id("phone")).sendKeys("15228487858");
        driver.findElement(By.xpath("//input[@id='age']")).sendKeys("18");
        driver.findElement(By.xpath("//input[@id='checkCode']")).sendKeys("1234");
        driver.findElement(By.xpath("//input[@id='submitBtn']")).click();
        sleep(5000);
        //弹出弹窗 是否确定
        driver.switchTo().alert().accept();
        sleep(5000);
        //变量+自定义名称=(父值符)...
        WebElement  hahaha=driver.findElement(By.name("userName"));
        hahaha.clear();
        hahaha.sendKeys("guoya525");


  }


}




最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容