Sunday, July 12, 2015

Frames

  • Frame:
  • Here we are trying to click the link, that is inside the frame.

    driver.switchTo().frame("<name of the frame>");
    driver.findElement(By.linkText(<"name of the text>")).click();

    driver.findElementt(By.tagName("frame")).size() --- gives number of frames available

    -

     

    Handling External files


    POM --- Page Object Model

    1/12/2016

    Collecting WebElements and Methods respective each page.

    Writing separate class for business Components(class A) and web elements (class B)

    Grid

    Refer to blog for more details: This website has complete command and screenshots associated with GRID.
    https://www.learn-automation.com



    - This is the last type of Selenium types. It supports the scripts written in older versions of Selenium.

    - Grid --- distributing the test cases into multiple systems. So make sure systesms are marked sub or hub accordingly. Here test cases can be executed acrosss multiple test cases in multiple browsers in parellel

    - Hub system - distributes the tc's across sub and collects the results.

    - Sub (node) system - executes the tc's assigned by Hub system

    - This helps in compatability testing

    - Using DesiredCapability object we can assign the browser settings we need to use.

    Node matches if all the requested capabilties are met, so to request specific capabilities on the grid specify them before passing the it into the WebDriver object as mentioned below:

    DesiredCapabilities capabilityobject = DesiredCapabilities.firefox();
    capabilityobject.setBrowserName("firefox");
    capabilityobject.setPlatform("LINUX");
    capabilityobject.version("3.6");

    WebDriver driver = new RemoteWebDriver(new URL(http://HubIP:4444/wd/hub), capability);



    Difference between Selenium Grid and QTP remote connection for CI?

    Based on the training- Jan 2016
     - QTP remote connection using Jenkins will need QTP installed on all the remote machines. Once remote machines are all set up, Jenkins will connect those machines and execute test cases instead of you doing it manually(clicking the run button).

    - Selenium Grid, looks like advanced concept compared with QTP remote connection. Here we need systems to be distributed as node and hub, and node does not need Eclipse installed on them just hub will need. Hub will connect respect node, make use of the nodes to execute the scripts in multiple machines (node) and browsers.


    Real code executed on my personal machine by registering hub and node on same machine:
    package seleniumGridconceptsProject;

    import java.net.MalformedURLException;
    import java.net.URL;

    import org.openqa.selenium.Platform;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;

    public class ExecutingGrid {

    public static void main(String args[]) throws MalformedURLException { //Not sure about this exception, added due to URL class

    DesiredCapabilities dc = DesiredCapabilities.chrome(); //path of chrome driver is given while registering node and hub

    URL url = new URL("http://192.168.0.12:4444/wd/hub");  // it can be hub url or node url. This will tell trigger class to trigger on which node. If you give hub url then hub will take care of which node to pick on its own.

    WebDriver driver = new RemoteWebDriver(url,dc);

    driver.get("http://learn-automation.com/");

    System.out.println("Printing through Grid");

    }
    }

    /* Prerequisites: Selnium webdriver jar and Selenium Standalone jar
              *Register hub:Open cmd
           * Navigate to selenum jar file folder
    * enter below command:
    * java -Dwebdriver.chrome.driver= "path of driver file" -jar seleniumjarname -hub
    *
    * Once registered as hub, 
              * Register Node:
              *Enter below command in another session of command prompt t
    * Navigate to selenium jar file folder
    * enter below command:
    * java -jar selenium jar name -role node -hub "hub url"
    *
    *
    */












    Implicit and Explicit waits

    - Implicit wait is common --- its applicable for driver object

    Once used we need not use repeatedly.
    - Explicit wait -- we cannot mention the time unit

    - Implicit wait checks, if element is present or not.

    Explicit also checks the status of the element(we can give the different conditions of the presence of the element not just preset...like is element enabled,

    - Compared with Thread.sleep(<millisecs>") .. we have few differences

    - syntax:

    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); --- it will wait for the web element as it checks the element for every seconds, if it available then move on(not waiting till the 10 seconds).

     -

     

    AutoIt


    JUnit


    Junit Notes:

    - Junit and TestNG are testing framework.
    - Junit is not meant for Selenium but for selenium we could use it
    - Junit is Jar file, inorder to use Junit we need to just download the jar file and give the build path in eclipse else right click import jar file when you get the error. Like Add Junit 4 library to the build path and execute by right clicking and then click Run As->Junit test
    - Annotations help you control the execution of script in Junit
    - When you are using Junit framework, one need not mention main method???
    - Annotations list:
    @Test   --- Test Case. If you mention @Test in the front of a class then it means that class would be execute as a test case(test case would be created in framework).
    @Before
    @After
    @Beforeclass
    @Afterclass
    @Ignore
    @RunWith(Suite.class)  --- helps to Run the classes in batch
    @SuiteClasses( ------- batch in classes
    {class1},
    {class2})
    @Rule


    - In @Test, if you mention word 'Test' in method name then @Test annotations script would be executed in an order
    - @After and @Before - are tagged to @Test. @After and @Before gets executed for everywhere @Test. To avoid this we have
    - Assume.assumeTrue(<True>) ---
    - Assertions
    Assert.assertEquals(Expected, Actual)
    - Drawback on Assertions(above statement) if Assertions fails then rest of the script will not be executed so we use try and catch.
    Like:
    try{
    Assert.assertEquals(var1,var2)
    }catch(Throwable t){
    system.out.println(




    - JUnit - Java Unit ---- as we use Java language. Different languages have different units.

    - Csharp -- we use Test

    - JUnit ---- has annotations, thats why we use units.

    Source: http://www.tutorialspoint.com/junit/junit_overview.htm



    Features

    • JUnit is an open source framework which is used for writing & running tests.
    • Provides Annotation to identify the test methods.
    • Provides Assertions for testing expected results.
    • Provides Test runners for running tests.
    • JUnit tests allow you to write code faster which increasing quality
    • JUnit is elegantly simple. It is less complex & takes less time.
    • JUnit tests can be run automatically and they check their own results and provide immediate feedback. There's no need to manually comb through a report of test results.
    • JUnit tests can be organized into test suites containing test cases and even other test suites.
    • Junit shows test progress in a bar that is green if test is going fine and it turns red when a test fails.


    It will just follow annoations instaed of going throug main method, ordering of executing the code could be changed using annoations(JUnit).







    Annotation most freq used for testing are:
    @Before  -- method that is marked @Before will be executed before executing every test in the class.
    @After
    @Test
    @BeforeClass
    @AfterClass

    - To create JUnit test case:
    Go Eclipse IDE-> right click on your package -> JUnit test case

    Provide class name(JUnitTest), you will have checkboxes for selecting annotations-- select setup() and teardown()

    Once you are done with the test case, here is how you better mention before and after as below:

    public class JUnitTest {
    @Before
    public void setUp() {
    System.out.Println("first");
       }

    @After
    public void tearDown() {
    System.out.Println("third");
      }

    @Test
    public void test1() {

    System.out.Println("second1");
    }
    }
    @Test
    public void test2() {

    System.out.Println("second2");
      }
    }

    output:
    first
    second1
    third
    first
    second2
    third

    - See JUnit will help you to create see test case in the results.

    Assertion - is to indicate whether the particular statement returning true or false.
    - assertEquals("<actualvalue>", "<expected>"); --- compares actuals with expected, and produce true or false in the results.  ---- you need not seperately write code to validate

    assertEquals("Google",driver.getTitle());

    - assertTrue()
    sub methods used with assertTrue() are
    isEnabled()
    isDisabled()
    isSelected()

    -   What are the packages that needs to be included???

    -