def test_formSubmission(self, getData): log = self.getLogger() homepage = HomePage(self.driver) log.info("first_name is " + getData["first_name"]) homepage.getName().send_keys(getData["first_name"]) # driver.find_element_by_css_selector("[name='name']").send_keys("Tito") homepage.getEmail().send_keys(getData["last_name"]) # driver.find_element_by_name("email").send_keys("Novianto") homepage.getCheckBoxBtn().click() # driver.find_element_by_id("exampleCheck1").click() self.selectOptionByText(homepage.getGenderSel(), getData["gender"]) # sel = Select(homepage.getGenderSel()) # sel = Select(driver.find_element_by_id("exampleFormControlSelect1")) # sel.select_by_visible_text("Male") homepage.getSubmitBtn().click() # driver.find_element_by_xpath("//input[@value='Submit]").click() alertText = homepage.getAlertText().text # alertText = driver.find_element_by_css_selector("[class*='alert-success']").text assert ("Success" in alertText) #To solve the below problem, one solution can be as following self.driver.refresh()
def test_formSubmission(self, getData): log = self.getLogger() # driver = webdriver.Chrome(executable_path="/Users/ami23772/Downloads/Study/Selenium_with_Python/chromedriver") # driver.get("https://rahulshettyacademy.com/angularpractice/") homepage = HomePage(self.driver) homepage.getName().send_keys(getData["firstname"]) homepage.getEmail().send_keys(getData["email"]) homepage.getPassword().send_keys(getData["password"]) homepage.getCheckout().click() # dropdown = Select(self.driver.find_element_by_id("exampleFormControlSelect1")) """ This is very exhaustive way and not to say hardcoded homepage.getGender().select_by_visible_text("Female") time.sleep(1) homepage.getGender().select_by_visible_text("Male") We can make it more flexible and reusable by making it generic in BaseClass then call the method and pass text """ self.selectOptionByText(homepage.getGender(), getData["gender"]) radio = self.driver.find_elements_by_name("inlineRadioOptions") radio[1].click() # self.selectRadioOption(homepage.getEmploymentStatus(), "Employed") time.sleep(1) homepage.getDOB().send_keys(getData["birthdate"]) log.info("Entered data is: " + getData['firstname'] + " " + getData['email'] + " " + getData['gender'] + " " + getData['birthdate']) time.sleep(1) # from here we assert the page content and then submit the form then we will go to shop # assert driver.execute_script("return document.getElementsByName('name')[0].value") == "A B C" # assert driver.execute_script("return document.getElementsByName('email')[0].value") == "*****@*****.**" # assert driver.execute_script("return document.getElementById('exampleInputPassword1').value") != "" # assert driver.execute_script("return document.getElementById('exampleFormControlSelect1').value") == "Male" # assert radio[1].is_selected() # assert driver.execute_script("return document.getElementsByName('bday')[0].value") == "1999-12-21" homepage.getButton().click() time.sleep(1) log.info("Text after submission is: " + homepage.getMessage().text) assert "Success" in homepage.getMessage().text self.driver.refresh()