如何使用属性文件在Selenium中的框架中声明全局变量?
我们可以在与.properties文件一起使用的Properties类的帮助下在Selenium中声明全局变量。在.properties文件中,数据存储在键值对中。我们可以在.properties文件中读取和写入值。
极端
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Propert {
public static void main(String[] args) throws IOException {
//TODO自动生成的方法存根
Propert t = new Propert();
t.login();
}
public void login() throws IOException {
Properties prop = new Properties();
FileInputStream ips = new FileInputStream(
"C:\\Users\\ghs6kor\\eclipse- workspace\\Inheritance\\config.properties");
prop.load(ips);
// read from properties file with getProperty() method
if (prop.getProperty("browser").equalsIgnoreCase("firefox")) {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\ghs6kor\\Desktop\\Java\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get(prop.getProperty("url"));
FileOutputStream ops = new FileOutputStream(
"C:\\Users\\ghs6kor\\eclipse- workspace\\Inheritance\\config.properties");
String urlnm = driver.getTitle();
// writing in the properties file with setProperty() method
prop.setProperty("title", urlnm);
prop.store(ops, null);
}
}
}热门推荐
10 五一公司放假祝福语简短
11 追星女孩的祝福语简短
12 给长辈端午祝福语 简短
13 生日祝福语有诗意简短
14 团圆日祝福语简短
15 中秋商务祝福语简短最新
16 温暖文艺简短祝福语短句
17 男孩上学祝福语简短的
18 入住酒店文案祝福语简短