I am testing a website that redirects the user to another website for buying stuff. Once I click on the Buy Now button a new browser tab opens and another website is launched displaying the product.
The objective is to test that the new website (which opens in a new tab) opens successfully (200 OK) without any error. This will assert that the integration is working fine (The new website is an affiliate to ours)
The solution I am trying is below:- (The code below is after reaching the buy now button)
self.driver.switch_to.window(self.driver.window_handles[1])
import requests
x = requests.get(self.driver.current_url)
print(x.status_code)
This returns HTTP 302, the definition of 302 is given below:-
The HyperText Transfer Protocol (HTTP) 302 Found redirect status response code indicates that the resource requested has been temporarily moved to the URL given by the Location header.
With 302 status I cannot say my test is passed. How can I proceed with this test? What else can be done to make sure I have a valid test, asserting 302 doesn't seem to the right way.