1

For a hobby project of mine, I'm building automatic test software for a complex website.

What the automatic test software does until now is:

  • Open the website
  • Do stuff on website
  • Write results to a file
  • Close website

Pretty straight forward and works like a charm.

The website is made to have a certain behaviour among other things based on the location you're accessing it from.

To test different kind of locations, I use ExpressVPN. Works like a charm again....

But while the "Doing stuff on the website"-part takes away a lot of effort from my side, I'd wish I could automate the changing of the VPN location (or accomplish the same thing in a completely different way). Has anybody any ideas?

  • How does the website determine the user's location? For testing you could add something like an URL parameter `location` where you pass in a fake location, and based on that the site changes its behaviour. – Christian Baumann Oct 08 '20 at 12:58
  • That would be the easy way, but I can't change anything about the website and it doesn't work with an URL parameter – Manon Van de Wiel Oct 08 '20 at 13:17
  • Since I can simulate a different location using VPN, I assume/guess it uses the IP adress from the device it's accessed from – Manon Van de Wiel Oct 08 '20 at 13:18
  • Quick google search shows that it is possible to do that in code, eg https://stackoverflow.com/questions/899349/connecting-to-a-vpn-without-installation-of-client-software So it depends on what programming language you're using. – Christian Baumann Oct 08 '20 at 13:37
  • @ChristianBaumann For now i've written it in VBA, but if solving this problem requires me to rewrite the rest of the code in another language, that's no problem – Manon Van de Wiel Oct 08 '20 at 14:12
  • 1
    Found a solution, will post it as answer – Manon Van de Wiel Oct 10 '20 at 10:11

1 Answers1

1

After some more googling, chasing down rabbit holes, sleepless nights and lots of trial and error, I found the solution. It takes some (a lot of) preparation, but if you use it a lot, like I'm planning to do, it's worth the effort....

Preparation

  • Download and install Open VPN GUI
  • Download config files for Open VPN from ExpressVPN
  • Edit config files according to info from ExpressVPN (used a script for that, but if you are only doing a few, might do that by hand)
  • Use OpenVPN to connect to all the servers (to enter credentials), this only has to be done once (if you don't forget to check the box "Remember password")

Actual code It's a pretty simple code (I know that this snippet is quick and dirty, have to add error handling and stuff, but I was happy I got it working)

Dim DirectoryListArray() As String
Dim myDir as String
Dim myFile as String
Dim Counter as Integer
Dim strCommand as String
Dim i as Integer

myDir = "C:\Program Files\OpenVPN\bin\"
ReDim DirectoryListArray(1000)

MyFile = Dir$("C:\Program Files\OpenVPN\config\*.*")
Do While myFile <> ""
    DirectoryListArray(Counter) = myFile
    myFile = Dir$
    Counter = Counter + 1
Loop

ReDim Preserve DirectoryListArray(Counter - 1)

For i = 1 To UBound(DirectoryListArray)
    strCommand = "openvpn-gui.exe --command disconnect_all"
    Call Shell("cmd.exe /c cd /d " & myDir & " & " & strCommand, 1)
    strCommand = "openvpn-gui.exe --command connect " & DirectoryListArray(i)
    Call Shell("cmd.exe /c cd /d " & myDir & " & " & strCommand, 1)

    'Do Stuff on website

Next i