-
-
Save mwickramanayaka/e7f3d71ff7ba29ff1634963fae40e311 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.io.InputStream; | |
import java.io.OutputStream; | |
import java.util.Properties; | |
import com.aventstack.extentreports.ExtentReports; | |
import com.aventstack.extentreports.ExtentTest; | |
import com.aventstack.extentreports.reporter.ExtentSparkReporter; | |
public class PropertiesFile { | |
//Create a object for class properties | |
static Properties prop = new Properties(); | |
//defining the project path | |
static String projectPath = System.getProperty("user.dir"); | |
//setting expected title from the ebay.com/Daraz.lk | |
static String expectedTitleebay ="Electronics, Cars, Fashion, Collectibles & More | eBay"; | |
static String expectedTitledaraz ="Online Shopping Sri Lanka: Clothes, Electronics & Phones | Daraz.lk"; | |
//create the htmlReporter object | |
static ExtentSparkReporter htmlReporter; | |
static ExtentReports extent; | |
static ExtentTest test1; | |
public static String browserName = null; | |
public static void main(String[] args) throws InterruptedException { | |
PropertiesFileTestNG.setup(); | |
PropertiesFileTestNG.test1(); | |
PropertiesFileTestNG.tearDown(); | |
} | |
public static void getProperties() { | |
try { | |
//create a object for class InputStream | |
InputStream input = new FileInputStream(projectPath + "/src/test/java/test/config.properties"); | |
//Load properties file | |
prop.load(input); | |
//get values from properties file | |
String browser = prop.getProperty("browser"); | |
System.out.println(browser); | |
//Setting browsername in the PropertiesFileTestNG class | |
PropertiesFileTestNG.browserName = browser; | |
} catch (Exception exp) { | |
System.out.println(exp.getMessage()); | |
System.out.println(exp.getCause()); | |
exp.printStackTrace(); | |
} | |
} | |
public static void setProperties() { | |
try { | |
//create a object for class OuputStream | |
OutputStream output = new FileOutputStream(projectPath + "/src/test/java/test/config.properties"); | |
//Load properties file and set firefox | |
prop.setProperty("result", "test passed"); | |
//store values i properties file | |
prop.store(output, "setting firefox"); | |
} catch (Exception exp) { | |
System.out.println(exp.getMessage()); | |
System.out.println(exp.getCause()); | |
exp.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment