Category Archives: Selenium

Cloud Testing with SauceLabs:

We can set up Selenium Server on our local computer or we can use cloud grid system providers such asSauceLabs, Browserstack or TestingBot, etc. This kind of companies provides extensive grid on their servers. You can find all OS and all browser versions. In this post will see how to test with those services.

What is Sauce Labs?
SauceLabs is a grid in the cloud. We can run our tests on their cloud with different browsers and operating systems. You can also do manual testing. In order to do these, first, we should go saucelabs.com and register for free.

In the saucelabs dashboard: Automated Builds, Automated Tests, Manual Tests.

Let’s start how to Run a Selenium Tests with SauceLabs:

SauceLabs is great because they allow you to focus on testing instead of worrying about maintaining a bunch of environments against which your tests need to run. To get a small taste of this sauceomeness, let’s take a look at what it takes to get a Selenium script running in the SauceLabs Cloud.

Getting started:
1. First, we should go saucelabs.com and register for free.

Eclipse:
1. Create a Maven project and add selenium-related things (version, TestNG) in the pom.xml

In the above SampleSauceTest, We are providing “USER_NAME” and “ACCESS_KEY” to connect saucelabs.

How to get Access Key?

Sauce Labs accounts are protected by a username, a password, and an access key. We use our username and password to access Sauce Labs’ site, and we use our username and access key to allow our tests to access SuaceLabs’s Selenium servers

1. Go to User Settings
2. ACCESS_KEY – Copy and Paste it into the class.

We configure Remote WebDriver with DesiredCapabilities (it configures browser type, version, platform, etc.) and external server URL. Then, we can run our tests on the server which we configured for RemoteWebDriver.

NOTE: Run Script and Verify on Saucelabs

Overview of Sauce Labs Features:
1. Web Functional testing
2. Cross Browser testing
3. Mobile Web testing
4. Manual Testing
5. Automated Testing Platform
6. Real device coverage

Benefits of SauceLabs:
1. Running tests 24/7
2. Fewer human resources
3. Simultaneity
4. Record
5. Screenshots

Thanks for reading this article!

How to send a mail through SMTP server using Java programming, it’s bulk process to send test cases(Screenshots, Description. text ) to many emails by manually so using JavaMail API it can be possible to send many users at a time.

This article will show you how to send a mail through SMTP server using java programming and follow below steps.

1. Create Maven Project
2. For sending the email using JavaMail API, you need to load the two jar files:

  • mail.jar
  • activation.jar

Download zip file

3. Project structure

MonitoringMail.java

TestConfig.java

TestMail.java

IMP: Before running the script we need to enable one option, follow below steps.

Note: This is only for FROM Mail address. Where we can send emails FROM and TO addresses.

Click on My account > Sign-in & security
Scroll down the page and then we should enable this ” Allow less secure apps: ON ” option otherwise, we will get exceptions.

One more point is will see this option only for new emails, not for old emails. it means email should be created recently.

Note: All set for running the code, right click on ” TestMail.java ” and run as JavaApplication.

You have successfully sent the mail.

Thanks for reading this article!

this is the continuation of the previous blog
Title : Selenium Webdriver With Firefox Profiles

Description :
when we don’t find any attribute of html tags while inspecting the elements for automation testing,
 we find xpath of that element.
procedure :
1. Working with firefox Browser.
 
To add firepath extension, follow the below screenshots.
To open the firefox(profile) browser, click on the firefox browser viagra mg it will show the below screenshot and then select the
profile and click on Start Firefox.

p1
p2

p3

click on the install tab.

p4

Now restart the browser.

p5

Task :
now let us inspect the elements for gmail -login page with firefox(profile) browser.
open the browser,
p1

Now let us open the gmail login page and click the ant icon which is the firpath extension, as shown in the below screenshot.

ant1

now you will get the below screenshot to inspect the elements.

1. first click on the icon (orange color highlighted).
2. click on the firepath (red color ).
3.click on the “Enter your email” text (yellow color), now u will get the xpath of that element.
4. copy the xpath and paste it in the selenium script( it will be covered in the below code snippet later).

ant2

same procedure also for “next “ button, you can check it in below screenshots.

ant3

Note :
[enter the gmail to go the next page.]

same procedure also for “Password” text box and Sign in button you can check it in below screenshots.

ant4

ant5

Now create a maven project in eclipse which also include firefox profile, to do so follow the below two blogs
Environment Setup For Selenium2.0 WebDriver  –  to create maven project.
Selenium Webdriver With Firefox Profiles           – to know about firefox profile.

Now add the below code in the App.java file, having all xpaths which we have taken from the above screenshots for gmail login, now execute it .

 

Now you will get the output as, it will open the gmail Inbox page.

Note :
we are not sure that every time the same xpath will work for the particular elements.
If developer changes the position of the element, the xpath will also changes.

2. Working with chrome Browser.
     No need of adding any extension for chrome browser, by default it had the feature to get the xpath.
Follow the below screenshot for the chrome browser.
For example let us take a gmail page.
Right click on next button, click on Inspect.

chrome11

Now right click on the (blue color highlighted content) in the html tags.
click on copy
click on xpath from the below screenshots.

chrome12

remaining procedure is as same as how we followed with the firefox browser.

you have successfully executed the Selenium script with firefox profile Browser and chrome Browser by finding xpath .

Selenium :
Selenium is a software testing framework for web Applications.

Softwares Required :
1. Install jdk1.7 in the System.
2. Install mozilla firefox Browser – version -40.0 (recommended)
After installing the firefox browser, change the default setting of automatic update.
Otherwise, later you may face the issue that browser not supported  while executing the
Selenium scripts.
To change the default automatic update for firefox browser, follow the below screenshots.
click on the red(higllighted) visible on screenshots, it might be content or icons.
f1

f2

f3

f4

To check the firefox version, follow the belowscreenshots.
click on the red(higllighted) visible on screenshots, it might be content or icons.

s21

s22

s23
2. Install eclipse-kepler IDE, from the below link.

3. No need of downloading the selenium jar file, just add the dependency in the pom.xml.
open the eclipse, create a maven project. To do so follow the below screenshots.
click on the red(higllighted) visible on screenshots, it might be content or icons.

s11

s12

s13

s14

s15

s16

s17

now add the dependency as shown in below screenshot.

s18

s19

Program : 
Now let us write a program to open gmail page ( http://www.gmail.com ) with firefox browser.
now copy paste the below selenium code in the App.java file and execute it.

You will get the below screenshot as the output.

fi

By default selenium supports firefox browser, but if You want to work with Chrome browser
download the .exe file from the below link.

d1

d2

d3

select any link from below (for example I shown one link, but  you can select any link and verify) and check the notes.txt file, for chrome browser support,  that which version you have  already installed in your System.
d4

d5

d6

To Download the .exe file for chrome ( it is  platform dependent ), So for both windows 32/ 64 bit, click on ChromeDriver_win32.zip. 
d7

After downloading the .exe file, open the eclipse and follow the same procedure as above (which we followed with firefox browser).

Program : 
Now let us write a program to open gmail page ( http://www.gmail.com ) with chrome browser.
now copy paste the below selenium code in the App.java file and execute it.

And also don’t forget to add the .exe file location of your system in the below code.

You will get the below screenshot as the output.

d8

Below is the link of Selenium API, you can explore more with it.

 

you have successfully executed the Selenium script with both firefox and chrome Browsers.

In the Previous Blog we Created a Maven Project.. then the Question comes what is Next??

For Reference of Maven Project Creation link : http://blog.nbostech.com/2016/08/about-maven-its-usage-and-setup-in-automation/

In this blog, I am going to discuss about the following :

  • Making Project TestNG Enabled.
  • Project Structure
  • Sample Selenium Test with TestNG annotations
  • Basic Structure of testng.xml
  • Creating profile for testng.xml in pom.xml
  • Executing Selenium test using maven
  • Viewing the Test Reports whether it failed or passed

TestNG is a testing framework for the Java programming language. It is designed to simplify a broad range of testing needs..

Few Advantages :

  • Advance and easy annotations
  • Execution patterns can be set
  • Concurrent execution of test scripts
    • Write the business logic of your test and insert TestNG annotations in your code.
    • Add the information about your test (e.g. the class name, the groups you wish to run, etc…) in a testng.xml file or in build.xml.
    •   testng.xml covers..
      • It can contain one or more tests and is defined by the <suite> tag.
      • A test is represented by <test> and can contain one or more TestNG classes.
      • A TestNG class is a Java class that contains at least one TestNG annotation. It is represented by the <class> tag and can contain one or more test methods.
      • A test method is a Java method annotated by @Test in your source.

      Frequently used annontations

      • @Test :
      • @beforeTest :
      • @AfterTest:
      • @beforeClass

To Start our Maven project with Selenium test and using TestNG.. The below are the steps to follow..

1. TestNG Enable

Make the project TestNG enabled.. we should add TestNG jar dependency details in pom.xml as below.

p2

Create testng.xml ..

   2. Project Structure

p3

    3. Sample Selenium test code along with TestNG

      AppTest.java


package com.wavelabs.webdriver;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class AppTest {
 
 public WebDriver driver;

 @BeforeTest
 public void beforeTest(){
 driver = new FirefoxDriver();
 }
 
 @Test(description = "facebook open page")
 public void url() {
 
 driver.get("https://facebook.com");

 }

 @Test(description = "login page", dependsOnMethods = "url")
 public void login() {

 driver.findElement(By.id("username")).sendKeys("**********");
 driver.findElement(By.id("password")).sendKeys("********");
 }
}

The annotations used in the above class are the basic annotations.. there are more like , we can use based on our requirement
@Test : It runs the method.. we have two methods with @Test annotation.. they run based on the parameters passed in the @Test annotation..
The parameter we are using is dependsOnMethods .. it means the method runs only after the url method is passed..

There are other parameters too.. eg : priority=1 , 2 .. etc..

@BeforeTest : This method gets executed before running of the methods who has @Test annotations.. we mostly use the method to initialize the objects of the classes.

   4. Basic Structure of testng.xml

  • test Tag :  the test. there can be multiple test tags in testng.xml
  • classes Tag: The parent tag for child tags (class tag)
  • class Tag : The class which the test tag wants to run.The structure of testng.xml looks like :
    <?xml version="1.0" encoding="UTF-8"?>
    
    <suite name=" WebDriver Suite">
    
     <test name="Testing">
     <classes>
     <class name="com.wavelabs.SeleniumTest.AppTest" />
     </classes>
     </test>
    
    </suite>
    

 

To run the test using Maven, we should create profile for testng.xml in pom.xml..

  5. Creating profile for testng.xml in pom.xml


<profiles>
 <profile>
 <id>SampleTest</id>
 <build>
 <plugins>
 <plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-surefire-plugin</artifactId>
 <version>2.16</version>
 <configuration>
 <argLine>-Xms2048M -Xmx4096M</argLine>
 <suiteXmlFiles>
 <suiteXmlFile>src/test/java/com/wavelabs/SeleniumTest/testng.xml</suiteXmlFile>
 </suiteXmlFiles>
 </configuration>
 <executions>
 <execution>
 <phase>integration-test</phase>
 <goals>
 <goal>test</goal>
 </goals>
 </execution>
 </executions>
 </plugin>
 </plugins>
 </build>
 </profile>
 </profiles>

Note :  we can have multiple testng.xml’s based on our requirement.. but with different names.. instead of testng.xml. we can give any valid name ..

For multiple testng.xml’s we should create multiple <profile> under <profiles> tag (Parent tag )..

6.  Executing Selenium test using maven

Run the command from the path of your project..
To Execute using Maven.. Command to use is :
Syntax :
mvn test -P”ProfileID”
Example :
mvn test -PSampleTest

7. Viewing the Test Reports whether it failed or passed

In the project structure, we see a ‘target folder’ , this folder contains the reports..
The file ‘emailable-report.html‘ gives you the complete report of your test..

p4