Automation task practice paper

Lot of interviewers nowadays give some practical problems to solve. One of such problem we will share in this article. It is often used to test your knowledge on the core concepts of Selenium Automation. Make sure you practice this before appearing for the interview.

Automation task practice paper

1. Open the browser 2. Enter the URL http://practice.automationtesting.in/ 3. Click on Shop Menu 4. Now click on Home menu button
5. Test whether the Home page has Three Arrivals only 6. Now click on one of the images in Arrivals 7. Click on the ADD TO BASKET button 8. Test whether the VIEW BASKET button is visible and click on it 9. Now user can find total and subtotal values just above the Proceed to Checkout button, test if the total is greater than the subtotal 10. Click the PROCEED TO CHECKOUT button 11. Fill in all required fields, set Cash on Delivery as your payment method, and click PLACE ORDER. 12. Check if the Payment method is set to Cash on Delivery in both fields


Try to solve the above problem statement and comment with your answers. We will soon share the code for this problem.
Solution
package TesteTema; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.jupiter.api.Assertions; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; public class AutomationDemo { @Test public void TesteTema() throws InterruptedException { System.setProperty("webdriver.chrome.driver", "src/main/resources/chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("http://practice.automationtesting.in/"); driver.manage().window().maximize(); Thread.sleep(2000); driver.findElement(By.xpath("//li/a[contains(text(),'Shop')]")).click(); driver.findElement(By.xpath("//a[contains(text(),'Home')]")).click(); int ele = driver.findElements(By.xpath("//a/img[contains(@class,'attachment-shop')]")).size(); System.out.println(ele); assertEquals(3,ele,"Test Passed"); driver.findElement(By.xpath("//a/img[contains(@title,'Thinking in HTML')]")).click(); driver.findElement(By.xpath("//a/img[contains(@title,'Mastering ')]")).click(); driver.findElement(By.xpath("//button[@type='submit']")).submit(); if( driver.findElement(By.xpath("//a[contains(text(),'View Basket')]")).isDisplayed()) { System.out.println("Element is Visible"); driver.findElement(By.xpath("//a[contains(text(),'View Basket')]")).click(); } WebElement elem1 = driver.findElement(By.xpath("//*[@id=\"page-34\"]/div/div[1]/div/div/table/tbody/tr[1]/td/span")); WebElement elem2 = driver.findElement(By.xpath("//*[@id=\"page-34\"]/div/div[1]/div/div/table/tbody/tr[3]/td/strong/span")); double var1 = Double.parseDouble(elem1.getText().substring(1)); double var2 = Double.parseDouble(elem2.getText().substring(1)); assertTrue(var2>var1); driver.findElement(By.xpath("//a[contains(text(),'Proceed to Checkout')]")).click(); driver.findElement(By.xpath("//input[@id='billing_first_name']")).sendKeys("romeo"); Thread.sleep(2000); driver.findElement(By.xpath("//input[@id='billing_last_name']")).sendKeys("ion"); Thread.sleep(2000); driver.findElement(By.xpath("//input[@id='billing_email']")).sendKeys("romeo@yahoo.com"); Thread.sleep(2000); driver.findElement(By.xpath("//input[@id='billing_phone']")).sendKeys("023423595"); Thread.sleep(2000); driver.findElement(By.xpath("//input[@id='billing_address_1']")).sendKeys("sec 2"); Thread.sleep(2000); driver.findElement(By.xpath("//input[@id='billing_city']")).sendKeys("bucharest"); Thread.sleep(2000); driver.findElement(By.xpath("//input[@id='billing_postcode']")).sendKeys("012345"); Thread.sleep(2000); List<WebElement> allOptions = driver.findElements(By.xpath("//span[@class='select2-chosen']")); System.out.println(allOptions.size()); WebElement radio1 = driver.findElement(By.xpath("//li[@class='wc_payment_method payment_method_cod']")); radio1.click(); Thread.sleep(2000); driver.findElement(By.xpath("//input[@value='cod']")).click(); driver.findElement(By.xpath("//input[@id='place_order']")).click(); WebElement var3 = driver.findElement(By.xpath("//*[@id=\"page-35\"]/div/div[1]/ul/li[4]/strong")); WebElement var4 = driver.findElement(By.xpath("//*[@id=\"page-35\"]/div/div[1]/table/tfoot/tr[3]/td")); String varr3 = var3.getText(); String varr4 = var4.getText(); assertEquals("Cash On Delivery", varr3); assertEquals("Cash On Delivery", varr4); driver.quit();


Comments

Popular posts from this blog

Azure Tutorials Series - Azure Networking

Coforge Interview Questions | Automation Testing profile

Testing in CI/CD