Saturday, 20 October 2018

Selennium With BrowserStack

Compatibility Testing Using BrowserStack & Selenium – TestNG


Image result for multiple platform testing

Compatibility Testing is a type of Software testing to check whether your software is capable of running on different hardware, operating systems, applications , network environments or Mobile devices.
Compatibility Testing is a type of the Non-functional testing
BrowserStack allow us to make automation testing on different platforms at once place.
You need to set few parameters browsers and platforms. There are few steps to be followed to integrate Selenium with BrowserStack.
Step1: Sign Up for BrowserStack account
Step2: Get your username and access key.
Step3: Create your test script using TestNG
Step4: Create your testng.xml file to run your test in parallel
Step5: Execute testng.xml
Step6: To view your result, login and click on automate link, so that you can view your project result.
Here is sample code that I am providing written using TestNG.

public class BSTC {
private WebDriver driver;
public static final String USERNAME = “<usename>”;
public static final String AUTOMATE_KEY = “<accesskey>”;
public static final String URL = “http://browserstack.com; + USERNAME + “:” + AUTOMATE_KEY
+ “@hub.browserstack.com/wd/hub”;
@BeforeTest
@Parameters(value = { “browser”, “version”, “platform” })
public void setUp(String browser, String version, String platform) throws exception{
DesiredCapabilities capability = new DesiredCapabilities();
capability.setCapability(“platform”, platform);
capability.setCapability(“browserName”, browser);
capability.setCapability(“browserVersion”, version)
capability.setCapability(“project”, “TestProject”);
capability.setCapability(“build”, “3.03”);
driver = new RemoteWebDriver(new URL(URL), capability);
}
@Test(priority = 1)
public void TC01() throws Exception {
driver.get(“http://www.google.com;);
Assert.assertEquals(“Google”, driver.getTitle());
WebElement element = driver.findElement(By.name(“q”));
element.sendKeys(“BrowserStack”);
element.sendKeys(Keys.ENTER);
}
@Test(priority = 2)
public void TC02() {
driver.get(“http://seleniumhq.org;);
Assert.assertEquals(“Selenium – Web Browser Automation”,
driver.getTitle());
}
@AfterMethod
public void takeScreenShot(ITestResult result)
{
if (result.getStatus() == ITestResult.FAILURE)
      {
           driver = new Augmenter().augment(driver);
           File srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
try {
           FileUtils.copyFile(srcFile, new File(“D:\\Screenshot”+ result.getParameters().toString() + “.png”));
} catch (IOException e)
{
          e.printStackTrace();
}
}
}
@AfterTest
public void tearDown() throws Exception {
driver.quit();
}
}
Now setup your configuration in xml file. Copy the below code.
<suite thread-count=”3″ name=”Suite” parallel=”tests”>
<test name=”FirstTest”>
          <parameter name=”browser” value=”firefox” />
          <parameter name=”version” value=”42″ />
          <parameter name=”platform” value=”Windows” />
          <classes>
                    <class name=”package1.BSTC” />
          </classes>
</test>
<test name=”SecondTest”>
          <parameter name=”browser” value=”safari” />
          <parameter name=”version” value=”7.0″ />
          <parameter name=”platform” value=”MAC” />
          <classes>
                     <class name=”package1.BSTC” />
          </classes>
</test>
<test name=”ThirdTest”>
          <parameter name=”browser” value=”Internet Explorer” />
          <parameter name=”version” value=”10″ />
          <parameter name=”platform” value=”Windows” />
          <classes>
                     <class name=”package1.BSTC” />
          </classes>
</test>
</suite>

This is how, we can execute same test case in multiple environment. Just login and click on 'Automate' link and you will see your result.
All The Best... 

Friday, 19 October 2018

How to handle SSL Certificate Error using Selenium Webdriver\

Image result for ssl certificate



\

Suppose we have written test scripts and while running those script, if you encounter situation like "Untrusted Connection" then how do we handle such exception in Selenium automation.

In such cases we have to adjust our script in such way that, it will take care of SSL exception by itself.

Some desired capabilities being used to configure webdriver instance. Through this capabililties one can configure all driver instances like ChromeDriver, FireFoxDriver and Internet Explorer.

SSL Certificate Error Handling in Chrome
To handle such case in Chrome, one needs to use desired capabilities of Selenium webdriver. Below snippet will help to accept all SSL certificate in Chrome. 
DesiredCapabilities handlSSLErr = DesiredCapabilities.chrome ()       
handlSSLErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true) 
WebDriver driver = new ChromeDriver (handlSSLErr); 

SSL Certificate Error Handling in Firefox

To handle such case in Chrome, one needs to use desired capabilities of Selenium webdriver. Below snippet will help to accept all SSL certificate in Chrome. 

1) Pre-requisite is, one needs to create new firefox profile say "myProfile" 
2) Now access myProfile in the script as below and create it's object.

ProfilesIni prof = new ProfilesIni()    
FirefoxProfile ffProfile= prof.getProfile ("myProfile")
3) Now we need to configure "SetAcceptUntrustedCertificates" and "setAssumeUntrustedCertificateIssuer" properties in the FireFox  profile

ffProfile.setAcceptUntrustedCertificates(true) 
ffProfile.setAssumeUntrustedCertificateIssuer(false)
4) Now use FireFox profile in FireFox driver instance.

WebDriver driver = new FirefoxDriver (ffProfile)   
Note: "setAcceptUntrustedCertificates" and "setAssumeUntrustedCertificateIssuer" are capabilities to handle the certificate errors in web browsers.


---------------------------

Saturday, 15 September 2018

How to install Jenkins on CentOS/RHEL

How to install Jenkins on CentOS/RHEL


Jenkins gives consistent integration services to programming improvement. It is server based framework running in servlet holder, for e,g, Apache Tomcat. It support SCM devices including CVS, Git, SVN, RTC, Perforce etc...and can execute Apache Ant and Apache Maven based task. 


Jenkins is opensource and most famous persistent joining device written in Java. There are numerous plugins accessible to make it more simpler. You can design built with different means like, activated by a submit in variant control framework scheduling by cron-jobs etc..

Step 1: Check Java Version
First, we have to check that Java has been installed on the server or not. Jenkins require Java 1.6 or more than. If Java version is less than 1.6 than we have to upgrade the Java. Use following command to check Java Version.
# java -version
openjdk version "1.8.0_45"
OpenJDK Runtime Environment (build 1.8.0_45-b13)
OpenJDK 64-Bit Server VM (build 25.45-b02, mixed mode)
Step 2: Jenkins Repository
After checking the version of Java we need to add Jenkins repositories on the server.
# wget -O /etc/yum.repos.d/jenkins.repo   http://jenkins-ci.org/redhat/jenkins.repo
# rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key

Step 3: Install Jenkins
Use following command to install Jenkins.
# yum install jenkins
Step 4: Start Jenkins
Start Jenkins Service uses following command.
# /etc/init.d/jenkins start | stop | restart
# chkconfig jenkins on
Step 5: Verify Jenkins
By default Jenkins use 8080 port. We use following command to check Jenkins is running or not.
 
# netstat -ntulp | grep 8080
Step 8: Change Jenkins HTTP port number
By default, Jenkins runs on port 8080. If you want to change the default port for Jenkins you need to change the file /etc/sysconfig/jenkins
# vim /etc/sysconfig/jenkins
Default:
JENKINS_PORT="8080"
New:
JENKINS_PORT="8443"
Step 9: Access Jenkins
Go to your browser and type http://localhost:8080/. Presently you ought to ready to see the Jenkins dashboard like below image:

I hope this tutorial will help you to install Jenkins on CentOS.

Thank You...!

Select Language