Today's Topic: I am picking some random topic related to java which may help in creating framework or basic understanding for a automation tester.
Constructor: Is a function having below mentioned features:
Default Constructor: If i want to do testing only in single browser. Then code can be like this-
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
class defaultConstructorTest {
public defaultConstructorTest()
{
WebDriver driver ;
System.setProperty("webdriver.chrome.driver",".\\chromedriver.exe");
// Puts an Implicit wait, Will wait for 10 seconds before throwing
// exception
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.blogger.com");
}
}
public class constructorTest
{
public static void main(String arg[])
{
defaultConstructorTest pct=new defaultConstructorTest();
}
}
Parameterized Constructor:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
class parameterizedConstructorTest {
public parameterizedConstructorTest(String browser)
{
WebDriver driver ;
if(browser.equalsIgnoreCase("chrome"))
{
System.setProperty("webdriver.chrome.driver",".\\chromedriver.exe");
// Puts an Implicit wait, Will wait for 10 seconds before throwing
// exception
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.blogger.com");
}
}
}
public class constructorTest
{
public static void main(String arg[])
{
parameterizedConstructorTest pct=new parameterizedConstructorTest("chrome");
}
}
Constructor: Is a function having below mentioned features:
- Same name as class
- No return type
- Used to initialize the object
- Default constructor
- Parameterized constructor
Default Constructor: If i want to do testing only in single browser. Then code can be like this-
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
class defaultConstructorTest {
public defaultConstructorTest()
{
WebDriver driver ;
System.setProperty("webdriver.chrome.driver",".\\chromedriver.exe");
// Puts an Implicit wait, Will wait for 10 seconds before throwing
// exception
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.blogger.com");
}
}
public class constructorTest
{
public static void main(String arg[])
{
defaultConstructorTest pct=new defaultConstructorTest();
}
}
Parameterized Constructor:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
class parameterizedConstructorTest {
public parameterizedConstructorTest(String browser)
{
WebDriver driver ;
if(browser.equalsIgnoreCase("chrome"))
{
System.setProperty("webdriver.chrome.driver",".\\chromedriver.exe");
// Puts an Implicit wait, Will wait for 10 seconds before throwing
// exception
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.blogger.com");
}
}
}
public class constructorTest
{
public static void main(String arg[])
{
parameterizedConstructorTest pct=new parameterizedConstructorTest("chrome");
}
}
No comments:
Post a Comment