├── .idea ├── .gitignore ├── vcs.xml ├── misc.xml ├── compiler.xml └── jarRepositories.xml ├── TayfaTestNG.iml ├── src └── test │ ├── resources │ └── veriler.xlsx │ └── java │ └── com │ └── tayfa │ ├── pages │ ├── AmazonPage.java │ └── W3Schools.java │ ├── tests │ ├── AmazonAramaTest.java │ ├── WindowHandlesTest.java │ ├── AlertTest.java │ ├── TableTest.java │ └── GoogleAramaTest.java │ ├── utilities │ ├── ConfigurationReader.java │ ├── ReusableMethods.java │ ├── Driver.java │ └── ExcelUtil.java │ └── excelautomation │ ├── WriteExcel.java │ └── ReadExcel.java ├── target └── test-classes │ ├── veriler.xlsx │ └── com │ └── tayfa │ ├── pages │ ├── AmazonPage.class │ └── W3Schools.class │ ├── tests │ ├── AlertTest.class │ ├── TableTest.class │ ├── AmazonAramaTest.class │ ├── GoogleAramaTest.class │ └── WindowHandlesTest.class │ ├── utilities │ ├── Driver.class │ ├── ExcelUtil.class │ ├── ReusableMethods.class │ └── ConfigurationReader.class │ └── excelautomation │ ├── ReadExcel.class │ └── WriteExcel.class ├── configuration.properties ├── pom.xml └── ders_notlari.txt /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /workspace.xml -------------------------------------------------------------------------------- /TayfaTestNG.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/test/resources/veriler.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hamzayilmaz2021/TayfaTestNG/HEAD/src/test/resources/veriler.xlsx -------------------------------------------------------------------------------- /target/test-classes/veriler.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hamzayilmaz2021/TayfaTestNG/HEAD/target/test-classes/veriler.xlsx -------------------------------------------------------------------------------- /configuration.properties: -------------------------------------------------------------------------------- 1 | browser = chrome 2 | engineer = hamza 3 | p_version = 0.0 4 | adres = https://www.google.com -------------------------------------------------------------------------------- /target/test-classes/com/tayfa/pages/AmazonPage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hamzayilmaz2021/TayfaTestNG/HEAD/target/test-classes/com/tayfa/pages/AmazonPage.class -------------------------------------------------------------------------------- /target/test-classes/com/tayfa/pages/W3Schools.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hamzayilmaz2021/TayfaTestNG/HEAD/target/test-classes/com/tayfa/pages/W3Schools.class -------------------------------------------------------------------------------- /target/test-classes/com/tayfa/tests/AlertTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hamzayilmaz2021/TayfaTestNG/HEAD/target/test-classes/com/tayfa/tests/AlertTest.class -------------------------------------------------------------------------------- /target/test-classes/com/tayfa/tests/TableTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hamzayilmaz2021/TayfaTestNG/HEAD/target/test-classes/com/tayfa/tests/TableTest.class -------------------------------------------------------------------------------- /target/test-classes/com/tayfa/utilities/Driver.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hamzayilmaz2021/TayfaTestNG/HEAD/target/test-classes/com/tayfa/utilities/Driver.class -------------------------------------------------------------------------------- /target/test-classes/com/tayfa/utilities/ExcelUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hamzayilmaz2021/TayfaTestNG/HEAD/target/test-classes/com/tayfa/utilities/ExcelUtil.class -------------------------------------------------------------------------------- /target/test-classes/com/tayfa/tests/AmazonAramaTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hamzayilmaz2021/TayfaTestNG/HEAD/target/test-classes/com/tayfa/tests/AmazonAramaTest.class -------------------------------------------------------------------------------- /target/test-classes/com/tayfa/tests/GoogleAramaTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hamzayilmaz2021/TayfaTestNG/HEAD/target/test-classes/com/tayfa/tests/GoogleAramaTest.class -------------------------------------------------------------------------------- /target/test-classes/com/tayfa/tests/WindowHandlesTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hamzayilmaz2021/TayfaTestNG/HEAD/target/test-classes/com/tayfa/tests/WindowHandlesTest.class -------------------------------------------------------------------------------- /target/test-classes/com/tayfa/excelautomation/ReadExcel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hamzayilmaz2021/TayfaTestNG/HEAD/target/test-classes/com/tayfa/excelautomation/ReadExcel.class -------------------------------------------------------------------------------- /target/test-classes/com/tayfa/excelautomation/WriteExcel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hamzayilmaz2021/TayfaTestNG/HEAD/target/test-classes/com/tayfa/excelautomation/WriteExcel.class -------------------------------------------------------------------------------- /target/test-classes/com/tayfa/utilities/ReusableMethods.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hamzayilmaz2021/TayfaTestNG/HEAD/target/test-classes/com/tayfa/utilities/ReusableMethods.class -------------------------------------------------------------------------------- /target/test-classes/com/tayfa/utilities/ConfigurationReader.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hamzayilmaz2021/TayfaTestNG/HEAD/target/test-classes/com/tayfa/utilities/ConfigurationReader.class -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/test/java/com/tayfa/pages/AmazonPage.java: -------------------------------------------------------------------------------- 1 | package com.tayfa.pages; 2 | 3 | import com.tayfa.utilities.Driver; 4 | import org.openqa.selenium.WebElement; 5 | import org.openqa.selenium.support.FindBy; 6 | import org.openqa.selenium.support.PageFactory; 7 | 8 | public class AmazonPage { 9 | 10 | public AmazonPage(){ 11 | PageFactory.initElements(Driver.getDriver() , this); 12 | } 13 | 14 | @FindBy ( id = "twotabsearchtextbox" ) 15 | public WebElement aramaKutusu; 16 | 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/test/java/com/tayfa/tests/AmazonAramaTest.java: -------------------------------------------------------------------------------- 1 | package com.tayfa.tests; 2 | 3 | import com.tayfa.pages.AmazonPage; 4 | import com.tayfa.utilities.Driver; 5 | import org.openqa.selenium.Keys; 6 | import org.testng.annotations.Test; 7 | 8 | public class AmazonAramaTest { 9 | 10 | AmazonPage page = new AmazonPage(); 11 | 12 | 13 | 14 | 15 | @Test 16 | public void aramaTesti(){ 17 | 18 | Driver.getDriver().get("https://amazon.com"); 19 | // aramakutusuna iphone yaz ve ara. 20 | 21 | page.aramaKutusu.sendKeys("iphone"+ Keys.ENTER); 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/com/tayfa/pages/W3Schools.java: -------------------------------------------------------------------------------- 1 | package com.tayfa.pages; 2 | 3 | import com.tayfa.utilities.Driver; 4 | import org.openqa.selenium.WebElement; 5 | import org.openqa.selenium.support.FindBy; 6 | import org.openqa.selenium.support.PageFactory; 7 | 8 | import java.util.List; 9 | 10 | public class W3Schools { 11 | 12 | public W3Schools(){ 13 | PageFactory.initElements( Driver.getDriver() , this ); 14 | } 15 | 16 | @FindBy ( xpath = "(//table)[1]//th" ) 17 | public List basliklar; 18 | 19 | @FindBy ( xpath = "(//table)[1]/tbody//td") 20 | public List hucreler; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/com/tayfa/utilities/ConfigurationReader.java: -------------------------------------------------------------------------------- 1 | package com.tayfa.utilities; 2 | 3 | import java.io.FileInputStream; 4 | import java.io.IOException; 5 | import java.util.Properties; 6 | 7 | public class ConfigurationReader { 8 | static Properties properties; 9 | 10 | static { 11 | String path = "configuration.properties"; 12 | FileInputStream file = null; 13 | try { 14 | file = new FileInputStream(path); 15 | properties = new Properties(); 16 | properties.load(file); 17 | } catch (IOException e) { 18 | e.printStackTrace(); 19 | } 20 | } 21 | 22 | public static String getPropery(String key){ 23 | return properties.getProperty(key); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | -------------------------------------------------------------------------------- /src/test/java/com/tayfa/utilities/ReusableMethods.java: -------------------------------------------------------------------------------- 1 | package com.tayfa.utilities; 2 | 3 | import org.openqa.selenium.By; 4 | import org.openqa.selenium.WebElement; 5 | 6 | import java.util.List; 7 | 8 | public class ReusableMethods { 9 | 10 | public static void sleep(int miliseconds){ 11 | try { 12 | Thread.sleep(miliseconds); 13 | } catch (InterruptedException e) { 14 | e.printStackTrace(); 15 | } 16 | } 17 | 18 | 19 | public static List getBasliklar(){ 20 | return Driver.getDriver().findElements(By.xpath("(//table)[1]//th")); 21 | } 22 | 23 | public static List getSatirlar(){ 24 | return Driver.getDriver().findElements(By.xpath("(//table)[1]/tbody/tr")); 25 | } 26 | 27 | public static List getTumHucreler(){ 28 | return Driver.getDriver().findElements(By.xpath("(//table)[1]/tbody//td")); 29 | } 30 | 31 | public static List getSatirdakiHucreler(int satir){ 32 | return Driver.getDriver().findElements(By.xpath("((//table)[1]/tbody/tr)["+satir+"]")); 33 | } 34 | 35 | public static List getSutun(int sutun){ 36 | return Driver.getDriver().findElements(By.xpath("(//table)[1]//tr/td["+sutun+"]")); 37 | } 38 | 39 | public static WebElement getSatirSutun(int satir, int sutun){ 40 | return Driver.getDriver().findElement(By.xpath("(//table)[1]//tr["+satir+"]/td["+sutun+"]")); 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/tayfa/tests/WindowHandlesTest.java: -------------------------------------------------------------------------------- 1 | package com.tayfa.tests; 2 | 3 | import com.tayfa.utilities.Driver; 4 | import com.tayfa.utilities.ReusableMethods; 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.WebElement; 7 | import org.testng.annotations.Test; 8 | 9 | import java.util.HashSet; 10 | import java.util.Set; 11 | 12 | public class WindowHandlesTest { 13 | 14 | @Test 15 | public void setTest(){ 16 | Set liste = new HashSet<>(); 17 | liste.add("Istanbul"); 18 | liste.add("Ankara"); 19 | liste.add("Zonguldak"); 20 | 21 | System.out.println(liste.toString()); 22 | 23 | } 24 | 25 | @Test 26 | public void test(){ 27 | Driver.getDriver().get("https://www.w3schools.com/html/default.asp"); 28 | String w3schoolsHandle = Driver.getDriver().getWindowHandle(); 29 | 30 | WebElement facebookLink = Driver.getDriver().findElement(By.xpath("//a[@title='Facebook']")); 31 | 32 | facebookLink.click(); 33 | String facebookHandle = Driver.getDriver().getWindowHandle(); 34 | 35 | //Set liste = Driver.getDriver().getWindowHandles(); 36 | 37 | ReusableMethods.sleep(3000); 38 | Driver.getDriver().switchTo().window(w3schoolsHandle); 39 | 40 | ReusableMethods.sleep(3000); 41 | Driver.getDriver().switchTo().window(facebookHandle); 42 | 43 | ReusableMethods.sleep(3000); 44 | Driver.getDriver().switchTo().window(w3schoolsHandle); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/com/tayfa/tests/AlertTest.java: -------------------------------------------------------------------------------- 1 | package com.tayfa.tests; 2 | 3 | import com.tayfa.utilities.Driver; 4 | import com.tayfa.utilities.ReusableMethods; 5 | import org.openqa.selenium.Alert; 6 | import org.openqa.selenium.By; 7 | import org.openqa.selenium.WebElement; 8 | import org.testng.annotations.Test; 9 | 10 | public class AlertTest { 11 | 12 | @Test 13 | public void test(){ 14 | 15 | /* 16 | WebElement kabulLinki = Driver.getDriver().findElement(By.xpath("//a[@onclick='removeCookiePolicy()']")); 17 | kabulLinki.click(); 18 | */ 19 | 20 | Driver.getDriver().get("https://www.tutorialsteacher.com/codeeditor?cid=js-1"); 21 | 22 | ReusableMethods.sleep(2000); 23 | 24 | // Alert'e geçiş yaptık. 25 | 26 | Alert alert1 = Driver.getDriver().switchTo().alert(); 27 | String icerik1 = alert1.getText(); 28 | alert1.accept(); 29 | 30 | Alert alert2 = Driver.getDriver().switchTo().alert(); 31 | String icerik2 = alert2.getText(); 32 | alert2.accept(); 33 | 34 | Alert alert3 = Driver.getDriver().switchTo().alert(); 35 | String icerik3 = alert3.getText(); 36 | alert3.accept(); 37 | 38 | System.out.println(icerik1); 39 | System.out.println(icerik2); 40 | System.out.println(icerik3); 41 | 42 | 43 | WebElement homeLinki = Driver.getDriver().findElement(By.xpath("//a[@title='TutorialsTeacher.com Home']")); 44 | 45 | homeLinki.click(); 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/com/tayfa/excelautomation/WriteExcel.java: -------------------------------------------------------------------------------- 1 | package com.tayfa.excelautomation; 2 | 3 | import org.apache.poi.ss.usermodel.*; 4 | import org.testng.annotations.Test; 5 | 6 | import java.io.FileInputStream; 7 | import java.io.FileOutputStream; 8 | import java.io.IOException; 9 | 10 | public class WriteExcel { 11 | 12 | @Test 13 | public void test() throws IOException { 14 | String dosyaYolu = "src/test/resources/veriler.xlsx"; 15 | FileInputStream file = new FileInputStream(dosyaYolu); 16 | 17 | // Workbook (excel) dosyasını okuyalım 18 | Workbook excel = WorkbookFactory.create(file); 19 | 20 | FileOutputStream fileOutputStream = new FileOutputStream(dosyaYolu); 21 | 22 | // Sheet seçimi 23 | Sheet sheet = excel.getSheetAt(0); 24 | 25 | // Yeni bir hücre oluşturma ve içerisine data ekleme 26 | sheet.getRow(0).createCell(3).setCellValue("Yorum"); 27 | sheet.getRow(1).createCell(3).setCellValue("50"); 28 | sheet.getRow(2).createCell(3).setCellValue("100"); 29 | //sheet.getRow(3).createCell(3).setCellValue("5"); 30 | 31 | // Satır silmek için 32 | Row silinecekSatir = sheet.getRow(3); 33 | sheet.removeRow(silinecekSatir); 34 | 35 | // Hücre silmek için 36 | Cell silinecekHucre = sheet.getRow(0).getCell(0); 37 | sheet.getRow(0).removeCell(silinecekHucre); 38 | 39 | 40 | excel.write(fileOutputStream); 41 | excel.close(); 42 | file.close(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/com/tayfa/tests/TableTest.java: -------------------------------------------------------------------------------- 1 | package com.tayfa.tests; 2 | 3 | import com.tayfa.pages.W3Schools; 4 | import com.tayfa.utilities.Driver; 5 | import com.tayfa.utilities.ReusableMethods; 6 | import org.openqa.selenium.WebElement; 7 | import org.testng.annotations.Test; 8 | 9 | import java.util.List; 10 | 11 | public class TableTest { 12 | 13 | W3Schools schools = new W3Schools(); 14 | 15 | @Test 16 | public void tumBasliklar(){ 17 | String url = "https://www.w3schools.com/html/html_tables.asp"; 18 | Driver.getDriver().get(url); 19 | 20 | // List 21 | 22 | 23 | for (WebElement element : schools.basliklar) { 24 | 25 | System.out.println(element.getText()); 26 | 27 | } 28 | 29 | } 30 | 31 | @Test 32 | public void tumHucreler(){ 33 | String url = "https://www.w3schools.com/html/html_tables.asp"; 34 | Driver.getDriver().get(url); 35 | 36 | for(WebElement element : schools.hucreler){ 37 | System.out.println(element.getText()); 38 | } 39 | } 40 | 41 | @Test 42 | public void tumBasliklarReusableMethods(){ 43 | String url = "https://www.w3schools.com/html/html_tables.asp"; 44 | Driver.getDriver().get(url); 45 | 46 | List liste = ReusableMethods.getBasliklar(); 47 | 48 | for(WebElement element : liste){ 49 | System.out.println(element.getText()); 50 | } 51 | } 52 | 53 | @Test 54 | public void satirSutunTesti() { 55 | String url = "https://www.w3schools.com/html/html_tables.asp"; 56 | Driver.getDriver().get(url); 57 | 58 | WebElement element = ReusableMethods.getSatirSutun(6,3); 59 | 60 | System.out.println(element.getText()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/com/tayfa/utilities/Driver.java: -------------------------------------------------------------------------------- 1 | package com.tayfa.utilities; 2 | 3 | import io.github.bonigarcia.wdm.WebDriverManager; 4 | 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.chrome.ChromeDriver; 7 | import org.openqa.selenium.firefox.FirefoxDriver; 8 | import org.openqa.selenium.ie.InternetExplorerDriver; 9 | import org.openqa.selenium.safari.SafariDriver; 10 | 11 | public class Driver { 12 | static WebDriver driver; 13 | 14 | public static WebDriver getDriver(){ 15 | if( driver == null ){ 16 | // properties dosyasının içerisindeki "browser" anahtarının 17 | // değerini getirecek ---> chrome 18 | String browser = ConfigurationReader.getPropery("browser"); 19 | 20 | switch (browser) { 21 | case "chrome": 22 | WebDriverManager.chromedriver().setup(); 23 | driver = new ChromeDriver(); 24 | break; 25 | case "firefox": 26 | WebDriverManager.firefoxdriver().setup(); 27 | driver = new FirefoxDriver(); 28 | break; 29 | case "ie": 30 | WebDriverManager.iedriver().setup(); 31 | driver = new InternetExplorerDriver(); 32 | break; 33 | case "safari": 34 | WebDriverManager.getInstance(SafariDriver.class).setup(); 35 | driver = new SafariDriver(); 36 | break; 37 | } 38 | } 39 | return driver; 40 | } 41 | 42 | public static void closeDriver(){ 43 | 44 | if(driver != null){ 45 | driver.quit(); 46 | driver = null; 47 | } 48 | 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | TayfaTestNG 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 1.8 13 | 1.8 14 | 15 | 16 | 17 | 18 | 19 | 20 | org.seleniumhq.selenium 21 | selenium-java 22 | 3.141.59 23 | 24 | 25 | 26 | 27 | io.github.bonigarcia 28 | webdrivermanager 29 | 4.2.0 30 | 31 | 32 | 33 | 34 | org.testng 35 | testng 36 | 7.1.0 37 | test 38 | 39 | 40 | 41 | 42 | org.apache.poi 43 | poi 44 | 4.1.2 45 | 46 | 47 | 48 | 49 | org.apache.poi 50 | poi-ooxml 51 | 4.1.2 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/test/java/com/tayfa/excelautomation/ReadExcel.java: -------------------------------------------------------------------------------- 1 | package com.tayfa.excelautomation; 2 | 3 | import org.apache.poi.ss.usermodel.*; 4 | import org.testng.annotations.Test; 5 | 6 | import java.io.FileInputStream; 7 | import java.io.FileNotFoundException; 8 | import java.io.IOException; 9 | 10 | public class ReadExcel { 11 | 12 | @Test 13 | public void test() throws IOException { 14 | 15 | String dosyaYolu = "src/test/resources/veriler.xlsx"; 16 | FileInputStream file = new FileInputStream(dosyaYolu); 17 | 18 | // Workbook (excel) dosyasını okuyalım 19 | Workbook excel = WorkbookFactory.create(file); 20 | 21 | // Sheet seçimi 22 | Sheet sheet = excel.getSheetAt(0); 23 | 24 | // Satırlar 25 | Row birinciSatir = sheet.getRow(0); 26 | 27 | // Hücreler 28 | Cell isim = birinciSatir.getCell(0); 29 | Cell sayi = birinciSatir.getCell(1); 30 | Cell kategori = birinciSatir.getCell(2); 31 | 32 | System.out.println(isim.toString()); 33 | System.out.println(sayi.toString()); 34 | System.out.println(kategori.toString()); 35 | /* 36 | // Kulaklık Satırı 37 | Row ikinciSatir = sheet.getRow(1); 38 | 39 | // Kategori hücresi 40 | Cell kulaklikKategori = ikinciSatir.getCell(2); 41 | */ 42 | 43 | Cell kulaklikKategori = sheet.getRow(1).getCell(2); 44 | System.out.println(kulaklikKategori.toString()); 45 | 46 | // Son satır indexini alma 47 | int sonSatir = sheet.getLastRowNum(); 48 | System.out.println(sonSatir); 49 | 50 | // İçerisinde data olan satır sayısı 51 | int satirSayisi = sheet.getPhysicalNumberOfRows(); 52 | System.out.println(satirSayisi); 53 | 54 | /*for(int i = 0; i <= sonSatir ; i++){ 55 | Cell data = sheet.getRow(i).getCell(2); 56 | System.out.println(data.toString()); 57 | }*/ 58 | 59 | for(Row row : sheet){ 60 | System.out.println(row.getCell(2).toString()); 61 | } 62 | 63 | // Sütun sayısını alma 64 | int sutunSayisi = sheet.getRow(2).getLastCellNum(); 65 | System.out.println(sutunSayisi); 66 | 67 | /*for(int k = 0 ; k < sutunSayisi ; k++){ 68 | Cell data = sheet.getRow(2).getCell(k); 69 | System.out.println(data.toString()); 70 | }*/ 71 | 72 | for(Cell cell : sheet.getRow(2)){ 73 | System.out.println(cell.toString()); 74 | } 75 | 76 | 77 | excel.close(); 78 | file.close(); 79 | 80 | } 81 | 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/test/java/com/tayfa/tests/GoogleAramaTest.java: -------------------------------------------------------------------------------- 1 | package com.tayfa.tests; 2 | 3 | import com.tayfa.pages.AmazonPage; 4 | import com.tayfa.utilities.Driver; 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.WebElement; 7 | import org.testng.annotations.Test; 8 | 9 | import java.util.List; 10 | 11 | public class GoogleAramaTest { 12 | 13 | @Test 14 | public void aramaTesti(){ 15 | 16 | 17 | // Driver'ı başlatır ve google'a gider. 18 | Driver.getDriver().get("https://www.amazon.com"); 19 | 20 | WebElement aramaKutusu2 = Driver.getDriver().findElement(By.xpath("//input[@id='twotabsearchtextbox']")); 21 | 22 | WebElement aramaKutusu = Driver.getDriver().findElement(By.id("twotabsearchtextbox")); 23 | aramaKutusu.sendKeys("telefon"); 24 | 25 | Driver.getDriver().navigate().to("https://www.amazon.com/AmazonBasics-Ear-Headphones-Mic-Black/dp/B07HH1QSLB/ref=sxin_5_trfob_0?cv_ct_cx=headphones&dchild=1&keywords=headphone&pd_rd_i=B07HH1QSLB&pd_rd_r=0bbe1ea0-6945-4453-aaeb-c82a5795e78a&pd_rd_w=TwVIK&pd_rd_wg=jN47U&pf_rd_p=6c6f0ed1-2306-4f6f-832e-d796b7d41a25&pf_rd_r=0D0E2KVA3AYQNAQY4BHB&qid=1620581814&sr=1-1-fcc74f9e-0165-48d2-a9e1-f41ea92a035c"); 26 | 27 | 28 | WebElement baslik = Driver.getDriver().findElement(By.tagName("h1")); 29 | String baslikString = baslik.getText(); 30 | System.out.println(baslikString); 31 | 32 | WebElement cevaplananSorular = Driver.getDriver().findElement(By.partialLinkText("50 answered questions")); 33 | String cevaplananSorularString = cevaplananSorular.getText(); 34 | System.out.println(cevaplananSorularString); 35 | 36 | List linkler = Driver.getDriver().findElements(By.tagName("a")); 37 | 38 | for(WebElement element : linkler){ 39 | System.out.println(element.getText()); 40 | } 41 | 42 | 43 | /* 44 | // 5 sn beklesin 45 | ReusableMethods.sleep(2000); 46 | 47 | // Başlığı alalım 48 | String baslik = Driver.getDriver().getTitle(); 49 | System.out.println(baslik); 50 | 51 | // Amazon.com'a gidelim 52 | Driver.getDriver().navigate().to("https://www.amazon.com"); 53 | 54 | // Başlığı alalım 55 | String baslikAmazon = Driver.getDriver().getTitle(); 56 | System.out.println(baslikAmazon); 57 | 58 | // Google.com'a geri dönelim. 59 | Driver.getDriver().navigate().back(); 60 | 61 | ReusableMethods.sleep(2000); 62 | 63 | // Amazon.com'a geri dönelim. 64 | Driver.getDriver().navigate().forward(); 65 | 66 | // driver classı içerisindeki close methodunu çağırır 67 | Driver.closeDriver(); 68 | */ 69 | } 70 | 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/com/tayfa/utilities/ExcelUtil.java: -------------------------------------------------------------------------------- 1 | package com.tayfa.utilities; 2 | 3 | import org.apache.poi.ss.usermodel.*; 4 | import org.testng.Assert; 5 | 6 | import java.io.FileInputStream; 7 | import java.io.FileOutputStream; 8 | import java.util.ArrayList; 9 | import java.util.HashMap; 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | public class ExcelUtil { 14 | private Sheet workSheet; 15 | private Workbook workBook; 16 | private String path; 17 | public ExcelUtil(String path, String sheetName) { 18 | this.path = path; 19 | try { 20 | // Open the Excel file 21 | FileInputStream ExcelFile = new FileInputStream(path); 22 | // Access the required test data sheet 23 | workBook = WorkbookFactory.create(ExcelFile); 24 | workSheet = workBook.getSheet(sheetName); 25 | Assert.assertNotNull(workSheet, "Worksheet: \"" + sheetName + "\" was not found\n"); 26 | } catch (Exception e) { 27 | throw new RuntimeException(e); 28 | } 29 | } 30 | // we create an object ExcelUtil class to work with specific excel file 31 | //in this case, file path will be retrieved from properties file 32 | public ExcelUtil(String sheetName) { 33 | //we are getting path to the excel file from properties file 34 | this.path = ConfigurationReader.getPropery("users_test_data"); 35 | try { 36 | // Open the Excel file 37 | FileInputStream ExcelFile = new FileInputStream(path); 38 | // Access the required test data sheet 39 | workBook = WorkbookFactory.create(ExcelFile); 40 | //Access specific work sheet 41 | //Then worksheet, contains table with rows and columns 42 | workSheet = workBook.getSheet(sheetName); 43 | //if spreadsheet is empty, throw exception 44 | Assert.assertNotNull(workSheet, "Worksheet: \"" + sheetName + "\" was not found\n"); 45 | } catch (Exception e) { 46 | //there is no point to continue without file 47 | throw new RuntimeException(e); 48 | } 49 | } 50 | public String getCellData(int rowNum, int colNum) { 51 | Cell cell; 52 | try { 53 | cell = workSheet.getRow(rowNum).getCell(colNum); 54 | String cellData = cell.toString(); 55 | return cellData; 56 | } catch (Exception e) { 57 | throw new RuntimeException(e); 58 | } 59 | } 60 | //this method will return data table as 2d array 61 | //so we need this format because of data provider. 62 | public String[][] getDataArray() { 63 | String[][] data = new String[rowCount()][columnCount()]; 64 | for (int i = 0; i < rowCount(); i++) { 65 | for (int j = 0; j < columnCount(); j++) { 66 | String value = getCellData(i, j); 67 | data[i][j] = value; 68 | } 69 | } 70 | return data; 71 | } 72 | public List> getDataList() { 73 | // get all columns 74 | List columns = getColumnsNames(); 75 | // this will be returned 76 | List> data = new ArrayList<>(); 77 | for (int i = 1; i < rowCount(); i++) { 78 | // get each row 79 | Row row = workSheet.getRow(i); 80 | // create map of the row using the column and value 81 | // column map key, cell value --> map bvalue 82 | Map rowMap = new HashMap(); 83 | for (Cell cell : row) { 84 | int columnIndex = cell.getColumnIndex(); 85 | rowMap.put(columns.get(columnIndex), cell.toString()); 86 | } 87 | data.add(rowMap); 88 | } 89 | return data; 90 | } 91 | public List getColumnsNames() { 92 | List columns = new ArrayList<>(); 93 | for (Cell cell : workSheet.getRow(0)) { 94 | columns.add(cell.toString()); 95 | } 96 | return columns; 97 | } 98 | public void setCellData(String value, int rowNum, int colNum) { 99 | Cell cell; 100 | Row row; 101 | try { 102 | row = workSheet.getRow(rowNum); 103 | cell = row.getCell(colNum); 104 | if (cell == null) { 105 | cell = row.createCell(colNum); 106 | cell.setCellValue(value); 107 | } else { 108 | cell.setCellValue(value); 109 | } 110 | FileOutputStream fileOut = new FileOutputStream(path); 111 | workBook.write(fileOut); 112 | fileOut.close(); 113 | } catch (Exception e) { 114 | e.printStackTrace(); 115 | } 116 | } 117 | public void setCellData(String value, String columnName, int row) { 118 | int column = getColumnsNames().indexOf(columnName); 119 | setCellData(value, row, column); 120 | } 121 | public int columnCount() { 122 | return workSheet.getRow(0).getLastCellNum(); 123 | } 124 | public int rowCount() { 125 | return workSheet.getLastRowNum() + 1; 126 | } 127 | } -------------------------------------------------------------------------------- /ders_notlari.txt: -------------------------------------------------------------------------------- 1 | TestNG Dersleri - 1. Ders 2 | Framework oluşturma 3 | 4 | -----TestNG ihtiyacımız olan kütüphaneler 5 | 6 | * Selenium-Java 7 | selenium-java 8 | * WebDriverManager 9 | webdrivermanager 10 | * TestNG 11 | testng 12 | 13 | ConfigurationReader.getProperty("browser") 14 | ===> chrome 15 | 16 | ConfigurationReader.getProperty("engineer") 17 | ===> hamza 18 | 19 | Driver.getDriver(); 20 | 21 | TestNG Dersleri - 2. Ders 22 | 23 | Driver.getDriver(); ---> Tarayıcımız 24 | 25 | .get("sayfaAdresi") -> istedilen sayfaya gitme 26 | 27 | .quit() -> Tarayıcıyı kapatır (açık olan tüm sekmelerle beraber) 28 | 29 | .close() -> Üzerinde bulunduğumuz, açık sekmeyi kapatmak için kullanılır. 30 | 31 | .getTitle() -> Üzerinde bulunduğumuz sayfanın başlığını getirir. 32 | 33 | .navigate().to -> İstediğimiz sayfaya yönlendiriyor (.get() methodu gibi) 34 | 35 | .navigate().back() -> Bir önceki sayfaya götürür. 36 | 37 | .navigate().forward() -> Geri geldiğimiz sayfaya götürür. 38 | 39 | .navigate().refresh() -> Sayfayı yeniler 40 | 41 | 42 | ***** navigate -> sayfa geçmişimiz ve çerezlerimiz(cookies) oluyor. 43 | - ileri, geri gidebiliriz. 44 | 45 | ***** get -> herhangi bir geçmiş ya da çerez(cookies) yok. 46 | 47 | aramaKutusu -> yaz -> kulaklık 48 | araButonu -> tıkla 49 | urunListesi -> tıkla 50 | fiyatBilgisi -> yazdir 51 | 52 | 53 |
--> tag açma 54 | Hamza Yılmaz --> içerik 55 |
--> tag kapatma 56 | 57 | 58 | tag ismi : div 59 | attribute : class ve id 60 | içerik : Hamza Yılmaz 61 | 62 | 63 | 64 | Hediye 65 | 66 | 67 | tag ismi : a 68 | attribute : href, class 69 | içerik : Hediye 70 | 71 |
72 | 73 |
Hamza Yılmaz
74 | 75 |
76 | You are on amazon.com. You can also shop on Amazon Turkey for millions of products with fast local delivery. Click here to go to amazon.com.tr 77 |
78 | 79 |
80 | 81 | 82 | tag ismi : div 83 | attribute : id, class 84 | id attribute'nun değeri : icerik 85 | class attribute'nun değeri : makale 86 | 87 | icerik elementinin 2 tane child'ı var. bunlar; 88 |
89 |
90 | 91 | baslik elementi parent'ı vardır. bu; 92 |
93 | 94 | baslik ve yazi elementi de kardeş elementlerdir. 95 | 96 | 97 | TestNG 3. Ders 98 | 99 | Google 100 | 101 | 102 | 103 | Locators 104 | 105 | 1. id 106 | 2. name 107 | 3. className 108 | 4. tagName 109 | 5. linkText (a elementi) 110 | 6. partialLinkText (a elementi) 111 | 7. xpath -> Tüm elementler 112 | 8. cssSelector -> CSS Değerleri 113 | 114 | 115 | 116 | 117 | 50 answered questions 118 | 119 | 120 | 121 | 122 | -> id, className, tagName, linkText, partialLinkText, xpath, cssSelector 123 | 124 | 125 | 126 | 127 | 128 | 1. id 129 | 2. name 130 | 3. className 131 | 4. tagName 132 | 5. xpath 133 | 6. cssSelector (class ve id) 134 | 135 | .findElement(By.id("buy-now-button")) 136 | 137 | .findElement(By.name("submit.buy-now")) 138 | 139 | .findElement(By.className("a-button-input")) 140 | 141 | .findElement(By.tagName("input")) 142 | 143 | .findElement(By.xpath(".....")) 144 | 145 | .findElement(By.cssSelector("....")) 146 | 147 | 148 | 149 | 150 | ********************************** 151 | 152 | Driver.getDriver(). 153 | => findElement(By.locatorTuru) 154 | ***** sadece 1 tane 155 | 156 | => findElements(By.locatorTur) 157 | ***** tüm elementleri, liste şeklinde 158 | 159 | 160 | 161 | 162 | WebElement aramaKutusu = findElement(By.locatorTuru) 163 | 164 | 165 | #twotabsearchtextbox ---> id 166 | .class-degeri ---> class 167 | 168 | 169 | 170 | 50 answered questions 171 | 172 | 173 | className 174 | cssSelector 175 | 176 | findElement(By.className("base")) 177 | findElement(By.cssSelector(".base")) 178 | 179 | findElement(By.id("kutu")) 180 | findElement(By.cssSelector("#kutu")) 181 | 182 | --------------------------------- 183 | 184 | sendKeys("yazi") --> yazi eklemek 185 | getText() --> içerdiği yazıyı getirir. 186 | 187 | TestNG Dersleri - 4. Ders 188 | 189 | xpath : herhangi bir webelementi bulabilmemiz için kullanılan en yaygın locator. 190 | ***** bir array gibi kullanılabiliyor. 191 | ***** webelementin içerdiği yazıya göre element bulmaya yardımcı oluyor. 192 | 193 | 194 | cssSelector : bir webelementin class, id gibi css'te kullandığımız selectorler yardımıyla bir webelementi bulmamıza yardımcı oluyor. 195 | ***** Genellikle sadece class değerleri içerisinde arama gerçekleştireceksek kullanılıyor. 196 | 197 | 198 | 199 | Google 200 | 201 | 202 | 1 - ID Hayır 203 | 2 - Name Hayır 204 | 3 - ClassName Hayır 205 | 206 | 207 | 8 - CssSelector Evet 208 | .link.google 209 | 210 | 211 | 212 |
213 | 214 |
215 | 216 | tagName : div 217 | 218 | cssSelector("div") 219 | 220 | cssSelector(".w3-clear") 221 | 222 | cssSelector("div.w3-clear") 223 | 224 | cssSelector("#yazi") 225 | 226 | cssSelector("div#yazi.w3-clear") 227 | 228 | 229 | 231 | 232 | cssSelector("div") 233 | 234 | cssSelector(".baslik") 235 | 236 | cssSelector(".logo") 237 | 238 | cssSelector(".baslik.logo") 239 | 240 | cssSelector("div.baslik.logo") 241 | 242 | 243 |
244 | 245 | Selamlar 246 | 247 |
248 | 249 | cssSelector("span") 250 | 251 | cssSelector(".yazi") 252 | 253 | cssSelector("span.yazi") 254 | 255 | cssSelector(".icerik .yazi") 256 | 257 | cssSelector("div span") 258 | 259 | cssSelector("div.icerik span.yazi") 260 | 261 | xpath 262 | 263 | //tagName[@attribute="deger"] 264 | 265 | 266 | colorpicker 267 | 268 | 269 | tagName -> EVET 270 | id -> HAYIR 271 | name -> HAYIR 272 | className -> HAYIR 273 | linkText -> HAYIR 274 | partialLinkText -> HAYIR 275 | xpath -> EVET 276 | cssSelector -> EVET 277 | 278 | 279 | xpath özel durumlar 280 | 281 | //tagName[@attribute="deger"] 282 | 283 | //tagName[.="deger"] 284 | 285 | //tagName[@attribute1="deger1" or @attribute2="deger2"] 286 | 287 | //*[.="yazi"] 288 | 289 | //*[contains(text(),"Hamza")] 290 | 291 | 292 | 293 | Davranışsal Sorular 294 | Sorularla Java Tekrarı 295 | Selenium-Advance Selenium (JUnit, TestNG, Cucumber) 296 | ISTQB Hazırlık 297 | Scrum Guide 298 | 3 aşamalı Interview 299 | Sorularla API 300 | Sorularla SQL 301 | Sorularla JDBC + Jenkins + Selenium Grid 302 | Konu Anlatımı : Git-Github 303 | Konu Anlatımı : HTML / CSS 304 | İş Başvuru Takibi 305 | Birebir Takip 306 | Mentör Desteği - Süreç Takibi 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | // JavaScript Tarih(Date) kullanımı 316 | var Kisi = function(isim, tarih){ 317 | this.isim = isim; 318 | this.tarih = tarih; 319 | 320 | this.yas = function(){ 321 | var tarih = new Date(); 322 | var dogumTarihi = new Date(this.tarih); 323 | 324 | var fark = tarih.getFullYear() - dogumTarihi.getFullYear(); 325 | 326 | return fark; 327 | } 328 | 329 | this.oyKullanabilirMi = function(){ 330 | if(this.yas() > 18){ 331 | return true; 332 | } 333 | else{ 334 | return false; 335 | } 336 | } 337 | } 338 | 339 | 340 | var hamza = new Kisi("Hamza", "1990-11-15"); 341 | 342 | console.log(hamza.yas()); 343 | console.log(hamza.oyKullanabilirMi()); 344 | --------------------------------------------------------------------------------