1

I've been working on editing and creating various path variables for some automated test scripts so that as I change software versions of my application I'm testing, all I need to do in the code is to change a single variable called version.

The code looks like this:

//App path
var appPath = "Windows (C:)\\Program Files\\APP\\";

//App exe versions
var appV2_0 = "App v2.0\\"
var appV2_1 = "App v2.1\\"

//App current version
var version = appV2_1

export var AppVersion = appPath + version + "Bin\\";

I'm also working on making some functions that will automatically export various "outputs" from our tests to a shared drive where other team members can grab them as they want. I'm trying to handle the paths to these directories in a similar fashion. That looks like this so far:

////Share Drive variables
var ShareDrive = "\\\\shareDrive\\Path\\To\\Drive\\APP\\";

//Share Drive Major Versions
var appV2_0_SD = "AP SW\\v2.0\\";
var appV2_1_SD = "AP SW\\v2.1\\";

//Share Drive Minor Versions
//v2.0
var appV2_0a_SD = "v2.0a\\Test Files\\AutoTCs\\";
var appV2_0b_SD = "v2.0b\\Test Files\\AutoTCs\\";

//v2.1
var appV2_1a_SD = "v2.1a\\Test Files\\AutoTCs\\";
var appV2_1b_SD = "v2.1b\\Test Files\\AutoTCs\\";

//Test Files -- Version Directories
var appV2_0a_TestFiles = ShareDrive + appV2_0_SD + appV2_0a_SD;
var appV2_0b_TestFiles = ShareDrive + appV2_0_SD + appV2_0b_SD;
var appV2_1a_TestFiles = ShareDrive + appV2_1_SD + appV2_1a_SD;
var appV2_1b_TestFiles = ShareDrive + appV2_1_SD + appV2_1b_SD;

export var shareDriveTestFiles = [HERE IS THE CRUX OF MY QUESTION].....

Ultimately, it would be fairly easy to simply put whatever new version shows up in both the version variable and the shareDriveTestFiles variable. However, since I've used the same nomenclature for naming my variables, I was hoping that I might be able to define the shareDriveTestFiles variable using the version variable similar to how I can append a string using a variable (e.g. "Hello " + worldText + "!") so that maybe I could define it something like shareDriveTestFiles = verson + _TestFiles so that changing the version will also cause it to select the correct variable under the "Test Files -- Version Directories" comment.

Hopefully that long explanation was clear enough. I tried googling around but I wasn't even sure how to word what I was searching for. So please, let me know if I can clear anything up.

JohnN
  • 968
  • 4
  • 13
  • 35
  • 2
    Just use a dictionary or an array. – Carcigenicate Aug 02 '19 at 14:03
  • @Carcigenicate Could you elaborate a little on that? – JohnN Aug 02 '19 at 14:09
  • Don't try and make variables with dynamic names like that. Have a JavaScript object, and make the keys to it strings that you construct however you like. – Carcigenicate Aug 02 '19 at 14:11
  • @Carcigenicate, the answer you marked this as duplicate is not the same issue I'm describing. That is adding an iterative value onto a variable name. This is not simply adding a increasing numerical value to the end of a variable name. – JohnN Aug 02 '19 at 14:12
  • It does not need to be an increasing number. Again, the idea is just to use map keys instead of plain variables. Those answers are quit in-depth. – Carcigenicate Aug 02 '19 at 14:14
  • @Carcigenicate Okay, I'm fairly new to JavaScript so that doesn't mean a lot to me. I'll try googling that and see what I can find. – JohnN Aug 02 '19 at 14:14
  • Have you used maps/dictionaries/JavaScript objects before? Like `{"a": 1, "b": 2}`. – Carcigenicate Aug 02 '19 at 14:16
  • @Carcigenicate Yes. I've used those to choose inputs from drop downs in a GUI. – JohnN Aug 02 '19 at 14:18

0 Answers0