I wanted to run our coded ui tests using Selenium against the staging uri during our continuous integration workflow of our cloud service web role. But the problem arose that I didn’t know the dynamically generated URI that gets created by Azure when deploying to the staging slot.

I chatted with DevOps guru Thiago Almeida about this and he had the following suggestion:

Add a Powershell script between the publish step and the test step.  Here’s what the Powershell looked like:

param (
[string] $servicename
$deployment = Get-AzureDeployment -ServiceName $servicename -Slot Staging
if ($deployment -eq $null)
   Write-Host "No deployment is detected. "
   throw "Staging slot not found"
   $deploymentUrl = $deployment.Url
   # As explained here this next line creates a new variable with the value that other tasks can use https://github.com/Microsoft/vsts-tasks/blob/master/docs/authoring/commands.md
   Write-Host $deploymentUrl
   Write-Host ("##vso[task.setvariable variable=StagingWebsiteURL;]$deploymentUrl")

To use this, you’ll need to change the service_name to your Azure service name.

Then, on the Test Assemblies task’s “Override TestRun Parameters” value, update it to this to set the base URL to be the value of the variable set in the PowerShell task above:



Nice! It totally worked! Tip of the hat to Thiago Almeida for suggesting this!