How to download url from 1 TC and load it in 2 TC

Hello, I’m trying to copy the URL from the first test case to the next test case but I can’t. Do I have to save it to a file and in the next TC download, it (only how) or is there any other way? I need this for the Salesforce platform.
I need it because in the first test case I create an account and want to download a unique URL, then in the second test case I want to load this URL and work on the account

There are a few ways to do that. Probably the easiest is to create GlobalVariable (in your project profile).

In TC1 you can set the value. In TC2 you an get it and use it.

1 Like

But every time you create a new account, the URL is new (unique) and I can’t assign it permanently

Create an empty GlobalVariable.MY_URL in the profile with ""

In TC1 set the value.

GlobalVariable.MY_URL = "https://..."

In TC2 use it

WebUI.navigateToUrl(GlobalVariable.MY_URL)

The globals are consistent across a suite, and maybe when using WebUI.callTestCase() (I haven’t tested that).

2 Likes

Alternatively, you can use something like this:

Test Case 1:

// Logic
return URL

Master Test Case (the test case that orchestrates the flow between test cases)

String url = WebUI.callTestCase('Test Case 1');
WebUI.callTestCase('Test Case 2', ['url': url]);

Test Case 2 (with a test case variable url defined in Test Case Variables tab)

println url;
2 Likes

Personally, I’d prefer that over global vars.

1 Like

Sorry but I still have a problem. I was able to do a simple test
I created global variables next
In TC1 I set the value:
GlobalVariable.MY_URL = WebUI.getUrl();
In TC2 I use:
WebUI.navigateToUrl(GlobalVariable.MY_URL) and this works but only performed as Test Suite, i.e. one case after another.

I had one more idea. Do you know how to save URL to a text file? And how to load this link from the file in the next test case? I think that would be the best solution :slight_smile:

@ThanhTo I can’t do it. I do not have a Master Test Case. In my 1TC I create an account, after clicking “Save” it goes to that account automatically and then I have a unique URL that I want to download.

In 2TC, I want to go straight to this URL and record the next steps. And then 3TC, 4TC on the same account which is the same URL.

@swider.lukasz

When I mean “master test case”, I simply mean a test case that calls other test cases, so it will call TC1, and then TC2, and then TC3, and finally TC4. Do you have a particular reason to not do it this way or with a straight-forward test suite and global variables ?

Saving a value to a text file and reading it to a variable is a trivial programming task, but it would take a bit effort if you are not familiar with coding at all.

The idea is to write a Custom Keyword that reads and writes values to a text file. The code that actually does the reading and writing is here:

Please try it out to see if it helps.

That’s because you haven’t written it yet. For the way it appears you want to work, making TC2 call TC1 is the easiest method. TC1 will RETURN the url and TC2 will use it.

// This is TC2 ...

String my_url = callTestCase(findTestCase("TC1")...)

WebUI.navigateToUrl(my_url)

At the very end of TC1…

return my_url