Notes
Notes - notes.io |
import java.time.Duration;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.Assert;
import org.testng.annotations.*;
public class MemberTest {
WebDriver driver;
@BeforeClass
public void beforeClass() {
System.setProperty("webdriver.gecko.driver",
"/home/pg_user/Desktop/geckodriver");
driver = new FirefoxDriver();
driver.get("http://localhost:8080/application/index.html");
driver.manage().window().maximize();
driver.manage().timeouts()
.implicitlyWait(Duration.ofSeconds(8));
}
@Test(priority = 1)
public void test1() throws Exception {
driver.findElement(By.linkText("Add a Member")).click();
String filePath =
"/home/pg_user/Desktop/Additional SuppliedFiles/Data.xls";
FileInputStream fis = new FileInputStream(filePath);
Workbook wb = WorkbookFactory.create(fis);
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(1);
String fname = row.getCell(0).getStringCellValue();
String lname = row.getCell(1).getStringCellValue();
String email = row.getCell(2).getStringCellValue();
int empNo = (int) row.getCell(3).getNumericCellValue();
String stream = row.getCell(4).getStringCellValue();
driver.findElement(By.name("firstName"))
.sendKeys(fname);
driver.findElement(By.name("lastName"))
.sendKeys(lname);
driver.findElement(By.name("email"))
.sendKeys(email);
driver.findElement(By.name("employeeNumber"))
.sendKeys(String.valueOf(empNo));
Select s = new Select(
driver.findElement(By.name("stream")));
s.selectByVisibleText(stream);
driver.findElement(By.id("female")).click();
driver.findElement(By.id("addMember")).click();
String msg =
driver.findElement(By.id("message")).getText();
Row writeRow = sheet.getRow(1);
Cell cell = writeRow.createCell(5);
cell.setCellValue(msg);
FileOutputStream fos = new FileOutputStream(filePath);
wb.write(fos);
fos.close();
wb.close();
driver.findElement(By.linkText("Home")).click();
}
@Parameters({"type","pswd"})
@Test(priority = 2)
public void test2(String type, String pswd) {
driver.findElement(
By.linkText("Already a Member?"))
.click();
driver.findElement(By.name("userName"))
.sendKeys(type);
driver.findElement(By.name("password"))
.sendKeys(pswd);
driver.findElement(By.id("login")).click();
Assert.assertTrue(
driver.findElement(
By.linkText("SignOut"))
.isDisplayed());
}
@DataProvider(name = "courseData")
public Object[][] data() {
return new Object[][]{
{"Selenium Using Python","Educator"},
{"Agile Testing","Co-Educator"}
};
}
@Test(priority = 3,
dataProvider = "courseData")
public void test3(String course,
String role) {
Select courseDrop =
new Select(driver.findElement(
By.name("course")));
courseDrop.selectByVisibleText(course);
Select roleDrop =
new Select(driver.findElement(
By.name("role")));
roleDrop.selectByVisibleText(role);
driver.findElement(
By.id("addDetails"))
.click();
}
@AfterClass
public void afterClass() {
driver.findElement(
By.linkText("SignOut"))
.click();
driver.quit();
}
}
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="MemberSuite">
<parameter name="type" value="ivs_bob"/>
<parameter name="pswd" value="illumination"/>
<test name="MemberTest">
<classes>
<class name="MemberTest"/>
</classes>
</test>
</suite>
import java.io.FileInputStream;
import java.time.Duration;
import java.util.Iterator;
import java.util.Set;
import org.apache.poi.ss.usermodel.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.Assert;
import org.testng.annotations.*;
public class ShoppingTest {
WebDriver driver;
@BeforeClass
public void beforeClass() {
System.setProperty("webdriver.gecko.driver",
"/home/pg_user/Desktop/geckodriver");
driver = new FirefoxDriver();
driver.get("http://localhost:8080/application/index.html");
driver.manage().window().maximize();
driver.manage().timeouts()
.implicitlyWait(Duration.ofSeconds(6));
}
@DataProvider(name = "credentials")
public Object[][] getData() {
return new Object[][]{
{"[email protected]", "password1"},
{"[email protected]", "password2"}
};
}
@Test(priority = 1, dataProvider = "credentials")
public void test1(String username, String password) {
driver.findElement(By.name("email"))
.sendKeys(username);
driver.findElement(By.name("password"))
.sendKeys(password);
driver.findElement(By.id("login"))
.click();
Set<String> tabs = driver.getWindowHandles();
Iterator<String> it = tabs.iterator();
String parent = it.next();
String child = it.next();
driver.switchTo().window(child);
System.out.println("Title of Page: "
+ driver.getTitle());
int links =
driver.findElements(By.tagName("a")).size();
System.out.println("Number of Hyperlinks: "
+ links);
driver.findElement(By.linkText("Logout"))
.click();
System.out.println("After Logout, Title of Page: "
+ driver.getTitle());
Assert.assertEquals(driver.getTitle(),
"Login");
}
@Parameters({"username","password"})
@Test(priority = 2)
public void test2(String username,
String password) throws Exception {
driver.findElement(By.name("email"))
.sendKeys(username);
driver.findElement(By.name("password"))
.sendKeys(password);
driver.findElement(By.id("login"))
.click();
Set<String> tabs = driver.getWindowHandles();
for(String s : tabs) {
driver.switchTo().window(s);
}
String path =
"/home/pg_user/Desktop/Additional Supplied Files/Data.xls";
FileInputStream fis =
new FileInputStream(path);
Workbook wb =
WorkbookFactory.create(fis);
Sheet sheet =
wb.getSheetAt(0);
for(int i=1;i<=sheet.getLastRowNum();i++) {
Row row = sheet.getRow(i);
String item =
row.getCell(0).getStringCellValue();
int qty =
(int) row.getCell(1)
.getNumericCellValue();
Select itemType =
new Select(driver.findElement(
By.name("itemType")));
itemType.selectByVisibleText(item);
driver.findElement(By.name("quantity"))
.clear();
driver.findElement(By.name("quantity"))
.sendKeys(String.valueOf(qty));
driver.findElement(By.id("addItem"))
.click();
}
driver.findElement(
By.id("calculateBill"))
.click();
String bill =
driver.findElement(By.id("totalBill"))
.getText();
Assert.assertTrue(bill.contains("137"));
}
@Test(priority = 3)
public void test3() {
WebElement table =
driver.findElement(By.id("myCart"));
java.util.List<WebElement> rows =
table.findElements(By.tagName("tr"));
for(int i=1;i<rows.size();i++) {
java.util.List<WebElement> cols =
rows.get(i)
.findElements(By.tagName("td"));
System.out.println(
"Item: " + cols.get(0).getText());
System.out.println(
"Quantity: " + cols.get(1).getText());
System.out.println(
"Bill: " + cols.get(2).getText());
System.out.println();
}
}
@AfterClass
public void afterClass() {
driver.quit();
}
}
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="ShoppingSuite">
<parameter name="username"
value="[email protected]"/>
<parameter name="password"
value="password2"/>
<test name="ShoppingTest">
<classes>
<class name="ShoppingTest"/>
</classes>
</test>
</suite>
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.time.Duration;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.poi.ss.usermodel.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.*;
import org.testng.asserts.SoftAssert;
public class CourseRegistrationTest {
WebDriver driver;
@BeforeClass
public void beforeClass() {
System.setProperty("webdriver.gecko.driver",
"/home/pg_user/Desktop/geckodriver");
driver = new FirefoxDriver();
driver.get("http://localhost:8080/application/index.html");
driver.manage().window().maximize();
driver.manage().timeouts()
.implicitlyWait(Duration.ofSeconds(10));
}
@Test(priority = 1)
public void test1() throws IOException {
System.out.println("Title of current page is "
+ driver.getTitle());
TakesScreenshot ts =
(TakesScreenshot) driver;
File src = ts.getScreenshotAs(OutputType.FILE);
File dest = new File(
"/home/pg_user/Desktop/Additional SuppliedFiles/Screenshots/Image.PNG");
FileUtils.copyFile(src, dest);
}
@Test(priority = 2)
public void test2() throws Exception {
String excelPath =
"/home/pg_user/Desktop/Additional SuppliedFiles/Data.xls";
FileInputStream fis =
new FileInputStream(excelPath);
Workbook wb =
WorkbookFactory.create(fis);
Sheet sheet = wb.getSheetAt(0);
driver.findElement(
By.linkText("Browse Catalog"))
.click();
driver.findElement(
By.linkText("Free Courses Online"))
.click();
driver.findElement(
By.linkText("Intro to Programming in Python"))
.click();
driver.findElement(
By.id("enroll"))
.click();
for (int i = 1; i <= 3; i++) {
Row row = sheet.getRow(i);
String name =
row.getCell(0).getStringCellValue();
String email =
row.getCell(1).getStringCellValue();
driver.findElement(By.name("name"))
.clear();
driver.findElement(By.name("name"))
.sendKeys(name);
driver.findElement(By.name("email"))
.clear();
driver.findElement(By.name("email"))
.sendKeys(email);
driver.findElement(By.name("college"))
.clear();
driver.findElement(By.name("college"))
.sendKeys("RTU");
driver.findElement(By.name("year"))
.clear();
driver.findElement(By.name("year"))
.sendKeys("2013");
driver.findElement(By.id("register"))
.click();
String message =
driver.findElement(By.id("message"))
.getText();
System.out.println(message);
}
wb.close();
}
@Test(priority = 3)
public void test3() {
driver.findElement(
By.linkText("Offers"))
.click();
WebElement table =
driver.findElement(By.id("offerTable"));
List<WebElement> rows =
table.findElements(By.tagName("tr"));
for (WebElement row : rows) {
List<WebElement> cols =
row.findElements(By.tagName("td"));
for (WebElement col : cols) {
System.out.print(
col.getText() + " ");
}
System.out.println();
}
SoftAssert softAssert =
new SoftAssert();
softAssert.assertEquals(
driver.getTitle(),
"Offers");
softAssert.assertAll();
}
@AfterClass
public void afterClass() {
driver.quit();
}
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team
