STQA-Selenium Practicals
STQA-Selenium Practicals
STQA-Selenium Practicals
Practical 2
Conduct a test suite for any two websites -
Create a script by Recording
Step 1- Launch Firefox and Selenium IDE
Type the value for any Base URL -http://demo.guru99.com/test/newtours/
Toggle the Record button on (if it’s not yet toggled on by default)
Step 2- In Firefox, navigate to http://demo.guru99.com/test/newtours/, firefox should take
you to the page which has been mentioned
Step 3-click on the various links or the pages on the given site
Step4 - you would see that the various commands shown in the IDE
Step 5- toggle the record button off to stop recording
Step 6- you can save the test suite (group of test cases) and give a name to it
TYBSc Computer Science
STQA – Solved Selenium Practical
List By
Dr. Madhavi Vaidya. VES College
My YouTube Channel –
madhavi2303
Step 7- Later go back to Selenium IDE,click the play button and execute the whole script or
run the recent Selenium IDE script.
Selenium IDE should be able to replicate everything flawlessly
Secondly, try the calculator.net to execute the operations such as Addition, Subtraction,
Multiplication and Division.
Practical 3 – Installation of Selenium server and demonstrate it using a script in Java.
Selenium installation is not only configuration and installation of single software but it is the
combination of few softwares configuration and installation. They are as below -
1. eclipse installation
2. Java configuration and setup
3. Selenium server standalone jar
4. geckodriver
Download selenium server for java, download latest and stable version (list can be found
from the site)
Download geckodriver
Keep all software in one folder (in my case its selenium settings) so that we can get them in
place as and when required
Open eclipse, create a java project as we are going to configure for Selenium using Java code
for automation.
You will find that JRE system lib files have been created and installed automatically.
Go to JRE System library, right click and Go to Build Path(it would be under Properties for
the Project name), check and open the Libraries Tab(if doesn’t open automatically), click on
add External JARs
Add here Selenium JAR file and Java JAR files from the said folder (selenium Settings)
a. Selenium has only one JAR file
b. But under Java,c:\ProgramFiles\Java\jre\lib , take all the JARs from here. Even go to each
and every folder like management,images,ext,deploy etc and choose all JARs one by one and
add through Add External JARs
OR
If port for the selenium server found already running busy then give the command as below -
-jar selenium-server-standalone-3.12.0.jar -port 1234 //-port 1234 is to be given if port 4444
is busy
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
driver.findElement(By.xpath("//*[@id=\"u_0_q\"]")).sendKeys("9869026553");
driver.findElement(By.xpath("//*[@id=\"u_0_x\"]")).sendKeys("passwd");
//Select sel1=new
Select(driver.findElement(By.xpath("//*[@id=\"day\"]")));
//sel1.selectByIndex("3");
//driver.findElement(By.id("SignIn")).click();
driver.findElement(By.xpath("//*[@id=\"u_0_15\"]")).click();
Select dropdown = new
Select(driver.findElement(By.id("day")));
dropdown.selectByIndex(2);
driver.findElement(By.xpath("//*[@id=\"month\"]")).sendKeys("July");
@Test
public void testImportexport1() throws Exception {
FileInputStream fi = new FileInputStream("E:\\selenium\\Student.xls");
Workbook w = Workbook.getWorkbook(fi);
Sheet s = w.getSheet(0);
String a[][] = new String[s.getRows()][s.getColumns()];
FileOutputStream fo = new FileOutputStream("E:\\selenium\\myBook2res.xls");
WritableWorkbook wwb = Workbook.createWorkbook(fo);
WritableSheet ws = wwb.createSheet("result1", 0);
for (int i = 0; i < s.getRows(); i++)
for (int j = 0; j < s.getColumns(); j++)
{
a[i][j] = s.getCell(j, i).getContents(); //first col of the specific row
Label l2 = new Label(j, i, a[i][j]);
ws.addCell(l2); //adding a new cell
Label l1 = new Label(6, 0, "Result"); //new label named Result would be created
6th col
ws.addCell(l1);
}
for (int i = 1; i < s.getRows(); i++) {
for (int j = 2; j < s.getColumns(); j++) //to check each row/col
{
a[i][j] = s.getCell(j, i).getContents();
int x=Integer.parseInt(a[i][j]);
if(x > 35) //if mks greater than 35 then pass , would be checked in each col
{
Label l1 = new Label(6, i, "pass"); //6th col would get pass/fail according to marks
ws.addCell(l1);
}
else
{
Label l1 = new Label(6, i, "fail");
ws.addCell(l1);
break; } }}
wwb.write();
wwb.close(); } }
TYBSc Computer Science
STQA – Solved Selenium Practical
List By
Dr. Madhavi Vaidya. VES College
My YouTube Channel –
madhavi2303
import java.io.FileReader;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.opencsv.CSVReader;
@BeforeTest
public void setup() throws Exception {
System.setProperty("webdriver.gecko.driver",
"E:\\Selenium\\gecko\\geckodriver.exe");
//WebDriver driver = new FirefoxDriver();
TYBSc Computer Science
STQA – Solved Selenium Practical
List By
Dr. Madhavi Vaidya. VES College
My YouTube Channel –
madhavi2303
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.get("http://only-testing-blog.blogspot.in/2014/05/form.html");
}
@Test
public void csvDataRead() throws IOException{
Workbook w = Workbook.getWorkbook(fi);
Sheet s = w.getSheet(0);
String a[][] = new String[s.getRows()][s.getColumns()];
FileOutputStream fout=new FileOutputStream("C:\\Users\\HP\\Desktop\\new1.xls");
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Sample_linkcount {
driver.get("http://toolsqa.wpengine.com/");
java.util.List<WebElement> links =
driver.findElements(By.tagName("a"));
System.out.println(links.size());
//Get all the option from dropdown list and assign into List
List<WebElement> listOptionDropdown = selectDropdown.getOptions();
// Count the item dropdown list and assign into integer variable
int dropdownCount = listOptionDropdown.size();
}}
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
TYBSc Computer Science
STQA – Solved Selenium Practical
List By
Dr. Madhavi Vaidya. VES College
My YouTube Channel –
madhavi2303
import org.openqa.selenium.firefox.FirefoxDriver;
import com.sun.xml.internal.bind.v2.schemagen.xmlschema.List;
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.ironspider.ca/forms/checkradio.htm");
}
int checkedCount=0, uncheckedCount=0;