1 / 22

DevLabs_Alliance_Top 20 Advanced Selenium Interview Questions for SDET

DevLabs_Alliance_Top 20 Advanced Selenium Interview Questions for SDET

Download Presentation

DevLabs_Alliance_Top 20 Advanced Selenium Interview Questions for SDET

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Top 20 Advanced Selenium Interview Questions for SDET By DevLabs Alliance Visit us at: www.devlabsalliance.com Email: training@devlabsalliance.com Contact: +91 9717514555

  2. Advanced Selenium Interview Questions for SDET 1. What will happen if you mix both implicit wait and explicit wait in a Selenium Script? According to the official Selenium documents, it is being suggested to not to mix both Implicit and Explicit Waits. If we mix both of them then it can cause unpredictable wait times. Implicit wait is defined only once in the code and it will remain same throughout the driver object instance. Explicit wait is defined wherever it is necessary in the code and it will called at the time of execution. Explicit wait will overwrite the implicit wait if applied in the code. So, Explicit Wait always gets first preference and the then Implicit Wait is executed.

  3. Advanced Selenium Interview Questions for SDET 2. What will happen if you run this command. driver.get(“www.devlabsalliance.com”) ; Since the given URL doesn’t contain http or https prefix hence it will throw an exception. So, it is required to pass HTTP or HTTPS protocol within driver.get() method. driver.get(“https://www.devlabsalliance.com”);

  4. Advanced Selenium Interview Questions for SDET 3. What is MaxInstances Properties in Selenium Grid? MaxInstances is defined as the number of browser instances of the same version of the browser that can run on the remote machine. for eg.-browser browserName=InternetExplorer,version=11,maxInstances=3,platform=WINDOWS -browser browserName=Firefox,version=12,maxInstances=2,platform=WINDOWS This will allow to run 5 instances (3 instances of IE and 2 instances of Firefox) at the same time in a remote machine.

  5. Advanced Selenium Interview Questions for SDET 4. What is MaxSession Properties in Selenium Grid? MaxSession is defined as a number of browsers, independent of the type & version, can run in parallel on the remote machine. MaxSession overrides the MaxInstances settings and hence can restrict the number of browser instances that can run in parallel. For eg. If maxSession=1 then only a single browser will run in remote machine. If maxSession=2 then any two browsers can run at a time irrespective of MaxInstances that we defined. It can be either 2 Internet Explorer or 2 FireFox or 1 Internet Explorer and 1 Firefox. browser browserName=firefox,maxInstances=5,maxSession=2

  6. Advanced Selenium Interview Questions for SDET 5. How can we handle Web-based Pop-ups or Alerts in Selenium? Web-based alerts or popups are handled by switching to the alert window and calling Selenium WebDriver Alert API methods.Below methods are called for various actions: • dismiss(): To click on Cancel button. • accept(): To Click on OK button. • getText(): To get the text which is present on the Alert. • sendKeys(): To enter the text into the alert box.

  7. Advanced Selenium Interview Questions for SDET 6. What happen if you mix both Thread.Sleep and WebDriver Waits in a Selenium Script? Thread.sleep() method is used to pause the execution of script for specified time in milliseconds If WebDriver waits are used along with Thread.sleep() method, then webdriver will hold the execution for specified time (as mentioned in Thread.sleep()) and then will follow other wait. If we mix both the waits, then test execution time will increase.

  8. Advanced Selenium Interview Questions for SDET 7. How can you use the Recovery Scenario in Selenium WebDriver? Recovery Scenarios are used by using “Try Catch” block within Selenium WebDriver Java tests. try{driver.get("https://www.devlabsalliance.com");}catch{System.Out.println(e.getMessage());}

  9. Advanced Selenium Interview Questions for SDET 8. What is Robot Class in Selenium and what are its advantages? Robot Class is used to control the keyboard or mouse to interact with Operating System windows like download pop-ups, alerts, print pop-ups, etc or native OS applications like Notepad, Calculator, Skype, etc. while doing browser automation. The various advantages of Robot Class are: • It simulates Mouse and Keyboard events. • It helps in upload/download of files while using Selenium webdriver. • It gets easily integrated with current automation framework (keyword-driven, data-driven or hybrid framework).

  10. Advanced Selenium Interview Questions for SDET 9. What are various Robot Class internal methods and explain their usage. Some of the Robot Class Internal methods and their usage are as follows: • keyPress():eg. : robot.keyPress(KeyEvent.VK_Down) : This method will press down the arrow key of keyboard. • mouseMove(): eg. robot.mouseMove(point.getX(), point.getY()) : This will move the mouse pointer to specific X and Y coordinates. • mousePress(): eg. robot.mousePress(InputEvent.BUTTON_DOWN_MASK): This method will press the right click of mouse. • mouseRelease(): eg. robot.mouseRelease(InputEvent.BUTTON_DOWN_MASK): This method will release the right click of mouse. • keyRelease(): eg. robot.keyRelease(KeyEvent.VK_DOWN): This method will release the down arrow key of keyboard.

  11. Advanced Selenium Interview Questions for SDET 10. How to Upload a file in Selenium WebDriver? We can upload a file in Selenium WebDriver using the AutoIT script. Follow the following steps for uploading a file with AutoIT script: • Download and Install the “AutoIT”. • Open Eclipse and write code through Selenium WebDriver for clicking on the “Upload File” button. • Ensure FileUpload.exe is generated after compilation in the location where AutoIT is installed. This FileUpload.exe already contains the file(say, devLabsAlliance.docx) to be uploaded and this is pre-configured through AutoIT editor. • After click of Upload button, AutoIT script needs to be called and then control immediately transferred to AutoIT in order to upload a file and then control is sent back to Selenium.Syntax for calling AutoIT script:Runtime.getRuntime().exec("D:\\AutoIT\\FileUpload.exe");

  12. Advanced Selenium Interview Questions for SDET 11. How to run Selenium test from Command Line in Selenium WebDriver? For doing this, we need to install TestNG, and need to set the class-path. Follow the below steps: • Create testng.xml file and store this xml file into project home directory. • Ensure that you put all the Selenium jars in separate folder and keep that folder into project home directory. • Open Command Prompt and type cd\ and then press Enter. • Now copy the path of your project home directory in this cd directory path and then press Enter. • Now set the classpath for this and specify the bin folder.Project Directory > set classpath=Project Directory\bin; and press enter • Now specify the folder(say, lib) where all the jars are available.Project Directory > set classpath=Project Directory\lib\*; and press enter • Now run xml file using below command:Project-directory > java org.testng.TestNG testng.xml and hit Enter.

  13. Advanced Selenium Interview Questions for SDET 12. How to connect a database in Selenium? To connect a database in Selenium, we use JDBC driver while using Java Programming language. Follow the below steps to connect database in Selenium: • Load the required JDBC driver class.Class.forName("net.sourceforge.jtds.jdbc.Driver"); • Establish a connection to the database:Connection con = DriverManager.getConnection("DataBaseURL", "userName", "password"); • Connection URL:jdbc:sqlserver://ipAddress:portNumber/dbName • Execute SQL Queries:Statement sqlStatement = con.createStatement();String sqlQuery = "SELECT * FROM table_name WHERE condition"ResultSet resSet = sqlStatement.executeQuery(sqlQuery); • Fetching data from resultSet:while (resSet.next()) { System.out.println(resSet.getString(required_column_name));} • Closing the database connection.con.close();

  14. Advanced Selenium Interview Questions for SDET 13. How to Scroll Web Page Down Or Up Using Selenium WebDriver? To scroll the page Up or Down, JavaScript scrollBy() method is used. Syntax for Scrolling WebPage down:WebDriver driver = new ChromeDriver(); driver.navigate().to("https://www.devlabsalliance.com"); JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("window.scrollBy(0, 250)", ""); Syntax for Scrolling WebPage Up:WebDriver driver = new ChromeDriver(); driver.navigate().to("https://www.devlabsalliance.com"); JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("window.scrollBy(0, -250)", "");

  15. Advanced Selenium Interview Questions for SDET 14. What is Desired Capabilities? Desired capabilities are used in to handle SSL certificates in Chrome browser. To achieve this, we need to create an instance of DesiredCapabilities: DesiredCapabilities desiredCapability = DesiredCapabilities.chrome();

  16. Advanced Selenium Interview Questions for SDET 15. How to Highlight Element Using Selenium WebDriver? We can highlight the specified element using JavaScriptExecuter interface. WebDriver driver = new ChromeDriver(); driver.get("https://www.devlabsalliance.com"); WebElement ele = driver.findElement(By.xpath("//*[@id='devLabs']")); JavascriptExecutor js = (JavascriptExecutor) driver; //Passing values based on css style. Yellow background color with solid red color border. js.executeScript("arguments[0].setAttribute('style', 'background: yellow; border: 3px solid red;');", ele)

  17. Advanced Selenium Interview Questions for SDET 16. How to launch a batch file in a Selenium webdriver? Before starting the automation, we need to set up the pre-requisites in a test suite to run a batch file or an executable file. Below code can be used for the same: Process batchFile = Runtime.getRuntime.exec(“Path of batch file”); batchFile.waitFor();

  18. Advanced Selenium Interview Questions for SDET 17. How Selenium Webdriver test can be run from the command line? Below code is used to write Selenium Webdriver test using command line: java -classpath “.;selenium-server-standalone-2.33.0.jar” ExampleClass

  19. Advanced Selenium Interview Questions for SDET 18. Which Selenium technology is useful for distributed data processing? Selenium Grid is popularly used for distributed data processing. Selenium Grid distributes tests on multiple machines in parallel. The tests can be executed in parallel on different operating systems and different web browsers at the same time with a single script using Selenium Grid. Distributed data processing in Selenium reduces overall time of execution and feedback is also quick in distributed data process.

  20. Advanced Selenium Interview Questions for SDET 19. Explain what the following snippet of Java code does in brief:WebElement example = driver.findElement(By.xpath(“//*[contains(text(), ‘data’)]”)); The above code is defining a variable ‘example’ of type WebElement and it is initializing it with a reference to an element that contains the text value “data” using XPath search.

  21. Advanced Selenium Interview Questions for SDET 20. What is StaleElementException? StaleElementException is an exception which is thrown when the element that is invoked is no longer attached to the DOM(Document Object Model) for any reason. For eg. If the element found in a web page is referenced as a WebElement in the Webdriver. Now if the DOM changes, then WebElement is no longer available, hence WebElement goes stale. Then if we try to interact with this stale element, then the StaleElementException is thrown.

  22. Visit us at: www.devlabsalliance.com Email: training@devlabsalliance.com Contact: +91 9717514555

More Related