tag:blogger.com,1999:blog-2481228809615388718.post2244684836925658191..comments2024-03-27T21:28:18.413-07:00Comments on Test Automation For Manual Testers: Selenium WebDriver Interview TestAlex Siminiuchttp://www.blogger.com/profile/13122336993155432445noreply@blogger.comBlogger25125tag:blogger.com,1999:blog-2481228809615388718.post-48167180310083792432016-04-25T17:33:21.120-07:002016-04-25T17:33:21.120-07:00this xpath expression is not good:
"/html/bod...this xpath expression is not good:<br />"/html/body/div[3]/div[2]/div[7]/div/div[1]/div[1]/form/div[2]/div/div[2]/div/div[5]/div[3]<br /><br />read the XPATH locators cheat sheet from my blog.Alex Siminiuchttps://www.blogger.com/profile/13122336993155432445noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-83916357131569438642016-04-25T17:32:01.467-07:002016-04-25T17:32:01.467-07:001. I dont see setUp() and tearDown() methods
2. ...1. I dont see setUp() and tearDown() methods<br /><br /><br />2. wait.until(EC.visibility_of_element_located((By.LINK_TEXT,"Mortgages")))<br />self.driver.find_element_by_link_text("Mortgages").click()<br /><br />These lines are redundant as any explicit wait returns a web element.<br /><br />You can save the result of the wait.until to a webelement variable and then click it.<br /><br /><br />3. time.sleep(10)<br /><br />Try avoiding any driver.findElement() statements and time.sleep(10) in your code.<br /><br />Replace both of these with explicit waits.<br /><br />See the Beginners Guide To Explicit Waits article from my blog.<br /><br /><br />4. The test script should not include any webdriver methods.<br /><br />Use the page objects model for this purpose.<br /><br />Google "page objects model" and read Martin Fowler's article for more details.Alex Siminiuchttps://www.blogger.com/profile/13122336993155432445noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-57470700358829073392016-04-25T17:30:41.464-07:002016-04-25T17:30:41.464-07:00This comment has been removed by the author.Alex Siminiuchttps://www.blogger.com/profile/13122336993155432445noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-1088568487500050162016-04-25T17:25:00.855-07:002016-04-25T17:25:00.855-07:00your code did not get uploaded so here it is:
cla...your code did not get uploaded so here it is:<br /><br />class selenium_interview_test(unittest.TestCase):<br /><br />def test_selenium_interview_test(self):<br />try:<br />self.driver = webdriver.Firefox()<br />self.driver.get("http://ia.ca/individuals")<br />wait = WebDriverWait(self.driver, 50)<br />self.driver.maximize_window()<br />wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "navbar-sub-main")))<br />self.driver.find_element_by_link_text("LOANS").click()<br />wait.until(EC.visibility_of_element_located((By.LINK_TEXT,"Mortgages")))<br />self.driver.find_element_by_link_text("Mortgages").click()<br />wait.until(EC.element_to_be_clickable((By.LINK_TEXT,"Calculate your payments")))<br /># Calculate Your Payments button<br />self.driver.find_element_by_link_text("Calculate your payments").click()<br /><br />#Verifying the element to be clickable<br />wait.until(EC.element_to_be_clickable((By.ID,"PrixProprietePlus")))<br /># Move the Purchase Price Slider to the right<br />source1 = self.driver.find_element_by_class_name('slider-track-high')<br />action = ActionChains(self.driver)<br />print source1.location<br />action.drag_and_drop_by_offset(source1,787,629).perform()<br />time.sleep(10)<br /># Change the Purchase Price to 500 000 using the + button of the slider<br />source2 = self.driver.find_element_by_class_name('slider-horizontal')<br />action = ActionChains(self.driver)<br />print source1.location<br />action.drag_and_drop_by_offset(source2,0,0).perform()<br />assert "500 000" in self.driver.find_element_by_xpath("/html/body/div[3]/div[2]/div[7]/div/div[1]/div[1]/form/div[2]/div/div[2]/div/div[5]/div[3]").text<br />wait.until(EC.element_to_be_clickable((By.ID,"MiseDeFondPlus")))<br /><br />#Change the Down Payment to 50 000 using the + button of the slider<br />self.driver.find_element_by_id("MiseDeFondPlus").click();<br />#Select 15 years for Amortization<br />wait.until(EC.visibility_of_element_located((By.NAME,"Amortissement")))<br />select = Select(self.driver.find_element_by_name('Amortissement'))<br />select.select_by_visible_text("15 years")<br />#Select Weekly for Payment Frequency<br />wait.until(EC.visibility_of_element_located((By.NAME,"FrequenceVersement")))<br />select = Select(self.driver.find_element_by_name('FrequenceVersement'))<br />select.select_by_visible_text("weekly")<br />#Change the Interest Rate to 5% by clearing the previous value and enering new value<br />wait.until(EC.visibility_of_element_located((By.ID,"TauxInteret")))<br />self.driver.find_element_by_id("TauxInteret").clear()<br />self.driver.find_element_by_id("TauxInteret").send_keys("5.00")<br />#Click the Calculate button<br />self.driver.find_element_by_id("btn_calculer").click()<br />#asserting the calculate value whther is valid or not<br />assert "$ 836.75" in wait.until(EC.visibility_of_element_located((By.ID,"paiement-resultats"))).text<br />self.driver.close()<br />except Exception, e:<br />print e<br />self.driver.quit()<br />raise<br /><br />suite = unittest.TestLoader().loadTestsFromTestCase(selenium_interview_test)<br />unittest.TextTestRunner(verbosity=2).run(suite)<br />Alex Siminiuchttps://www.blogger.com/profile/13122336993155432445noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-76936012837797642432016-04-25T06:21:32.633-07:002016-04-25T06:21:32.633-07:00Pls provide feedback.Pls provide feedback.Anonymoushttps://www.blogger.com/profile/10606238535056263593noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-44567680710853137942016-04-13T05:47:45.896-07:002016-04-13T05:47:45.896-07:00Thank u for your information. I read your shared i...Thank u for your information. I read your shared information on selnium Topic.<br /><a href="http://hyderabadsys.com/selenium-online-training/" rel="nofollow">Selenium Online Training</a> Anonymoushttps://www.blogger.com/profile/10459602416215558607noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-89224413386067821562016-04-04T07:27:35.908-07:002016-04-04T07:27:35.908-07:00more feedback
1. need a tearDown() method with th...more feedback<br /><br />1. need a tearDown() method with the @AfterMethod annotation for closing the driver<br /><br />2. driver.manage().window().maximize() can be in the setUp() method; <br />this way, if you have multiple scripts, there is no need to repeating this line in each script<br /><br />3.i dont see code for these 2 steps of the test case:<br /><br />Move the Purchase Price Slider to the right<br />Validate that the Purchase Price Slider movement works<br /><br />The purchase price slider needs to be moved by dragging and dropping.<br /><br />4. no need of a for statement for just 2 repetitions:<br /><br />for (int i = 0; i <2; i++){<br />findElementIfClickable(properties.getProperty("Purchaseprice")).click();<br />}<br /><br />5. no need of a for statement here:<br /><br />for (int i = 0; i < 1; i++){<br />findElementIfClickable(properties.getProperty("Downpayment")).click();<br />}<br /><br />6. use explicit waits (findElementIfClickable) in the selectValue and typeValue() methods<br /><br />7. the code is using properties.getProperty() for reading locators, urls, values;<br />it would be more readable if you would have something like getLocator(), getValue(), getUrl()<br /><br />8. you should validate that each step of the test script worked<br />example:<br /><br />findElementIfClickable(properties.getProperty("Purchaseprice")).click();<br />findElementIfClickable(properties.getProperty("Purchaseprice")).click();<br /><br />after changing the purchase price by clicking the + button twice, you should validate that the displayed purchase price is indeed correct (500 000)Alex Siminiuchttps://www.blogger.com/profile/13122336993155432445noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-30258547441175643052016-04-04T07:07:40.826-07:002016-04-04T07:07:40.826-07:00Yes .. that's the latest oneYes .. that's the latest oneRavi Nellurihttps://www.blogger.com/profile/09591355149863662608noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-52069788261247795902016-04-04T07:06:26.909-07:002016-04-04T07:06:26.909-07:00Ravi's latest code (April 4)
public class mor...Ravi's latest code (April 4)<br /><br />public class mortgagePaymentCalculator {<br /><br />//initialization of driver with properties file.<br /><br />static WebDriver driver;<br />static Properties properties = new Properties();<br />static FileInputStream inputproperties = null;<br /> <br />// setup method to initialize the browser type and loading the propertiy file <br />@BeforeMethod<br />public void setup() throws IOException<br />{<br /><br />driver = new ChromeDriver();<br />System.setProperty("webdriver.chrome.driver",<br />"D:\\Selenium\\BrowserPlugins\\chromedriver_win32\\chromedriver.exe");<br /><br />inputproperties = new FileInputStream("D:\\Selenium\\Frame\\Dummy\\Properties\\config.properties");<br />properties.load(inputproperties);<br /> <br />}<br /><br />@Test<br />public void calculatePayments() throws InterruptedException {<br /> <br />driver.manage().window().maximize();<br /> <br />//Navigating to the www.ia.ca, here URL value will be loaded from Property file<br />driver.navigate().to(properties.getProperty("URL"));<br /><br />//Click the Loans link<br />findElementIfClickable(properties.getProperty("Loans")).click();<br /> <br />//Click the Mortgages link<br />findElementIfClickable(properties.getProperty("Mortgages")).click();<br /> <br />// Click the Calculate Your Payments button <br />findElementIfClickable(properties.getProperty("Calculateyourpayments")).click();<br /><br />// Change the Purchase Price to 500 000 using the + button of the slide<br />for (int i = 0; i <2; i++){<br />findElementIfClickable(properties.getProperty("Purchaseprice")).click();<br />}<br /><br />// Change the Downpayment to 50 000 using the + button of the slide<br />for (int i = 0; i < 1; i++){<br />findElementIfClickable(properties.getProperty("Downpayment")).click();<br />}<br /><br />// Selecting the Amortization from list of values<br />selectValue(properties.getProperty("Amortization"),properties.getProperty("AmortizationValue"));<br /> <br />//Entering the Interestrate <br />enterValue(properties.getProperty("Interestrate"),properties.getProperty("InterestrateValue"));<br /> <br />// Selecting the Paymentequency from list of values <br />selectValue(properties.getProperty("Paymentequency"),properties.getProperty("PaymentequencyValue"));<br /> <br />// Click the Calculate button<br />findElementIfClickable(properties.getProperty("Calculate")).click();<br /> <br />// Verify that the weekly payments value is 836.75 as extracting the value<br />String value = driver.findElement(By.xpath(properties.getProperty("Monthlypayments"))).getText();<br /><br />System.out.println(value);<br /> <br />// Verifying the actuval value and derived value both are same<br />Assert.assertEquals(value, "$ 836.75" , "Test Passes");<br /><br />}<br /><br />// This methos us used to wait the driver until driver found the element<br />public static WebElement findElementIfClickable(String text) {<br /><br />WebElement element = (new WebDriverWait(driver, 200)).until(ExpectedConditions.elementToBeClickable(By.xpath(text)));<br /><br />return element;<br />}<br /> <br />//This methos is used to select the value from drop down list<br />public static void selectValue(String listbox, String inputValue) {<br /><br />try {<br />Thread.sleep(8000);<br />WebElement listBox = driver.findElement(By.xpath(listbox));<br />Select selectvalue = new Select(listBox);<br />selectvalue.selectByVisibleText(inputValue);<br /><br />} catch (Exception e) {<br />throw new RuntimeException("Exception while procesing selectValueFromListBox: ", e);<br />}<br />}<br /> <br />//This methos is used to enter the value to a text box<br />public static void enterValue(String textBox, String inputValue) {<br /><br />try {<br />driver.findElement(By.xpath(textBox)).click();<br />driver.findElement(By.xpath(textBox)).clear();<br />driver.findElement(By.xpath(textBox)).sendKeys(inputValue);<br />} catch (Exception e) {<br />throw new RuntimeException("Exception while procesing enterTextboxValue: ", e);<br />}<br />}Alex Siminiuchttps://www.blogger.com/profile/13122336993155432445noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-62169047399678273392016-04-01T11:16:43.683-07:002016-04-01T11:16:43.683-07:00this feedback applies to the last version of your ...this feedback applies to the last version of your code.<br /><br />1. both TestNg and JUNIT have @Before annotation for setting up the test <br />environment.<br /><br />If you use the @Before annotation for the setUp() method, this annotation of the test script does not need the DependsOnMethods() part:<br /><br />@Test(dependsOnMethods={"setup"})<br /><br />2. navigating to the first page should be done in the test script instead of the setUp() method:<br /><br />driver.navigate().to(properties.getProperty("URL"));<br /><br />this is because the test class may have test scripts that start with a different page<br /><br />3. the names of your methods are not clear at all.<br /><br />the name of any method should be short, descriptive and clear.<br /><br />public void cal() is none of those.<br /><br />something like testCalculatePayments() is better.<br /><br />the same can be said about<br /><br />selectValueFromListBox - selectValue() is sufficient as you cannot make selections for other html elements<br /><br />enterTextboxValue - text box is the only element where you can type a value; how about type() as a name?<br /><br />4. use the findElementIfClickable() not only in the test script but in all methods<br /><br />Change the code based on this feedback and then add comments about where each step of the test case is implemented.<br /><br />Thanks.<br /><br />Alex<br />Alex Siminiuchttps://www.blogger.com/profile/13122336993155432445noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-88890273292071638462016-03-31T19:15:51.302-07:002016-03-31T19:15:51.302-07:00Any new assignments Any new assignments Ravi Nellurihttps://www.blogger.com/profile/09591355149863662608noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-51422588305627424552016-03-30T10:25:27.032-07:002016-03-30T10:25:27.032-07:00Hi Riyan,
Please see below the first feedback for...Hi Riyan,<br /><br />Please see below the first feedback for you.<br /><br />Thanks.<br /><br />Alex<br /><br />1. the purpose of the method that uses the @Before annotation is to prepare the test environment needed by the test scripts;<br /><br />calling this method selectBrowser() is incorrect as many other things may need to be done in this method<br /><br />a better name than selectBrowser() is needed such as setUp() or prepareEnvironment();<br /><br /><br />2. you can declare the WebDriverWait as a class member and instantiate it (wait = new WebDriverWait(driver,20);) in the setUp() method. <br /><br /><br />3. the driver.get("http://www.ia.ca") command should not be in the setUp() method (using the @Before annotation) as it is possible that <br />some of the test scripts do not start on the home page<br /><br /><br />4. this explicit wait returns a web element:<br /><br />wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(text(), 'Loans')]")));<br /><br />an explicit wait of this type can be used instead of driver.findElement() as it has the advantage that it waits for the element until the element is<br />available.<br /><br /><br />5. this xpath expression is not optimal:<br /><br />".//*[@id='main']/div[2]/div[4]/div[1]/div[2]/a"<br /><br />you should build xpath expressions that use the tag and attributes of the element to be found<br /><br /><br />6. save all xpath expressions as class membersAlex Siminiuchttps://www.blogger.com/profile/13122336993155432445noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-68611535903857460202016-03-30T05:21:43.272-07:002016-03-30T05:21:43.272-07:00CODE POSTED BY RIYAN:
Riyan has left a new commen...CODE POSTED BY RIYAN:<br /><br />Riyan has left a new comment on your post "Selenium WebDriver Interview Test": <br /><br />public class MortgagePaymentCalculator {<br />WebDriver driver;<br /><br />@Before<br />public void SelectBrowser(){<br /><br />//1. Open the www.ia.ca in the Chrome browser<br />String browserName = System.getenv("browser");<br />if(browserName != null && browserName.equalsIgnoreCase("chrome")){<br />driver = new ChromeDriver();<br />}<br />else{<br />driver =new FirefoxDriver();<br />}<br />driver.get("http://www.ia.ca");<br />driver.manage().window().maximize();<br /><br />}<br /><br />@Test<br />public void MortgageCalculate() throws InterruptedException{<br /><br />//1. Click LOANS<br />WebDriverWait wait = new WebDriverWait(driver,20);<br />wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(text(), 'Loans')]")));<br /><br />WebElement loanLink = driver.findElement(By.xpath("//span[contains(text(), 'Loans')]"));<br /><br />loanLink.click();<br /><br />//2. Click the Mortgages link<br /><br />WebElement mortgagesLink = driver.findElement(By.xpath("//a[contains(text(), <br />'Mortgages')]"));<br /><br />mortgagesLink.click();<br /><br />//3. Click the Calculate Your Payments button<br /><br />WebElement calculateButton = driver.findElement(By.xpath(".//*[@id='main']/div[2]/div[4]/div[1]/div[2]/a"));<br /><br />calculateButton.click();<br /><br />//6. Move the Purchase Price Slider to the right<br /><br />WebElement purchaseSlider = driver.findElement(By.xpath(".//*[@id='form_calculateur_versements']/div[2]/div/div[2]/div/div[1]/div[9]"));<br /><br />WebElement to = driver.findElement(By.xpath("//*[@id='form_calculateur_versements']/div[2]/div/div[2]/div/div[1]/div[3]"));<br /><br />Actions builder = new Actions(driver);<br />Action dragAndDrop = builder.clickAndHold(purchaseSlider)<br />.moveToElement(to)<br />.release(to)<br />.build();<br /><br />dragAndDrop.perform(); <br /><br />//7. Validate that the Purchase Price Slider movement works<br /><br />boolean moved = false;<br /><br />if(purchaseSlider != null){<br />moved = true;<br />}<br />System.out.println(moved);<br />Assert.assertTrue(moved, "Price Slider movement works");<br /><br />//8. Change the Purchase Price to 500 000 using the + button of the slider<br />WebElement minusButton= driver.findElement(By.id("PrixProprieteMinus"));<br /><br />for(int i=0;i<5;i++){<br />minusButton.click();<br />}<br /><br />WebElement plusButton = driver.findElement(By.id("PrixProprietePlus"));<br /><br />for(int i=0;i<2;i++){<br /><br />plusButton.click();<br /><br />}<br /><br />//9. Change the Down Payment to 50 000 using the + button of the slider<br /><br />WebElement downPayment = driver.findElement(By.xpath(".//*[@id='MiseDeFondPlus']"));<br /><br />downPayment.click();<br /><br />//10. Select 15 years for Amortization<br /><br />Select select = new Select(driver.findElement(By.xpath(".//*[@id='Amortissement']")));<br /><br />select.selectByVisibleText("15 years");;<br />//11. Select Weekly for Payment Frequency<br /><br />Select select1 = new Select(driver.findElement(By.xpath(".//*[@id='FrequenceVersement']")));<br /><br />select1.selectByVisibleText("weekly");;<br />//12. Change the Interest Rate to 5%<br /><br />WebElement interestRate = driver.findElement(By.xpath(".//*[@id='TauxInteret']"));<br /><br />interestRate.clear();<br /><br />interestRate.sendKeys("5");<br /><br />//13. Click the Calculate button<br />WebElement calculate = driver.findElement(By.xpath(".//*[@id='btn_calculer']"));<br /><br />calculate.click();<br /><br />Thread.sleep(3000);<br /><br />//14. Verify that the weekly payments value is 836.75<br /><br />WebElement paymentValue = driver.findElement(By.xpath(".//*[@id='paiement-resultats']"));<br /><br />String result = paymentValue.getText();<br /><br />Assert.assertEquals(result, "$ 836.75", "Test passed");<br /><br />}<br /><br />@After<br />public void TearDown(){<br /><br />driver.quit();<br /><br />}<br /><br />}Alex Siminiuchttps://www.blogger.com/profile/13122336993155432445noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-10423033381558793822016-03-30T05:16:00.499-07:002016-03-30T05:16:00.499-07:00if you upload your code and it does not show up on...if you upload your code and it does not show up on the page, feel free to email it to me at alex@alexsiminiuc.com.<br /><br />i will upload it for you.Alex Siminiuchttps://www.blogger.com/profile/13122336993155432445noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-25177302580163508772016-03-30T04:52:27.256-07:002016-03-30T04:52:27.256-07:00Hi Ravi,
this is your code.
I will provide feedb...Hi Ravi,<br /><br />this is your code.<br /><br />I will provide feedback shortly.<br /><br />thanks.<br /><br />Alex<br /><br />URL=http://www.ia.ca/individuals<br />Loans=//span[contains(.,'Loans')]<br />Mortgages=//a[contains(.,'Mortgages')]<br />Calculateyourpayments=//a[contains(.,'Calculate your payments')]<br />Purchaseprice=//button[contains(@id,'PrixProprietePlus')]<br />Downpayment=//button[contains(@id,'MiseDeFondPlus')] <br />Amortization=//select[contains(@name,'Amortissement')]<br />AmortizationValue=15 years<br />Interestrate=//input[contains(@class,'toNumber')]<br />InterestrateValue=5<br />Paymentequency=//select[contains(@id,'FrequenceVersement')]<br />PaymentequencyValue=weekly<br />Calculate=//button[contains(.,'Calculate')]<br />Monthlypayments=.//*[@id='paiement-resultats']<br /><br /><br />static WebDriver driver;<br /><br />static Properties properties = new Properties();<br />static FileInputStream inputproperties = null;<br /><br />@Test<br />public void setup() throws IOException<br />{<br /><br />driver = new ChromeDriver();<br />System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\BrowserPlugins\\chromedriver_win32\\chromedriver.exe");<br /> <br />inputproperties = new FileInputStream("D:\\Selenium\\Frame\\Dummy\\Properties\\config.properties");<br /><br />properties.load(inputproperties);<br />driver.manage().window().maximize();<br />driver.navigate().to(properties.getProperty("URL"));<br /><br />}<br /><br />@Test(dependsOnMethods={"setup"})<br />public void cal() throws InterruptedException {<br /> findElementIfClickable(properties.getProperty("Loans")).click();<br /> findElementIfClickable(properties.getProperty("Mortgages")).click();<br /> findElementIfClickable(properties.getProperty("Calculateyourpayments")).click();<br /><br />for (int i = 0; i <2; i++){<br /> findElementIfClickable(properties.getProperty("Purchaseprice")).click();<br /><br />}<br /><br />for (int i = 0; i < 1; i++){<br /> findElementIfClickable(properties.getProperty("Downpayment")).click();<br /><br />}<br /><br />selectValueFromListBox(properties.getProperty("Amortization"),properties.getProperty("AmortizationValue"));<br /> <br />enterTextboxValue(properties.getProperty("Interestrate"),properties.getProperty("InterestrateValue"));<br /> <br />selectValueFromListBox(properties.getProperty("Paymentequency"),properties.getProperty("PaymentequencyValue"));<br /> <br />findElementIfClickable(properties.getProperty("Calculate")).click();<br /> <br />String value = driver.findElement(By.xpath(properties.getProperty("Monthlypayments"))).getText();<br /><br />System.out.println(value);<br />Assert.assertEquals(value, "$ 836.75");<br /><br />}<br /><br />public static WebElement findElementIfClickable(String text) {<br /><br />WebElement element = (new WebDriverWait(driver, 200)).until(ExpectedConditions.elementToBeClickable(By.xpath(text)));<br /><br />return element;<br /><br />}<br /> <br />public static void selectValueFromListBox(String listbox, String inputValue) <br />{<br /><br />try {<br /><br />Thread.sleep(8000);<br />WebElement listBox = driver.findElement(By.xpath(listbox));<br />Select selectvalue = new Select(listBox);<br />selectvalue.selectByVisibleText(inputValue);<br /><br />} catch (Exception e) {<br /><br />throw new RuntimeException("Exception while procesing selectValueFromListBox: ", e);<br /><br />}<br />}<br /> <br />public static void enterTextboxValue(String textBox, String inputValue) {<br /><br />try {<br /><br />driver.findElement(By.xpath(textBox)).click();<br />driver.findElement(By.xpath(textBox)).clear();<br /> driver.findElement(By.xpath(textBox)).sendKeys(inputValue);<br /><br />} catch (Exception e) {<br /><br />throw new RuntimeException("Exception while procesing enterTextboxValue: ", e);<br /><br />}<br />}Alex Siminiuchttps://www.blogger.com/profile/13122336993155432445noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-42237814595637741062016-03-30T04:09:45.855-07:002016-03-30T04:09:45.855-07:00Alex mailed the latest code to alex@alexsiminiuc.c...Alex mailed the latest code to alex@alexsiminiuc.com . Please check and let me know comments . Whenever I pasted the code and refresh posted code is not displaying so, I mailed Ravi Nellurihttps://www.blogger.com/profile/09591355149863662608noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-58614206974012912082016-03-30T00:20:22.041-07:002016-03-30T00:20:22.041-07:00Hi Ravi,
You are welcome.
We are not done here :...Hi Ravi,<br /><br />You are welcome.<br /><br />We are not done here :)<br /><br />Upload the changed code for more feedback.<br /><br />Thanks,<br /><br />AlexAlex Siminiuchttps://www.blogger.com/profile/13122336993155432445noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-91242551187994423092016-03-29T19:11:28.013-07:002016-03-29T19:11:28.013-07:00Thx for your knowledge share :) . Looking more ass...Thx for your knowledge share :) . Looking more assignments Ravi Nellurihttps://www.blogger.com/profile/09591355149863662608noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-79262302308845208232016-03-29T10:17:49.932-07:002016-03-29T10:17:49.932-07:00Hi Ravi,
I missed adding to my feedback that you ...Hi Ravi,<br /><br />I missed adding to my feedback that you should change the return type of the ExplicitWait() method to WebElement and that you should return the found WebElement object:<br /><br />public static WebElement ExplicitWait(String text) {<br /><br />WebElement element = (new WebDriverWait(driver, 100)).until(ExpectedConditions.elementToBeClickable(By.xpath(text)));<br /><br />return element;<br />}<br /><br />Hope this helps,<br /><br />AlexAlex Siminiuchttps://www.blogger.com/profile/13122336993155432445noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-41596344694904862042016-03-29T09:52:28.973-07:002016-03-29T09:52:28.973-07:00I used property file to store all the xpaths. I di...I used property file to store all the xpaths. I did not understand the 2 and 3 rd points . How can I add those two points in to 1. if we do then .click() event will not be present as it's work only for element. Please let me know if i am wrong <br /><br /><br />URL=http://www.ia.ca/individuals<br />Loans=//span[contains(.,'Loans')]<br />Mortgages=//a[contains(.,'Mortgages')]<br />Calculateyourpayments=//a[contains(.,'Calculate your payments')]<br />Purchaseprice=//button[contains(@id,'PrixProprietePlus')]<br />Downpayment=//button[contains(@id,'MiseDeFondPlus')] <br />Amortization=//select[contains(@name,'Amortissement')]<br />Interestrate=//input[contains(@class,'toNumber')]<br />Paymentequency=//select[contains(@id,'FrequenceVersement')]<br />Calculate=//button[contains(.,'Calculate')]<br />Monthlypayments=.//*[@id='paiement-resultats']Ravi Nellurihttps://www.blogger.com/profile/09591355149863662608noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-10905239214905935452016-03-29T00:36:49.361-07:002016-03-29T00:36:49.361-07:00Hi Ravi,
Please see feedback below.
Thanks,
Ale...Hi Ravi,<br /><br />Please see feedback below.<br /><br />Thanks,<br /><br />Alex<br /><br />1. rename ExplicitWait to findElementIfClickable()<br /><br />2. replace the next 2 lines <br /><br />ExplicitWait("//a[contains(.,'Calculate your payments')]");<br />driver.findElement(By.xpath("//a[contains(.,'Calculate your payments')]")).click();<br /><br />with <br /><br />findElementIfClickable("//a[contains(.,'Calculate your payments')]").click();<br /><br />3. use findElementIfClickable() instead of driver.findElement()<br /><br />4. save all your xpath expressions in class variables so that they can be used by other class test scripts<br /><br />5. do you have to use a static driver variable? does the test script have to be static?<br /><br />6. move these 3 lines to the setUp() method:<br /><br />System.setProperty("webdriver.chrome.driver",<br />"D:\\Selenium\\BrowserPlugins\\chromedriver_win32\\chromedriver.exe");<br /><br />driver = new ChromeDriver();<br /><br />driver.manage().window().maximize();<br /><br />7. do not use xpath expression if the element has id attributeAlex Siminiuchttps://www.blogger.com/profile/13122336993155432445noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-86611523564820301922016-03-28T03:09:38.774-07:002016-03-28T03:09:38.774-07:00static WebDriver driver = new ChromeDriver();
@Te...static WebDriver driver = new ChromeDriver();<br /> @Test<br /> public static void cal() throws InterruptedException {<br /><br /> System.setProperty("webdriver.chrome.driver",<br /> "D:\\Selenium\\BrowserPlugins\\chromedriver_win32\\chromedriver.exe");<br /><br /> driver.manage().window().maximize();<br /> driver.navigate().to("http://www.ia.ca/individuals");<br /> ExplicitWait("//span[contains(.,'Loans')]");<br /> driver.findElement(By.xpath("//span[contains(.,'Loans')]")).click();<br /> driver.findElement(By.xpath("//a[contains(.,'Mortgages')]")).click();<br /> ExplicitWait("//a[contains(.,'Calculate your payments')]");<br /> driver.findElement(By.xpath("//a[contains(.,'Calculate your payments')]")).click();<br /><br /> for (int i = 0; i <2; i++){<br /><br /> ExplicitWait("//button[contains(@id,'PrixProprietePlus')]");<br /><br /> driver.findElement(By.xpath("//button[contains(@id,'PrixProprietePlus')]")).click();<br /> }<br /><br /> for (int i = 0; i < 1; i++){<br /><br /> driver.findElement(By.xpath("//button[contains(@id,'MiseDeFondPlus')]")).click();<br /> }<br /><br /> WebElement listBox = driver.findElement(By.xpath("//select[@id='']"));<br /> Select selectvalue = new Select(listBox);<br /> selectvalue.selectByValue("15");<br /><br /> WebElement Irate = driver.findElement(By.xpath("//input[contains(@class,'toNumber')]"));<br /> Irate.clear();<br /> Irate.sendKeys("5");<br /> WebElement listBox1 = driver.findElement(By.xpath("//select[contains(@id,'FrequenceVersement')]"));<br /> Select selectvalue1 = new Select(listBox1);<br /> selectvalue1.selectByVisibleText("weekly");<br /><br /> driver.findElement(By.xpath("//button[contains(.,'Calculate')]")).click();<br /> String value = driver.findElement(By.xpath(".//*[@id='paiement-resultats']")).getText();<br /> System.out.println(value);<br /> Assert.assertEquals(value, "$ 836.75");<br /><br /> }<br /><br /> public static void ExplicitWait(String text) {<br /> (new WebDriverWait(driver, 100)).until(ExpectedConditions.elementToBeClickable(By.xpath(text)));<br /> }Ravi Nellurihttps://www.blogger.com/profile/09591355149863662608noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-73552162188407717002016-03-27T12:04:43.866-07:002016-03-27T12:04:43.866-07:00Hi Kamarajsivam,
The first 4 suggestions for you ...Hi Kamarajsivam,<br /><br />The first 4 suggestions for you are below:<br /><br />1. create xpath expressions that are simpler, shorter and do not depend on the position of the element.<br /><br />the following expression will not work if the final element is moved around in the page:<br /><br />driver.findElement(By.xpath("//*[@id='nav-secondaire']/div[1]/ul/li[4]/ul/li[1]/section/ul/li[1]/a")).click();<br /><br />your xpath expression should try to find the final node using the // operator, the element tag and the element attributes.<br /><br />2. if the same element is used in multiple actions (clear() and sendKeys()), save the element in a WebElement variable and use the variable.<br /><br />this avoids finding the element multiple times:<br /><br />driver.findElement(By.id("TauxInteret")).clear();<br />driver.findElement(By.id("TauxInteret")).sendKeys("5.00");<br /><br />3. use explicit waits instead of driver.findElement() to avoid using delays (thread.sleep(10000)).<br /><br />Thread.sleep(10000);<br />driver.findElement(By.xpath(".//*[@id='btn_calculer']")).click();<br /><br />4. use JUNIT or TEST NG assertions in your test script for making verifications:<br /><br />String value = driver.findElement(By.xpath(".//*[@id='paiement-resultats']")).getText();<br />if (value == "$ 836.75") <br />System.out.println("TEXT");<br />else <br />System.out.println("Not TEXT");<br /><br />Please make these changes and re-submit the code for additional feedback.<br /><br />Thanks,<br /><br />AlexAlex Siminiuchttps://www.blogger.com/profile/13122336993155432445noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-78981203636329544462016-03-24T11:29:20.367-07:002016-03-24T11:29:20.367-07:00Hi Kamarajsivam,
Can you please post the code aga...Hi Kamarajsivam,<br /><br />Can you please post the code again and explain where each step of the test case is handled?<br /><br />Thanks.<br /><br />AlexAlex Siminiuchttps://www.blogger.com/profile/13122336993155432445noreply@blogger.comtag:blogger.com,1999:blog-2481228809615388718.post-18391120954359258602016-03-24T07:31:25.034-07:002016-03-24T07:31:25.034-07:00System.setProperty("webdriver.chrome.driver&q...System.setProperty("webdriver.chrome.driver", "D:/Kamaraj/selenium-java-2.52.0/chromedriver.exe");<br /> WebDriver driver = new ChromeDriver();<br /> driver.get("http://www.ia.ca/individuals");<br /> driver.manage().window().maximize();<br /> driver.findElement(By.xpath("//*[@id='nav-secondaire']/div[1]/ul/li[4]/a")).click();<br /> driver.findElement(By.xpath("//*[@id='nav-secondaire']/div[1]/ul/li[4]/ul/li[1]/section/ul/li[1]/a")).click();<br /> driver.findElement(By.xpath(".//*[@id='main']/div[2]/div[4]/div[1]/div[2]/a")).click();<br /> for (int i = 0; i < 2; i++){<br /> driver.findElement(By.xpath(".//*[@id='PrixProprietePlus']")).click();<br /> }<br /> for (int i = 0; i < 1; i++){<br /> driver.findElement(By.xpath(".//*[@id='MiseDeFondPlus']")).click();<br /> }<br /> Select oselect = new Select(driver.findElement(By.id("Amortissement")));<br /> oselect.selectByValue("15");<br /> Select oselect2 = new Select(driver.findElement(By.id("FrequenceVersement")));<br /> oselect2.selectByValue("52");<br /> driver.findElement(By.id("TauxInteret")).clear();<br /> driver.findElement(By.id("TauxInteret")).sendKeys("5.00");<br /> Thread.sleep(10000);<br /> driver.findElement(By.xpath(".//*[@id='btn_calculer']")).click();<br /> Thread.sleep(10000);<br /> String value = driver.findElement(By.xpath(".//*[@id='paiement-resultats']")).getText();<br /> if (value == "$ 836.75") {<br /> System.out.println("TEXT");}<br /> else {<br /> System.out.println("Not TEXT");<br /> }<br /> }<br />Kamarajsivamhttps://www.blogger.com/profile/17456027672875639683noreply@blogger.com