What is Tor Browser?

Well, Tor browser is cool because it allows you to browse the web anonymously. If you take a look at your IP address in a Tor browser, you will notice that it’s not the actual IP of your computer. In fact, your IP might come from a completely different country when you are using a Tor browser.

As a QA Automation Engineer, I like using Tor to see how my application handles different IP addresses. You can run a test on Tor and see how the web app handles a visitor from Australia, Germany, and any other random country. You can check the performance of your app against different locations and make sure that this is acceptable to your Product Owners or clients. Furthermore, journalists like to use this to stay anonymous on the web. Some people like to use this browser to just stay anonymous in general. And others even use this browser for bad things that occur on the Deep Web (tum dum dum…).

Whatever your need for using the Tor browser, I will teach you how to use Selenium Webdriver to automate that sucker. What you do with this knowledge is up to you.

Our Test Case

The goal for this test case is simple:

  1. Open Tor browser using Selenium Webdriver
  2. Go to this URL www.qtptutorial.net/automation-practice
  3. Select the radio button that says, “I love HP UFT”

Select this:

select this radio buttonHow to set up and Download Everything that you need to run Tor?

  1. Download the Tor browser here
    1. Pick the appropriate version based on your Operating System
  2. You will download an application called something like “torbrowser-install-5.0.4_en-US” that will take you through the installation process
  3. Afterwards, there will be a folder where you installed Tor that looks something like this
  4. Next, download my sample VS application. If you’re not sure how to download a Github project, you can learn that here.folder
  5. I took this folder and placed it inside of my ‘Drivers’ folder for my Visual Studio project. You should do the same thing and place the ‘Browser’ folder into the ‘Drivers’ folder of the code that you just downloaded from my Github. This looks like the image below.3Open up your Visual Studio and open the Tor.sln file that you just downloaded.
  6. Open the UnitTest2.cs class that contains our unit test.
  7. Look at the SetupTest() method. Inside, you will need to update the ‘torBinaryPath’ variable to point to the firefox.exe in your ‘Browser’ folder. My code looks like this: var torBinaryPath = “C:\Source\Github\Tor\TorTest\Drivers\Browser\firefox.exe”;
  8. Yes, you will need to install Firefox if you do not have it. We use the proxy generated by Tor, but our test actually runs in Firefox. This is really awesome because you guys should be familiar with running automation tests on Firefox.

How to run a Webdriver test with Tor

4

  1. Go inside of the UnitTest2.cs file to run the unit test just like any other unit test in Visual Studio. If you’re not sure how to do that, take the Selenium course to learn.
  2. When you are running the test, you will notice that the Tor browser is the first to load. However, your test actually runs in Firefox.
  • If you don’t believe that your IP has changed and want to double check, you can see your IP here before you run the test.
  • Next, pause the test in the middle, after getting the QTP Tutorial website.
  • Finally, go back to this website and notice how now you have a “different” IP. That’s because you’re browsing anonymously!

That’s all there is to it. Feel free to update the code for whatever purpose you want. Element identification can be done in Firefox without any issues.

By the way, special thanks to this really helpful article from Anton Angelov who is one of my favorite Selenium bloggers. His content is always full of awesome info!