频道栏目
首页 > 资讯 > 其他 > 正文

自动化框架Quantum Automation Framework (JAVA,Appium,TestNG,QAF) + cucumber + perfecto (mobile)

18-07-10        来源:[db:作者]  
收藏   我要投稿

 

自动化框架Quantum Automation Framework (JAVA,Appium,TestNG,QAF) + cucumber + perfecto (web)

1. mobile test suit 参数设置


    
        
    

    
    
    
    
    
    

    
        
        
        
        
        
        
        
        

        
            
                
            
        
        
            
        
    

在test下的众多parameter设置,也可以写在另外的文件中,通过如下参数导入?

 

这样能让文件看起来更简洁,便于维护

src/main/resources/android下的env.properties文件里

perfecto.capabilities.platformName=android
perfecto.capabilities.applicationName=Calculator
driver.capabilities.driverClass=io.appium.java_client.android.AndroidDriver

注意最后一个参数,如果测试安卓请务必设置这个参数为AndroidDriver, 如果是IOS程序设置为IosDriver

这个两个类都是继承了appiumDriver类,可以直接使用appium封装的方法,但是对于要模拟安卓按键操作,需要使用AndroidDriver里的pressKeyCode方法。这里不修改的话在程序里去获取到AndroidDriver对象是会报错的,提示appiumdriver 和 androiddriver类不能相互转换。

2. 编写test步骤

@demoApp
Feature: Appium demoApp Example Feature
  #Sample Test Scenario Description

  @demoApp
  Scenario: Appium Example
    Given I start application by name "API Demos"
    And I am using an AppiumDriver
    When I wait for "2" seconds
    Then I will see "NFC" in screen
    When I click on button "App"
    And I will see "Action Bar" in screen
    Then I click on button "Loader"
    And I wait for "5" seconds
    Then I will go back to pre-screen
    And I wait for "2" seconds

3. 定义步骤方法,同样一些公共参数可以写在src/main/resources/android下的**.loc文件里面,通过标签导入

package com.quantum.steps;

import com.qmetry.qaf.automation.step.QAFTestStep;
import com.qmetry.qaf.automation.step.QAFTestStepProvider;
import com.qmetry.qaf.automation.ui.WebDriverTestBase;
import com.qmetry.qaf.automation.ui.webdriver.QAFExtendedWebElement;
import com.qmetry.qaf.automation.util.StringUtil;
import com.quantum.utils.AppiumUtils;
import com.quantum.utils.ConfigurationUtils;
import com.quantum.utils.ConsoleUtils;
import com.quantum.utils.DriverUtils;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import cucumber.api.java.en.And;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidKeyCode;
import io.appium.java_client.ios.IOSDriver;
import org.openqa.selenium.By;

/**
 * @author LeonLi
 *
 */
@QAFTestStepProvider
public class DemoAppStepDefs {

    @QAFTestStep(description = "I start application by name {0}")
    public void iStartApplicationByName(String str0){

    }

    @Then("I will see \"(.+)\" in screen")
    public void iWillSeeInTitleBar(String text){
        new QAFExtendedWebElement(By.xpath("//android.widget.TextView[@content-desc=\"" + text + "\"]")).verifyText(text);
    }

    @When("I click on button \"(.*?)\"")
    public void iClickOnButton(String btn){
        DriverUtils.getAndroidDriver().findElementByXPath("//android.widget.TextView" +
                "[@content-desc=\"" + btn + "\"]").click();
    }

    @And("I am using an AppiumDriver")
    public void testForAppiumDriver() {
        if (ConfigurationUtils.getBaseBundle().getPropertyValue("driver.name").contains("Remote"))
            ConsoleUtils.logWarningBlocks("Driver is an instance of QAFExtendedWebDriver");
        else if (AppiumUtils.getAppiumDriver() instanceof IOSDriver)
            ConsoleUtils.logWarningBlocks("Driver is an instance of IOSDriver");
        else if (AppiumUtils.getAppiumDriver() instanceof AndroidDriver)
            ConsoleUtils.logWarningBlocks("Driver is an instance of AndroidDriver");
    }

    @When("I will go back to pre-screen")
    public void iWillGoBackToPreScreen(){
        DriverUtils.getAndroidDriver().pressKeyCode(AndroidKeyCode.BACK);
    }
}

一切准备好后,打开模拟器,运行appium server,运行test case。

强烈推荐appium server 1.8.1,设置简单,可以通过UI界面直接启动模拟器上的软件,实时同步,自带控件的inspector

相关TAG标签
上一篇:h5解决高度塌陷的代码教程
下一篇:Pycharm学习讲解之定制外观分析
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站