Complete File
Complete File
List<WebElement> e = f.findElements(By.xpath("//input[@name='email_to[]']"));
System.out.println(Integer.toString(e.size()));
for(WebElement ela : e )
{
ela.click();
ela.click();
Zoom browser :
{
WebDriver d;
d=new FirefoxDriver();
d.manage().window().maximize();
d.get("https://accounts.google.com");
d.findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL,Keys.ADD));
}
Proxy setting :
Write Excel :
@Data Provider :
@Test(dataProvider = "dp",priority=1)
public void f(String n, String s)
Syntax :
@DataProvider
public Object[][] dp() {
return new Object[][] {
new Object[] { "arun", "1234" },
new Object[] { "test", "4321" },
new Object[] {"user","asasas"},
};
@Parameters :
@Parameters({"user","pass"})
@Test
public void f(String user,String pass)
XML :
Cross Browser :
@Parameters("browser")
@BeforeTest
public void beforeTest(String browser) throws Exception
{
if(browser.equalsIgnoreCase("firefox"))
{
g=new FirefoxDriver();
}
XML :
Screen Shots :
File h=((TakesScreenshot)g).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(h, new File("d:\\driver1\\base.png"));
Groups :
@Test(groups={"Smoke"})
@Test(groups={"Regression"})
@Test(groups={"Regression","Smoke"})
@Listners :
@Listeners(checking.anno.class)
ITestResult :
@AfterMethod
Public void main(ItestResult result)
{
If(ItestResult.FAILURE==result.getStatus());
{
Utility.CaptureScreeshot(driver.result,getname());
}
Driver.quit();
}
Robot API :
Alert :
String at=z.switchTo().alert().getText();
System.out.println(at);
if(at.equals("First name Should not contain Special Characters"))
{
System.out.println("pass");
z.switchTo().alert().dismiss();
}
DB Testing :
Dependens test :
@Test(dependsOnMethods={"testLogin"})
Implicit Wait :
driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);
Explicit wait :
Syntax :
WebDriverWait wait = new WebDriverWait(t,30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("")));
Example :
ElementNotVisibleException
alertIsPresent()
elementSelectionStateToBe()
elementToBeClickable()
elementToBeSelected()
frameToBeAvaliableAndSwitchToIt()
invisibilityOfTheElementLocated()
invisibilityOfElementWithText()
presenceOfAllElementsLocatedBy()
Assert :
Xpath :
1. Single attribute :
//tagname[@attribute-name='value1']
Example : //input[@name='log']
2. Double attribute :
//input[@class='input'][@name='log']
3. And & OR
//input[@class='input' OR @name='log']
//a[contains(@href,'edit.php')][text()='Posts']
//*[text()='Discussion']//following::a[contains(@href,'edit.php')][text()='Posts']
//*[contains(@id,'edit)']
//*[starts-with(@id,'edit')]
6. Search by text :
7. Search by following :
.//*[@id='content-label']/label//following::textarea
.//*[@id='content-label']/label//following::input[2]
8. Search by precedings:
.//*[@id='content-label']/label/preceding::input[2]
Selenium Task :
Web Tables :
1. table
2. Th-table heaading
3. Td-Table data
4. Tr-Table row
Answer 1 : To get the all datas from table using xpath(catch the table wii display all the contents) :
Multiple windows :
driver.switchTo().window(mainWindowHandle);
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"\t");
driver.switchTo().defaultContent();
File Handling :
1.InputStream - superclass of all classes representing an input stream (read data from a source).
3.FileInputStream -
4.FileOutputStream -
5.SequenceInputStream - Java SequenceInputStream class is used to read data from multiple streams.
It reads data sequentially (one by one).
8.FileWriter -Java FileWriter class is used to write character-oriented data to a file. It is character-oriented
class which is used for file handling in java.
you don't need to convert string into byte array because it provides method to write string
directly.
9.FileReader - Java FileReader class is used to read data from the file. It returns data in byte format like
10.BufferedWriter -Java BufferedWriter class is used to provide buffering for Writer instances. It makes the
performance fast. It inherits Writer class.
11.BufferedReader -Java BufferedReader class is used to read the text from a character-based input stream.
It can be used to read data line by line by readLine() method. It makes the performance
fast. It inherits Reader class
1. Code to write and read text in file:
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public static void main(String args[]) throws Exception
{
BufferedWriter out1 = new BufferedWriter(new FileWriter("E:\\File Handling\\practise 1\\dinesh.txt"));
out1.write("string to be copied\n");
out1.close();
BufferedReader in1 = new BufferedReader(new FileReader("E:\\File Handling\\practise 1\\dinesh.txt"));
String str;
while ((str = in1.readLine()) != null) {
System.out.println(str);
}
in1.close();
}}
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.OutputStream;
len = read.readLine();
write.write(len+"\n");
}
write.close();
read.close();
}
}
*BDD
Tradition approach
Focus on what to test not how to test.
Problem : If system requiremets needs more then we cannot continue because Business req is fixed based upon we need
to create.
BDD is controls this by providing some new techniques that -->What to test.
Gherkins-->separte lang will provide keywords like some meaningfull example -->Given,When ,Then, And etc
Project :
Feature
Given : preconditions
Maven :
maven 3.3.1
Conti.itergration :
*trigger
*Build Steps
*Post Build Steps
Practise :
Task 1 : Cut the given strings and save in different file -->part wise storing.
Selenium :
-->NoSuchElementException
This exception occurs when WebDriver is unable to identify the elements during run time.
Due to wrong selector or selector, which is, not exist.
-->ElementNotVisibleException
This Exception occurs when the element presence is in DOM, it is not visible.
Example:-
Hidden Elements, which has presence in DOM and it, is not visible. Visibility means the height and
width should be greater than zero. Hidden Elements are defined in HTML using of type=”hidden”.
-->NoSuchFrameException
This Exception occurs when the driver is switching to an invalid frame, which is not available.
-->NoAlertPresentException
This Exception occurs when the driver is switching to an invalid Alert, which is not available.
-->NoSuchWindowException
This Exception occurs when the driver is switching to an invalid Window, which is not available.
-->WebDriverException
This Exception occurs when the driver is performing the action after immediately closing the browser.
-->SessionNotFoundException
This Exception occurs when the driver is performing the action after immediately quitting the browser.
-->StaleElementReferenceException
This Exception occurs when the Element belongs to a different frame than the current one. The user has
navigated away to another page.
-->IOException
Waits :