Selenium代码示例

 2023-09-05 阅读 371 评论 0

摘要:注册功能Selenium代码: package com.selenium.testng; import org.openqa.selenium.WebDriver; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.selenium.test.We; public class RegisterTest { WebDriver driver; Str

注册功能Selenium代码:

package com.selenium.testng;

import org.openqa.selenium.WebDriver;

import org.testng.annotations.BeforeClass;

import org.testng.annotations.Test;

import com.selenium.test.We;

public class RegisterTest {

         WebDriver driver;

         String Url="http://172.31.19.159/ecshop/";

 

         @BeforeClass

         public  void print(){

                   System.out.println("beforeclass at register");

                   driver=We.findDriver();

                   We.findURL(driver,Url );

         }

 

         @Test

         public void regist() throws InterruptedException {

                   //进入前台主页,前提是之前登录的已经退出,浏览器不记忆登录信息

                   for (int i = 0; i <1; i++) {

                            register();

                   }                

         }

 

         int systime=(int) System.currentTimeMillis();

         String uname1=systime+"yang";

         String uname=uname1.substring(3);

         public  void register() throws InterruptedException{

                   String pwd="123456";

                   String mail=systime+"@qq.com";

                   //点击注册

                   We.byPathClick(driver,"//a[@href='user.php?act=register']");

                   //输入用户名

                   We.byIdWrite(driver, "username",uname);

                   //输入用密码

                   We.byIdWrite(driver, "password1", pwd);

                   //输入email

                   We.byIdWrite(driver, "email", mail);

                   //输入确认密码

                   We.byIdWrite(driver, "conform_password", pwd);

                   //输入msn

                   We.byNameWrite(driver,"extend_field1", mail);

                   //输入qq

                   We.byNameWrite(driver,"extend_field2", pwd);

                   //输入电话

                  We.byNameWrite(driver,"extend_field3", pwd);

                   //输入家庭电话

                   We.byNameWrite(driver,"extend_field4", pwd);

                   //输入手机

                   We.byNameWrite(driver,"extend_field5", pwd);

                   //输入密保问题

                   We.byNameSelect(driver, "sel_question", "motto");

                   //输入密保答案

                   We.byNameWrite(driver,"passwd_answer", pwd);

                   //点击确定

                   We.byNameClick(driver, "Submit00");

                   //检查是否登录成功

                   We.AssertEByClassName(driver, "f4_b", uname);            

         }

 

}

 

Selenium工具类示例代码:

//----------------------------下拉框选择

         //通过名字找到并选择

         public static void byNameSelect(WebDriver driver,String name,String value){

                   wait = new WebDriverWait(driver,10,1);

                   wait.until(ExpectedConditions.visibilityOfElementLocated(By.name(name)));

                   WebElement el=driver.findElement(By.name(name));

                   Select sel = new Select(el);

                   sel.selectByValue(value);

         }

         //通过xpath找到并选择

         public static void byPathSelect(WebDriver driver,String name,String value){

                   wait = new WebDriverWait(driver,10,1);

                   wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(name)));

                   WebElement el=driver.findElement(By.xpath(name));

                   Select sel = new Select(el);

                   sel.selectByValue(value);

         }

//----------------------------断言assetEquals

         //通过name找到并选择

         public static void AssertEByName(WebDriver driver,String name,String actual){

                   wait = new WebDriverWait(driver,10,1);

                   WebElement el= wait.until(ExpectedConditions.visibilityOfElementLocated(By.name(name)));

                   Assert.assertEquals(el.getText(),actual);

         };

         //通过id找到并选择

         public static void AssertEById(WebDriver driver,String name,String actual){

                   wait = new WebDriverWait(driver,10,1);

                   WebElement el= wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(name)));

                   Assert.assertEquals(el.getText(),actual);

         };

 

 

信息录入功能Appium代码示例:

public class AppDemo {

         private  AndroidDriver  driver;

         @BeforeMethod(alwaysRun=true)

         public void set() throws Exception{

                   this.driver=wUtils.setUp();

         }

         @AfterMethod(alwaysRun=true)

         public void tearDown() throws Exception {

                   driver.quit();

         }

         @Test(groups={"InfoQuery"} )

         public void inforQuery(){

                   wUtils.byNameClick(driver, "信息查询");

                   wUtils.byNameClick(driver, "社区人口信息查询");

                   wUtils.radiobuttons_Click(driver, 1);

                   wUtils.editTexts_SendKeys(driver, 0, "高林达");

         }

}

转载于:https://www.cnblogs.com/Testers/p/7469479.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/1/465.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息