Use a VPN extension instead of proxies in automation (using pop-up extensions)

Tram Ho

I. Introduction

When it comes to automation, for system requirements, or for some personal reason, we want to change IP every time we run automation.

The easiest way is to set the proxy in capability for the browser, how can I refer here

However, the limited use of a proxy is that we can only set the proxy when initializing the browser (I thought of the case of adding a proxy list and getting random to run, but it is still limited and easy to duplicate). This means that we can only use the proxy for one run, if we run data-driven, a set of data will only use the same proxy. So is there a way to change the IP for each test case?

Currently, there are some VPN extensions that support us in this, if we can do it manually, why not try it in automation.

In this article I will use the “Touch VPN” extension on Chrome. However, this extension does not automatically run after we install it (the UI will display like that, but when checked, the IP will not change) , but this extension requires manipulation on the popup of the extension. use to be. Let’s learn about how to launch this extension or similar required extensions in this article.

II. Let’s try it manually

  1. First, access the Chrome extensions page
  2. Search for “Touch VPN”
  3. Select “Add to Chrome”
  4. Once added to Chrome, click the extension button in the right corner of Chrome
  5. Select “Touch VPN – Secure and unlimited VPN proxy”
  6. In the popup window, click on “Connect”
  7. After the popup changes to “Encription is enabled” and displays the parameters, the VPN has been successfully used

image

In step (3), we must click on connect to be able to use this extension, so how to perform auto on this pop-up. Let’s try another way to do it.

III. Write code to perform the above steps

Here I will use Selenium with Java, TestNG and maven, other languages, the way to do the same.

1. Download the VPN extension to your device

The file extension is in crx format. How to download the extension to your computer can refer to this article

Here I have already downloaded this extension, you can download it here

2. Install the required libraries

The libraries include Selenium, TestNG, WebDriverManager, add these libraries to pom.xml file.

How to add these libraries and why need it, please refer to Part II of my previous post

3. Create class to perform the above steps

  • First, put the crx file you downloaded in step (1) into the project folder, here I will put in “main / resources /”

image

  • Next, declare @BeforeTest annotation and configure Chrome driver:

  • rootFolder is the path to the project directory
  • vpn is the path to the downloaded crx file above that I put in “/main/resources/touchVPN.crx”. The use of File.seperator is so that we can run on many different OSs, because each different OS will have a different path mark (on Linux it is “”).
  • Declare ChromeOptions to add Extension Touch VPN
  • Declare implicit wait equal to 30 seconds
  • Next, write a @Test method to access the extension’s index page, click connect (step 6, part II above).

  • We cannot do auto pop-ups when we click on the extension and then press connect, so here we access the extension’s index page instead of clicking the extension. The index page will take the form of extension protocol + extension ID + /panel/index.html
  • Where can I get the extension ID? extension ID can be found from the Chrome Extension page image
  • After initializing the browser with the extension, the extension will automatically initialize a page of the extension, so we have to switch back to the page we want to operate, here is the index page and https://whatismyipaddress.com/
  • After accessing https://whatismyipaddress.com/ , check if the country is not Vietnam, that means we have successfully changed the IP, the currently used IP is no longer in Vietnam. image
  • Finally, close the browser

If we put this step before each test case, it will be possible to change the IP (using VPN) for each test case. This method will take more time, but it should solve the problem.

IV. Conclusion

Of course, using proxies is only rare, of course, we can refer to accessing the extension’s index page for other extensions that require clicking on the icon to be able to operate , because not all extensions are required. The installation is ready to use.

Hope this article will be of help to you when you encounter similar problems

Referencies: https://github.com/npmtam/Automation-Testing-Articles/issues/3

Share the news now

Source : Viblo