Setup Menus in Admin Panel

ITeLearn.com

Couldn't get all environment specific values from properties file | Selenium Automation | Discussions | ITeLearn.com

Forum usage guidelines

  1. Search First.: If you don’t find a similar post, start a new topic. If you find a similar thread and still have a question, reply to that topic. Duplicate threads will be ignored/deleted without warning.
  2. Proper Subject: Ensure you choose a very appropriate topic name. Else it will be tough to get support from other members.
  3. Patience, please: Our Tech team or other members will usually try to respond within 24 hours on weekdays and max within 48 hours on weekends. Sometimes sooner.
  4. Share opinions: Please feel free to reply, add or comment on any ongoing topics. Collective learning will be of great benefit to all.

 
ITeLearn reviews from participants.

Please consider registering
guest

Log In

Lost password?
Advanced Search

— Forum Scope —

  

— Match —

   

— Forum Options —

   

Minimum search word length is 4 characters - maximum search word length is 84 characters

Topic RSS
Couldn't get all environment specific values from properties file
December 21, 2018
3:43 pm
Anuradha Jutty Devadoss
Member
Forum Posts: 6
Member Since:
June 21, 2017
Offline

Hello

I am developping my code to run my test suite to different environments and for that I have created 2 different TestSuite file 1 for Env1 and other for Env2. In my testsuite xml, I am parameterizing the environment name and loading the environment properties file to load all the values from properties file to be used in my test.

The issue is, I could successfully load the first value from properties file and the test works as expected but I am struggling to figure out the way load other values from properties file.

I am not sure what I am doing wrong and I couldn’t figure out for the past 2 days. Any guidance on this will be very helpful.

Thanks in advance

Below are the code snippet for your information

TestSuite1.xml
————–

TestSuite2.xml
————–

jenkins.properties
——————

#This file is used to store the configuration properties for Jenkins Environment

SERVERNAME = jenkins.svr.net
CONNECTION_STRING = jdsfkjadfpdashfadsjfhdasofd
KEY = kljdagfljkdasgfldsaj
ENV = J

dev.properties
————–

#This file is used to store the configuration properties for Jenkins Environment

SERVERNAME = dev.svr.net
CONNECTION_STRING = ghdsghfdvfghshsdghsdghdgh
KEY = werewrtsadvsdfdghfsdgdfs
ENV = D

com.kk.portal.EngineTests.CreateResourceOnboarding
————————————————–

package com.kk.portal.EngineTests;

import com.kk.portal.utilities.*;
import com.kk.portal.webPages.EngineOIDCWebApiResourceOnboardingScreen;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class CreateResourceOnboarding extends DriverProvider {

@BeforeClass
public void launchApplicationAndLogin() {

if(!loggedIn){
logInCheck();
}
webApiOnboardScreen = new EngineOIDCWebApiResourceOnboardingScreen(driverInstance.getDriver());
}

private void createAResource(String onBoardType, String testNum){
{
openOIDCWebApiResourceOnboardScreen(onBoardType,testNum);
}

}

@Test
public void CreateResourceOnboarding01JustSubmitTest() {
String onBoardType = “R”;
String testNum = “01”;
createAResource(onBoardType,testNum);
webApiOnboardScreen.submitButton().click();
}

com.kk.portal.EngineTests.DriverProvider
—————————————-

package com.kk.portal.EngineTests;

import com.kk.portal.config.Driver;
import com.kk.portal.config.DriverType;
import com.kk.portal.utilities.*;
import com.kk.portal.webPages.*;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Parameters;

import java.sql.Connection;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

public class DriverProvider {
public static Driver driverInstance ;
private EngineConfigProperties configProperties;
public static Boolean loggedIn = false;
public static Properties property;
public static Boolean sealIdInserted = false;
public static Boolean sealIdInsertedForSaml = false;
protected HomePage homePageItem;
protected OnboardUsingOpenIdPage oidcItem;
protected OnboardUsingSAMLPage samlItem;
protected MyApplicationsPage myApplicationItem;
protected OIDCResourceOnBoardingIntroPage resourceOnboardingIntroItem;
protected EngineOIDCWebApiResourceOnboardingScreen webApiOnboardScreen;
protected OnboardUsingOpenIdPageApiToApi resourceOnboardingItem;
protected OIDCResourceOnboardingScreen resourceOidcItem;
protected OIDCClientOnboardingPage oidcClientOnboardingItem;
protected EngineAuthorizationRolesTab authorizationRolesTab;
protected MultiFactorAuthRsaSecuredIDTab multiFactorAuthTab;
protected EngineLDAPOnboardingPage ldapItem;

@BeforeSuite
@Parameters (“environment”)
public void initDriver(String environment) {
driverInstance = new Driver(DriverType.FIREFOX);
driverInstance.getDriver().manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
ValidateApplicationIsUpAndRunningWithDBConnection(environment);
}

public void logInCheck() {
if (!loggedIn) {
LoginPage.logIn(driverInstance.getDriver(), Constants.USERNAME, Constants.PASSWORD, Constants.DOMAIN);
loggedIn = true;
}
}

public void openOIDCWebApiResourceOnboardScreen(String onBoardType, String testNum) {
configProperties = new EngineConfigProperties();
sealIdInserted = false;
sealIdIntegrationCheckResourceOnboarding();
webApiOnboardScreen.openResourceUsrIdentityAttrTab(onBoardType,testNum);
}

@AfterSuite(alwaysRun = true)
public void quitDriver() {
driverInstance.getDriver().quit();
}

public void ValidateApplicationIsUpAndRunningWithDBConnection(String environment) {
try {
driverInstance.getDriver().manage().window().maximize();
configProperties = new EngineConfigProperties();
property = configProperties.getProperties(environment);
driverInstance.getDriver().get(Constants.PORTAL_FORM_LOGIN_URL.replace(Constants.SERVERNAME, property.getProperty(Constants.SERVERNAME)));
logInCheck();
Check DB connectivity whether DB is accessible or not
DBConnector dbConn = new DBConnector();
Connection connObj = dbConn.validateDBConnectionExistsOrNot();
if (connObj == null) {
quitDriver();
} else {
connObj.close();
connObj = null;
}
}

}

com.kk.portal.utilities.EngineConfigProperties
———————————————-

package com.kk.portal.utilities;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class EngineConfigProperties {

public static Properties getProperties(String environment) {

File file = new File(“src\\main\\java\\com\\kk\\portal\\config\\”+ environment +”.properties”);

FileInputStream fileInput = null;
try {
fileInput = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Properties prop = new Properties();

//load properties file
try {
prop.load(fileInput);
} catch (IOException e) {
e.printStackTrace();
}
return prop;
}
}

com.kk.portal.utilities.Constants
———————————

package com.kk.portal.utilities;

public class Constants {

public static final String SERVERNAME = “SERVERNAME”;
public static final String ENV = “ENV”;
public static final String KEY = “KEY”;
public static final String CONNECTION_STRING = “CONNECTION_STRING”;
public static final String RESOURCE =”https%3A%2F%2Fvsin7u9904.svr.net%2Ffsportal”;
public static final String CLIENT_ID = “PC-103836-ADFSAPIV2TestFID-0-DEV”;
public static final String PORTAL_URL = “https://”+SERVERNAME+”/portal”;
public static final String PORTAL_FORM_LOGIN_URL = “https://identityinfra.svr.com/fs/oauth2/authorize?response_type=code”+
“&client_id=”+CLIENT_ID +
“&redirect_uri=”+”https%3A%2F%2F”+SERVERNAME+”%2Fportal%2FAccount%2FExternalLogin”+
“&scope=openid”+
“&resource=”+RESOURCE +
“&response_mode=form_post” +
“&nonce=ad0be9fb35b94d93aafe87162b9caf87″+
“&prompt=login”;
public static final String USERNAME = System.getenv(“PORTAL_USERNAME”);
public static final String PASSWORD = System.getenv(“PORTAL_PASSWORD”);
public static final String APP_FRIENDLY_NAME = “select top 1 ApplicationFriendlyName from [dbo].[InvTable] where ApplicationFriendlyName like ‘SEL%R01’ order by SLN asc;”;
public static final String APP_FRIENDLY_NAME_COLUMN = “ApplicationFriendlyName”;
}

com.kk.portal.webPages.EngineOIDCWebApiResourceOnboardingScreen
—————————————————————

package com.kk.portal.webPages;

import com.kk.portal.utilities.*;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;

public class EngineOIDCWebApiResourceOnboardingScreen {
private static WebElement element = null;
private static Select selection = null;
private static WebDriver driver;

public static WebDriver getDriver() {
return driver;
}

public static void setDriver(WebDriver webDriver) {
driver = webDriver;
}

public EngineOIDCWebApiResourceOnboardingScreen(WebDriver driver) {
setDriver(driver);
}

public void openResourceUsrIdentityAttrTab(String onBoardType, String testNum) {
combobxSealIdFirstSelection();
combobxEnvironmentDevSelection();
onboardNewResourceBtn().click();
userEntryforAppfriendname(EngineAppFriendlyName.appFriendName(onBoardType,testNum));
chkbxIHaveReadAndUnderstandSection().click();
proceedOnboardClick().click();
}
}

com.kk.portal.utilities.EngineAppFriendlyName
———————————————

package com.kk.portal.utilities;

import java.util.Properties;

public class EngineAppFriendlyName {

private EngineConfigProperties configProperties;
public static Properties property;

public static final String getIternationNumber () {

String AppFriendlyName = new EngineExtractFromDB().getAppFriendlyName();
String IterationNumber = String.valueOf(String.format(“%06d”,Integer.parseInt(AppFriendlyName.substring(4,10))+1));
return IterationNumber;
}

public static String appFriendName(String onBoardType, String testNum) {

//configProperties = new EngineConfigProperties();
//property = configProperties.getProperties(environment);

String tool = “SEL”;
//String environment = “J”;
String environment = property.getProperty(Constants.ENV);
String iteration = getIternationNumber();
String appName = tool + environment + iteration + onBoardType + testNum;
return appName;
}
}

com.kk.portal.utilities.EngineExtractFromDB
——————————————-

package com.kk.portal.utilities;

import java.sql.*;
import java.util.Properties;

public class EngineExtractFromDB {

private EngineConfigProperties configProperties;
public static Properties property;
public Connection conn = null;
public Statement stmt=null;

public EngineExtractFromDB() {
getDBConnection();
}

public void getDBConnection() {

try {
com.microsoft.sqlserver.jdbc.SQLServerDriver driver = new com.microsoft.sqlserver.jdbc.SQLServerDriver();
DriverManager.registerDriver(driver);
//conn = DriverManager.getConnection(DataSecurity.decrypt(DBConstants.KEY, DBConstants.KEY, DBConstants.CONNECTION_STRING));
conn = DriverManager.getConnection(DataSecurity.decrypt(property.getProperty(Constants.KEY), property.getProperty(Constants.KEY), property.getProperty(Constants.CONNECTION_STRING)));
} catch (Exception ex) {
// System.out.println(“Error: unable to load driver class!”);
Log.error(ex.getMessage());
}
}

public void closeConnection() {
try {
if (stmt != null)
stmt.close();
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception e) {
Log.error(Constants.DATE_INFO + TestUtil.getTime() + e.toString());
}
}

public String getAppFriendlyName () {

if (conn == null) {
getDBConnection();
}
String AppFriendlyName = null;
try {
String query = Constants.APP_FRIENDLY_NAME;
PreparedStatement stmt = conn.prepareStatement(query);
ResultSet rs = stmt.executeQuery();
while (rs.next()){
AppFriendlyName = rs.getString(Constants.APP_FRIENDLY_NAME_COLUMN);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
closeConnection();
}
return AppFriendlyName;
}
}

Forum Timezone: Asia/Kolkata

Most Users Ever Online: 70

Currently Online:
4 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Techhelp: 1971

Manu: 114

Shan Nathan: 80

Palanki sai charan: 67

Userone: 59

Vishal Anand: 53

Archana Sapre: 51

Geetha Reddy: 44

useL: 38

Kavya Vangala: 37

Member Stats:

Guest Posters: 19

Members: 8254

Moderators: 0

Admins: 1

Forum Stats:

Groups: 1

Forums: 22

Topics: 2163

Posts: 5912

Newest Members: karibandi Akki, Liana Pan, Venkata Ramana Edagottu, Ralph Arrey, Vinay Singh Kanawat, Harsha S, Ronnie Alauddin, Sushma Shetty, Jayakumar Arukutty, Manjula Kamarajan

Administrators: Karthik eLearn (Admin): 49

0 Responses on Discussions"

Main Menu