Quick Reference - Selenium Interview Questions

* What is hard asserstion and soft assertion

* Handle alerts  -->  driver.switchTo().alert().accept();

* Select options

Select select = new Select(webElement); //select.getOptions();
select.selectByIndex(1);

* tesng.xml example
   <suite name="TestSuiteName" parallel="tests">
     <test name="TestName" preserve-order="true">
              <classes>
<class name="org.pacakge.name.TestClassName" />
     </classes>
     </test>
   </suite>

* how to disable web security in chrome
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-web-security");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);

* how to take screenshot
TakesScreenshoot screenshot = ((TakesScreenshot)driver)
File sourceFile = screenshot.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(sourceFile, "filename.jpg");

* Difference between navigate().to(URL) and driver.get(URL)

* Difference between implicitWait and explicitWait

* Wait for pageLoad
WebDriverWait wait = new WebDriverWait(driver, timeoutInSecs);
ExpectedCondition<Boolean> pageLoadCondition = new ExpectedCondition<Boolean>(){
public Boolean apply(WebDriver driver) {
return ((JavascriptExecutor)driver).executeScript(
"return document.readyState").equals("Complete");
}
};
wait.until(pageLoadCondition);


* KeyboardActions
Ex: Actions action = new Actions(driver);
action.keyDown(Keys.CONTROL).sendKeys(Keys.F5).perform();

* Difference between testNG and JUnit

* assertions and types

* Run TestNG using cucumber
use following classes
MultiLoader()
RuntimeOptionsFactory()
PluginFactory()
ResourceLoaderClassFinder()

* ErrorCollector in JUnit

* Javascript in selenium

Ex: String MAX_BROWSER_WIN = "if (window.screen){window.moveTo(0,0); window.resizeTo(window.screen.availWidth, window.screen.availHeight);};";
((JavascriptExecutor)driver).executeScript(MAX_BROWSER_WIN);

Ex: ((JavascriptExecutor)driver).executeScript("scroll(250, 0)");

* configuration of testng in maven
<pluings>
<plugin>
-----
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>

* configuration of reports in maven

* grouping from testng.xml

<suite>
<test name="testName">
<groups>
<define name="includeGroup">
<inlucde name="includeTestOne" />
<include name="includeTestTwo" />
</define>
<define name="exlcudeGroup">
<exclude name="excludeTestOne" />
<exclude name="excludeTestTwo" />
</define>
<run>
<include name="include-group" />
<exclude name="exclude-group" />
</run>
</groups>
</test>
</suite>

* customization of test execution reports
using XSLT reports using testng+ANT

* Design patterns in selenium
DomainDrivenDesign: Express your tests in the language of the end-user of the app.
PageObjects  : A simple abstraction of the UI of your web app.
LoadableComponent : Modeling PageObjects as components.
BotStyleTests  : Using a command-based approach to automating tests, rather than the object-based approach that PageObjects encourage
AcceptanceTests   : Use coarse-grained UI tests to help structure development work.
RegressionTests   : Collect the actions of multiple AcceptanceTests into one place for ease of maintenance.

No comments:

Post a Comment