We can run a proxy with Selenium webdriver in Python. A proxy is an essential component to do localization testing. We can take an e-commerce application and check if the language and currency visible is as per the user location.
With the help of proxy within tests, we can verify if the website user interface matches with the location. We have to SET a proxy with below steps −
Import webdriver from Selenium package.
Define proxy server address.
Create an object of ChromeOptions class
Communication of proxy with ChromeOptions.
Summing options to Chrome() object.
from selenium import webdriver #proxy server definition py = "18.104.22.168:8080" #configure ChromeOptions class chrome_options = WebDriverWait.ChromeOptions() #proxy parameter to options chrome_options.add_argument('--proxy-server=%s' % py) #options to Chrome() driver = webdriver.Chrome(chrome_options= chrome_options) driver.implicitly_wait(0.6) driver.get("https://www.tutorialspoint.com/index.htm")
Then, to check if a search field has the present user address we shall add the below code snippet −
def checkL(self): self.driver.get(self.url) st = self.driver.find_element_by_xpath('#loc') #check location with assertion self.assertEqual('India', st.text)
If we have to verify more than locations, we can create a method and pass the proxy address as an argument.