@findy注解,testNG控制执行顺序

@findy注解

1、针对每个页面新建一个类


@findy注解,testNG控制执行顺序_第1张图片
image.png

2、在类中使用@FindBy注解定位元素,并把定位结果存在变量中


@findy注解,testNG控制执行顺序_第2张图片
image.png

3、对每个元素封装一个操作的方法
@findy注解,testNG控制执行顺序_第3张图片
image.png

4、新建一个类写业务代码,先初始化页面,再调用封装好的元素操作方法


@findy注解,testNG控制执行顺序_第4张图片
image.png

5、添加断言
image.png

testNG控制执行顺序

package com.guoyasoft.gyautotest.ui.testCase.test.guoya.pages;
import com.guoyasoft.gyautotest.ui.common.BaseUI;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import java.nio.file.Watchable;
/**
 * @Auther: xuepl
 * @Date: 2018/12/19 14:04
 * @Description:
 */
public class GuoYaHome  extends BaseUI {
    @FindBy(xpath = "//a[contains(text(),'课程查询')]")
    private WebElement classSearchLink;
    @FindBy(xpath = "//a[contains(text(),'面试统计')]")
    private WebElement interviewCountLink;
    @FindBy(xpath = "//a[contains(text(),'查询面试')]")
    private WebElement searchInterviewLink;
    @FindBy(xpath = "//iframe")
    private WebElement iframe;
    public void clickClassSearchLink(){
        click(classSearchLink);
    }
    public void clickInterviewCountLink(){
        click(interviewCountLink);
    }
    public void clickSearchInterviewLink(){
        click(searchInterviewLink);
    }
    //因为要用到driver,所以需要传一个driver参数
    public void switchToIframe(WebDriver driver){
        driver.switchTo().frame(iframe);
    }
}
package com.guoyasoft.gyautotest.ui.testCase.test.guoya.pages;
import com.guoyasoft.gyautotest.ui.common.BaseUI;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
/**
 * @Auther: xuepl
 * @Date: 2018/12/19 14:14
 * @Description:
 */
public class SearchInterview extends BaseUI {
    @FindBy(xpath = "//input[@name=\"custmerName\"]")
    private WebElement studentNameInput;
    @FindBy(xpath = "//button[contains(text(),'查询')]")
    private WebElement searchButton;
    public void sendKeysStudentNameInput(String studentName){
        sendKeys(studentNameInput,studentName);
    }
    public void clickSearchButton(){
        click(searchButton);
    }
}
package com.guoyasoft.gyautotest.ui.testCase.test.guoya.testcase;
import com.guoyasoft.gyautotest.ui.common.BaseUI;
import com.guoyasoft.gyautotest.ui.testCase.test.guoya.pages.GuoYaHome;
import com.guoyasoft.gyautotest.ui.testCase.test.guoya.pages.SearchInterview;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.Test;
/**
 * @Auther: xuepl
 * @Date: 2018/12/19 14:17
 * @Description:
 */
public class TestGuoYa extends BaseUI {
    @Test
    public void testSearchInterview2(){
        driver.get("http://www.guoyasoft.com:8080/guoya-client-qa/");
        GuoYaHome guoYaHome = PageFactory.initElements(driver, GuoYaHome.class);
        guoYaHome.clickSearchInterviewLink();
        guoYaHome.switchToIframe(driver);
        SearchInterview searchInterview = PageFactory.initElements(driver, SearchInterview.class);
        searchInterview.sendKeysStudentNameInput("张继成");
//        searchInterview.clickSearchButton();
        sleep(3);
    }
    @Test
    public void testSearchInterview1(){
        driver.get("http://www.guoyasoft.com:8080/guoya-client-qa/");
        GuoYaHome guoYaHome = PageFactory.initElements(driver, GuoYaHome.class);
        guoYaHome.clickSearchInterviewLink();
        guoYaHome.switchToIframe(driver);
        SearchInterview searchInterview = PageFactory.initElements(driver, SearchInterview.class);
        searchInterview.sendKeysStudentNameInput("王鹏");
//        searchInterview.clickSearchButton();
        sleep(3);
    }
}

testNG.xml配置文件



    
        
            
            
      
          
         
         
      
  
   


你可能感兴趣的:(@findy注解,testNG控制执行顺序)