Automation Using Selenium Webdriver

Monday, 10 October 2016

How to create dependency between testcases in Selenium




I am sure you must be confused with Title like How to create a dependency between test cases in Selenium but in this post we will see this through example.

In real time, you will come across many situation where you have to create test cases which are dependent on the previous test case.

Take an example I have 3 test case.

First one which verify login credential and start application
Second test case check some validation  or do some activity
Third test case simply just for log-out activity.

If my first test case does not work (failed) that it does not make any sense to run second and third test case so in these type of scenarios you can use dependency between test case.

How can I do this?

TestNG already comes with this features so you can use the same with @Test annotations


Syntax- @Test(dependsOnMethods={"loginTestCase"})

public void testAccount()
{

// sample code

}
Syntax- @Test(dependsOnMethods={"loginTestCase"})

public void testAccount()
{

// sample code

}
How to create dependency between test cases in Selenium



It means this test case name testAccount depends on test case whose name is loginTestCase so until loginTestCase will not execute successfully this test case won’t execute so if loginTestCase will pass this test case will execute and if loginTestCase will fail then this test case won’t execute and runner will skip this test cases and this test case will come under skip test cases.

Let’s implement the same


package Demo;

import org.testng.Assert;
import org.testng.annotations.Test;

public class TestMultiple {

@Test
public void testLogin()
{

System.out.println("login done");

}

@Test(dependsOnMethods={"testLogin"})
public void testAccount()
{
System.out.println("Account has been created");

}

@Test(dependsOnMethods={"testLogin","testAccount"})
public void testLogout()
{
System.out.println("logout");

}

}


package Demo;

import org.testng.Assert;
import org.testng.annotations.Test;

public class TestMultiple {

@Test
public void testLogin()
{

System.out.println("login done");

}

@Test(dependsOnMethods={"testLogin"})
public void testAccount()
{
System.out.println("Account has been created");

}

@Test(dependsOnMethods={"testLogin","testAccount"})
public void testLogout()
{
System.out.println("logout");

}

}


In the above scenario if testLogin will pass then only testAccount will execute and testLogout will only execute of testLogin and testAccount will  be executed

but if testLogin will fail due to some error or exception the testAccount will not be executed and this test case will skip and testLogout is dependent on testLogin and testAccount so now this will also come into skipped category

Let’s implement again


import org.testng.Assert;
import org.testng.annotations.Test;

public class TestApplication {

@Test
public void testLogin()

{
Assert.assertEquals("Selenium", "Selnium");
System.out.println("login done");

}

@Test(dependsOnMethods={"testLogin"})
public void testAccount()

{
System.out.println("Account has been created");

}

@Test(dependsOnMethods={"testLogin","testAccount"})

public void testLogout()

{
System.out.println("logout");
}
}

import org.testng.Assert;
import org.testng.annotations.Test;

public class TestApplication {

@Test
public void testLogin()

{
Assert.assertEquals("Selenium", "Selnium");
System.out.println("login done");

}

@Test(dependsOnMethods={"testLogin"})
public void testAccount()

{
System.out.println("Account has been created");

}

@Test(dependsOnMethods={"testLogin","testAccount"})

public void testLogout()

{
System.out.println("logout");

}
}


Output

FAILED: testLogin
java.lang.AssertionError: expected [Selnium] but found [Selenium]
at org.testng.Assert.fail(Assert.java:94)
SKIPPED: testAccount
SKIPPED: testLogout

===============================================
Default test
Tests run: 3, Failures: 1, Skips: 2
===============================================

===============================================
Default suite
Total tests run: 3, Failures: 1, Skips: 2
===============================================

OUTPUT in HTML

Saturday, 8 October 2016

Advanced-Selenium-Autoamtion-Real-Time-Support PPT

EMIDS Technologies Last Week Asked 2 Years Selenium Testing Position

EMIDS  INTERVIEW QSNFOR 2 YEARS SELENIUM TESTING POSITION.

      Prepare  Code Also Some Scenarios Asked 

1ST round-TECHNICAL
·         Introduce yourself  tell something about your last project.
·         Which framework  you have used and why?
·         Why automation ?
·         Write the format of XML file for BATCH EXICUTION?
·         How synchronisation resolved in automation?
·         How many wait statements you know ?
·         What  is polymorphisim?
·         Have u used constructor in WebDriver?

2nd round – TECHNICAL

·         Tell me about your project and responsibilities?
·         Which module u worked on ur project ?
·         Tell me the flow of your framework?
·         Write a  java code to read the data through excel file?
·         I have some reusable methods and i have some new feture,so i want to acess the reusable methods to my current application,how can i do that?
·         Is it possible to write the xpath using IE browser?
·         What exactly your file structure looks like when you are automating something by using of eclipse ?
·         How did you verify that given number on webpage in sorted order ?
·         How can i do priority based testing using webDriver ?
·         Write a login  code using page factory ?
·         Is that necessary to creat Generic Lib. For  every project?
·         Write a code for screen shot ?
·         Have u ever faced like You don’t have requirement document  and  You have to test,how wil you do that?
·         Why we r using some tool for reporting?
·         What is TestNg ?tell me the annotations of TestNG? (if you are using TestNG)
·         Can you write a sample  for parallel execution  in TestNG.xml file?
·         How are you maintaining the objects in your project?
·         What is constructor ? what is super ()?
·         What is Encapsulation?
·         What is the difference between interface and abstract class?
·         What is poly morphism?
·         Actually  X-path writing a confusion task for me, is there any way to find webElement in UI?
·         How wil you capture the dynamic object using selenium webDrive?
·         Tell me the syntax for Implicity wait() and Explicity wait()

3RD round-maneger
Gv ur intro with your roles and responsibilities?
How many bug you hv found on your project?
Can you please explain flow of your project?