自动化测试随笔3

Posted 十年之光

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自动化测试随笔3相关的知识,希望对你有一定的参考价值。

拼成的list 写入值

package testcase.category.level3category;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import Common.common;
import testcase.category.level1category.AddLevel1Category;
import testcase.category.level2category.AddLevel2Category;

import Common.GetWebSite;
import Common.excel;

public class AddLevel3Category {
    private WebDriver driver;
    
    public void addLevel3Category(WebDriver driver, String strLevel1CategoryName,String strLevel2CategoryName,String strLevel3CategoryName) throws Throwable{
        List<List<String>> list=excel.addexcel();
        System.out.println(list);
        /* 新增三级品类 */    
        common.scrollToElement(driver, By.xpath("//ul[li[@id=‘"+strLevel1CategoryName+"‘]]/ul/button")).click();
        //品类名称
        common.waitForElement(driver, By.xpath("//*[@id=‘threeCategory‘]/div[1]/div/div[2]/div[1]/div/form/table/tbody/tr[2]/td[2]/input")).sendKeys(strLevel3CategoryName);
        //品类别名
        common.waitForElement(driver, By.name("acname")).sendKeys(strLevel3CategoryName);

        for(int i=0;i<list.size();i++){
            Thread.sleep(3000);
            if(list.get(i).get(0).equals("规格")){
                continue;
            }
            else if(list.get(i).get(0).equals("重量")){
                continue;
            }
            else if(list.get(i).size()==1){
                continue;
            }
            else{
                //新增属性
                common.waitForElement(driver, By.xpath("//*[@id=‘threeCategory‘]/div[1]/div/div[2]/div[1]/div/form/table/tbody/tr[5]/td/button")).click();
                //属性名
                common.waitForElement(driver, By.name("pname")).sendKeys(list.get(i).get(0));
            }
            for(int j=1;j<list.get(i).size();j++){
                //属性值
                common.waitForElement(driver, By.name("cpvalues")).sendKeys(list.get(i).get(j));
                driver.findElement(By.xpath("//*[@id=‘content‘]/div[2]/form/table/tbody/tr[4]/td[2]/i/input")).click();
            }
            
        Thread.sleep(1000);
        //完成
        common.waitForElement(driver, By.xpath("//*[@id=‘content‘]/div[2]/div/button")).click();
        
        }
        Thread.sleep(2000);
        //再点完成
        common.waitForElement(driver, By.xpath("//*[@id=‘threeCategory‘]/div[1]/div/div[2]/div[2]/button")).click();
    }
    

    @BeforeTest
    public void beforeTest() throws Throwable{
        this.driver = GetWebSite.getWebSite2();
    }
    
    @Test
    public void addSingleAttributeValue() throws Throwable {
   
        String strL1CategoryName = "蔬菜"+common.getCurrentTime();
        String strL2CategoryName = "块茎类"+common.getCurrentTime();
        String strL3CategoryName = "萝卜"+common.getCurrentTime();
        
        common.waitForElement(driver, By.linkText("品类管理")).click();
        AddLevel1Category AddLevel1Category = new AddLevel1Category();
        AddLevel1Category.addLevel1Category(driver,strL1CategoryName);
        AddLevel2Category AddLevel2Category = new AddLevel2Category();
        AddLevel2Category.addLevel2Category(driver,strL1CategoryName,strL2CategoryName);
        AddLevel3Category AddLevel3Category = new AddLevel3Category();
        AddLevel3Category.addLevel3Category(driver,strL1CategoryName,strL2CategoryName,strL3CategoryName);
        Thread.sleep(2000);
        common.waitForElement(driver, By.partialLinkText(strL2CategoryName)).click();
        common.waitForElement(driver, By.partialLinkText(strL2CategoryName)).click();
        Assert.assertEquals(common.waitForElement(driver, By.partialLinkText(strL3CategoryName)).getText(),strL3CategoryName);

    }
    
    @AfterTest
    public void afterTest(){
//        driver.close();        
    }

}

 

以上是关于自动化测试随笔3的主要内容,如果未能解决你的问题,请参考以下文章

十二年测试生涯随笔

测试团队搭建随笔

python+requests随笔:unittest框架

软件测试入门随笔——软件测试基础知识

Android测试随笔模拟长按电源键

Beta冲刺-用心聚落步