Mohamed Nazeer’s Post

View profile for Mohamed Nazeer, graphic

Test Lead | Automation testing | Selenium | Cucumber | Test NG

Dear Connections Whoever interested in Selenium and Automation Interview questions or if you preparing for an interview,I am going to post 4 or 5 Important questions and Answers as a Series ,Pls learn it whenever you see it -- Starts Episode 1 What is Stale element exception? StaleElementReferenceException is one of the most common Selenium exceptions when the web element you are trying to interact with is no longer associated in the DOM Reason 1: When element you are finding is moved Reason 2 :When element your are finding is deleted Solution1 : Use Explicit WebDriverwait Method 1: Wait until the element is present wait.until(ExpectedConditions.presenceOfElementLocated(Web element locator"))) Solution2. Use the try-catch block WebElement element = driver.findElement(By.id("web element locator")); try {     element.click(); } catch (StaleElementReferenceException e) {   // Refresh the page   driver.navigate().refresh();    // Try to locate the element again   element = driver.findElement(By.id("web element locator "));   element.click(); } Solution 3. Use Page Object Model Solution 4: Refresh the web page How do you optimize the code for selenium? ·      Use concise code ·      Give proper Naming conversion, ·      No hard coded values ·      //Commenting code with details ·      Avoid code duplicates ·      Use fast locators - wherever applicable use css ·      Use parallel testing ·      Use headless browser testing - improves performance ·      Prioritize test cases: Focus on critical functionality first, and split large test suites into smaller chunks. ·      Remove redundant tests: Remove redundant and outdated tests. ·      Write shorter tests: Keep the number of steps in each test under 20. How to run parallel tests in TestNG? Pre--requisite:  Step 1 To create a testing.xml file, right click on the ParallelTest class and select TestNG >> Convert To TestNG. Executing Test Classes in Parallel using TestNG Step 1 To run classes in parallel mode, create two class files as ChromeTest and FirefoxTest with three test methods. Step 2 In the testing.xml file, add class names and update parallel value as classes and run it. Example -<suite name="Suite" parallel="classes"> How to do datadriven testing in testing? ·      Using dataprovider annotations ,we can achieve data driven testing by the parameterizing the tests ·      We allowing the same test method to be executed multiple times with different sets of input data. Different types of framework? Linear Scripting Framework is a basic level test automation framework that is in the form of ‘Record and Playback’ in a linear fashion. Modular Testing Framework: In the modular testing framework, testers create test scripts module wise by breaking down the complete application under test into smaller, independent tests. Data-driven Framework: It allows us to create test automation scripts by passing different sets of test data.

How to run parallel test cases in TestNG | BrowserStack

How to run parallel test cases in TestNG | BrowserStack

browserstack.com

To view or add a comment, sign in

Explore topics