如何从外部设置所需功能(不进行硬编码);

时间:2019-03-27 10:08:48

标签: frameworks appium

public void setUp() throws MalformedURLException,InterruptedException 
  {


    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("newCommandTimeout", 100000);
    capabilities.setCapability("BROWSER_NAME", "Android");
    capabilities.setCapability("platformVersion", "8.1.0");
    capabilities.setCapability("deviceName", "a1cc6f96");
    capabilities.setCapability("platformName", "Android");

}

1 个答案:

答案 0 :(得分:1)

在项目中创建 config.properties 文件。在config.properties文件中添加以下数据

import Button from '@ui/Button/Button'
import Dialog from './Dialog';

class ModalExample extends React.Component {
    constructor(props) {
        super(props);
        this.state = {visible: false}
    }
...

然后添加将返回属性值的方法

newCommandTimeout = 100000
browserName = chrome
platformVersion = 8.1.0
deviceName = a1cc6f96
platformName = Android

之后,您可以使用以下属性

public class LoadProperty {
  Properties prop = new Properties();
  InputStream input = null;

  public String getProperty (String propertyName){
    try {
        input = new FileInputStream("path/to/config file/config.properties");
        prop.load(input);
        return prop.getProperty(propertyName);
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
  }
}