Thursday, November 26, 2015

Handle window authentication?

It is very easy to handle web component fields. But some time we have to facing some problem to access website because to window authentication.
Before Work on window authentication it is valuable to know about application dependency on browsers  because window authentication is different from browser to browser. Please see the screen shot of different authentication pop up on different browsers.

IE ( Internet Explorer) browser.






Firefox browser:-

Chrome browser:-
------------------------------------------------------------------------------------------
1) To handle window authentication , add a testng class in eclipse and write the code inside.
package LoginScreen;
---------------------------------
import java.io.IOException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.*;

public class GrowthLogin {
WebDriver driver;

@BeforeTest
public void initialization()
{
  driver = new FirefoxDriver();
  driver.manage().window().maximize();
}

@Test
public void UserLogin() throws InterruptedException, IOException
{

Runtime.getRuntime().exec("D:\\Auto\\HandleAuthentication.exe");
driver.get("http://10.4.8.241:1051");
       //Thread.sleep(1000);
}

@AfterTest
public void Enddriver()
{
driver.quit();
}
}//End of class

2) Create an auto script , its name should be "HandleAuthentication" that i have used above.
Write down the below code and save it in a path as mentioned above program.
WinWaitActive("Authentication Required")
Send("Valid username")
send("{TAB}")
Send("valid password")
Send("{Enter}")

3) Now run the program ..... Enjoy baapuuuuuuuu tera program chal gaya ( now its login)................



Thursday, November 19, 2015

Test NG:- Annotation_ priority

Similar as Junit, TestNG has annotations. Now below is the example , in which i am using two annotation one is @test and other one is @configuration(beforeTestclass) . you should keep in your mind, as the name implies of the annotation , its corresponding functions executation are also depend on its annotation.
in the below example i am writing @test annotation method first and @beforetestclass annotation after that. After execution what should be its result :-
Example
-----------------------------------------------------------------------
import org.testng.annotations.Test;

public class Readdata_From_Excelfile {
@Test(groups = { "functest" })
public void serverIsRunning() {
System.out.println("serverisrunning");
}

@Configuration(beforeTestClass = true)
public void init()
{
System.out.println("init function");
}


}

Result is :-
init function
Serverisrunning