├── .idea ├── .gitignore ├── compiler.xml ├── inspectionProfiles │ └── Project_Default.xml ├── jarRepositories.xml ├── misc.xml ├── uiDesigner.xml └── vcs.xml ├── README.md ├── Wiki.md ├── pom.xml ├── src ├── main │ └── java │ │ └── com │ │ └── maksu │ │ ├── BasePage.java │ │ ├── GenderSection.java │ │ ├── PracticeFormPage.java │ │ └── SamplePage.java └── test │ ├── java │ └── com │ │ └── maksu │ │ ├── BaseTest.java │ │ ├── Test_Gender_Selection.java │ │ └── Test_Setting_Name_Lastname_Email.java │ └── resources │ └── junit-platform.properties └── target ├── classes ├── BasePage.class ├── GenderSection$1.class ├── GenderSection$Genders.class ├── GenderSection.class ├── PracticeFormPage.class ├── SamplePage.class └── junit-platform.properties ├── maven-status └── maven-compiler-plugin │ ├── compile │ └── default-compile │ │ ├── createdFiles.lst │ │ └── inputFiles.lst │ └── testCompile │ └── default-testCompile │ ├── createdFiles.lst │ └── inputFiles.lst ├── surefire-reports ├── TEST-Test_Gender_Selection.xml ├── TEST-Test_Setting_Name_Lastname_Email.xml ├── Test_Gender_Selection.txt └── Test_Setting_Name_Lastname_Email.txt └── test-classes ├── BaseTest.class ├── Test_Gender_Selection.class └── Test_Setting_Name_Lastname_Email.class /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # YouTube Selenium Lessons 2 | 3 | * Channel link : https://www.youtube.com/channel/UClFClVa2qjJK-mBbTw3RAxA -------------------------------------------------------------------------------- /Wiki.md: -------------------------------------------------------------------------------- 1 | 2 | ## Karşılaşılan hatalar ve çözümleri 3 | 4 | * Test class'ı içerisinde tanımlanan page objesi(driver) npe fırlattı. Bunun nedeni aldığı "driver" 5 | parametresinin BaseTest class'ından daha setUp() methodu içerisinde oluşturulmadığından dolayı idi. 6 | Çözüm olarak setUp() methodu içerisinde page(driver) setleyerek bu çözülmüş oldu. 7 | 8 | * input tagine sahip elemenler için getText() methodunu kullanamıyoruz. Bunun yerine getAttribute("value") 9 | methodunu kullanabiliriz. Burada "value" ile bir attribute yoksa bile doğru şekilde text'i alabiliyoruz. 10 | 11 | 12 | Problem : mvn-clean-test diyerek testleri koşamıyorduk. 13 | Solution: junit-jupiter-engine kütüphanesini ekleyince sorun çözüldü. -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | org.example 7 | demoqa-automation-project 8 | 1.0-SNAPSHOT 9 | 10 | 11 | 8 12 | 8 13 | 3.141.59 14 | 5.7.0 15 | 16 | 17 | 18 | 19 | org.seleniumhq.selenium 20 | selenium-java 21 | ${selenium.version} 22 | 23 | 24 | org.seleniumhq.selenium 25 | selenium-chrome-driver 26 | ${selenium.version} 27 | 28 | 29 | org.junit.jupiter 30 | junit-jupiter-engine 31 | ${junit.jupiter.version} 32 | test 33 | 34 | 35 | io.github.bonigarcia 36 | webdrivermanager 37 | 4.4.3 38 | test 39 | 40 | 41 | 42 | 43 | 44 | 45 | org.apache.maven.plugins 46 | maven-surefire-plugin 47 | 2.22.0 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/main/java/com/maksu/BasePage.java: -------------------------------------------------------------------------------- 1 | import org.openqa.selenium.By; 2 | import org.openqa.selenium.WebDriver; 3 | import org.openqa.selenium.WebElement; 4 | 5 | public class BasePage { 6 | 7 | protected WebDriver driver ; 8 | String baseUrl = "https://demoqa.com/"; 9 | 10 | public BasePage(WebDriver driver){ 11 | this.driver = driver ; 12 | } 13 | 14 | public WebElement find(By locator){ 15 | return driver.findElement(locator); 16 | } 17 | 18 | public void click(By locator){ 19 | find(locator).click(); 20 | } 21 | 22 | public void type(By locator , String text){ 23 | find(locator).sendKeys(text); 24 | } 25 | 26 | public Boolean isSelected(By locator){ 27 | return find(locator).isSelected(); 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/maksu/GenderSection.java: -------------------------------------------------------------------------------- 1 | import org.openqa.selenium.By; 2 | import org.openqa.selenium.WebDriver; 3 | 4 | public class GenderSection extends BasePage { 5 | 6 | private final By maleLabelLocator = new By.ByCssSelector("label[for='gender-radio-1']"); 7 | private final By femaleLabelLocator =new By.ByCssSelector("label[for='gender-radio-2']"); 8 | private final By otherLabelLocator = new By.ByCssSelector("label[for='gender-radio-3']"); 9 | 10 | private final By maleRadiotButtonLocator = By.id("gender-radio-1"); 11 | private final By femaleRadiotButtonLocator = By.id("gender-radio-2"); 12 | private final By otherRadioButtonLocator = By.id("gender-radio-3"); 13 | 14 | public enum Genders {MALE , FEMALE , OTHER} 15 | 16 | public GenderSection(WebDriver driver){ 17 | super(driver); 18 | } 19 | 20 | public void clickRadioButton(Genders gender){ 21 | switch (gender) { 22 | case FEMALE: 23 | click(femaleLabelLocator); 24 | break; 25 | case MALE : 26 | click(maleLabelLocator); 27 | break; 28 | case OTHER : 29 | click(otherLabelLocator); 30 | break; 31 | } 32 | } 33 | 34 | public boolean isRadioButtonChecked(Genders gender){ 35 | boolean isChecked = false ; 36 | switch (gender){ 37 | case FEMALE: 38 | isChecked = isSelected(femaleRadiotButtonLocator); 39 | break; 40 | case MALE: 41 | isChecked = isSelected(maleRadiotButtonLocator); 42 | break; 43 | case OTHER: 44 | isChecked = isSelected(otherRadioButtonLocator); 45 | break; 46 | } 47 | return isChecked ; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/maksu/PracticeFormPage.java: -------------------------------------------------------------------------------- 1 | import org.openqa.selenium.By; 2 | import org.openqa.selenium.WebDriver; 3 | 4 | public class PracticeFormPage extends BasePage { 5 | 6 | private final By nameLocator = By.id("firstName"); 7 | private final By lastNameLocator = By.id("lastName"); 8 | private final By emailLocator = By.id("userEmail"); 9 | 10 | private GenderSection genderSection; 11 | 12 | public PracticeFormPage(WebDriver driver){ 13 | super(driver); 14 | driver.get(baseUrl.concat("automation-practice-form")); 15 | genderSection = new GenderSection(driver); 16 | } 17 | 18 | public GenderSection genderSection(){ 19 | return this.genderSection; 20 | } 21 | 22 | public void setName(String name){ 23 | type(nameLocator , name); 24 | } 25 | 26 | public void setLastName(String lastName){ 27 | type(lastNameLocator , lastName); 28 | } 29 | 30 | public void setEmail(String email){ 31 | type(emailLocator , email); 32 | } 33 | 34 | public String getName(){ 35 | return find(nameLocator).getAttribute("value"); 36 | } 37 | 38 | public String getLastname(){ 39 | return find(lastNameLocator).getAttribute("value"); 40 | } 41 | 42 | public String getEmail(){ 43 | return find(emailLocator).getAttribute("value"); 44 | } 45 | 46 | 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/maksu/SamplePage.java: -------------------------------------------------------------------------------- 1 | import org.openqa.selenium.WebDriver; 2 | 3 | public class SamplePage extends BasePage{ 4 | 5 | 6 | public SamplePage(WebDriver driver) { 7 | super(driver); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/test/java/com/maksu/BaseTest.java: -------------------------------------------------------------------------------- 1 | import io.github.bonigarcia.wdm.WebDriverManager; 2 | import org.junit.jupiter.api.*; 3 | import org.openqa.selenium.WebDriver; 4 | import org.openqa.selenium.chrome.ChromeDriver; 5 | import org.openqa.selenium.firefox.FirefoxDriver; 6 | 7 | @TestInstance(TestInstance.Lifecycle.PER_METHOD) 8 | public class BaseTest { 9 | 10 | WebDriver driver ; 11 | static String browser = System.getProperty("browser"); 12 | 13 | @BeforeAll 14 | public static void setUp(){ 15 | if (browser.equals("firefox")){ 16 | WebDriverManager.firefoxdriver().setup(); 17 | }else if(browser.equals("chrome")){ 18 | WebDriverManager.chromedriver().setup(); 19 | } 20 | System.out.println("Test initiated."); 21 | } 22 | 23 | @BeforeEach 24 | public void beforeMethod(){ 25 | driver = getDriver(browser); 26 | } 27 | 28 | @AfterEach 29 | public void afterMethod(){ 30 | driver.quit(); 31 | } 32 | 33 | @AfterAll 34 | public static void tearDown(){ 35 | System.out.println("Test finished."); 36 | } 37 | 38 | private WebDriver getDriver(String browser){ 39 | WebDriver driver = null ; 40 | if (browser.equals("firefox")){ 41 | driver = new FirefoxDriver(); 42 | }else if(browser.equals("chrome")){ 43 | driver = new ChromeDriver(); 44 | } 45 | return driver ; 46 | } 47 | 48 | 49 | 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/maksu/Test_Gender_Selection.java: -------------------------------------------------------------------------------- 1 | import org.junit.jupiter.api.Assertions; 2 | import org.junit.jupiter.api.Test; 3 | 4 | public class Test_Gender_Selection extends BaseTest{ 5 | 6 | @Test 7 | public void check_male_radio_button(){ 8 | PracticeFormPage practiceFormPage = new PracticeFormPage(driver); 9 | practiceFormPage.genderSection().clickRadioButton(GenderSection.Genders.MALE); 10 | Assertions.assertTrue(practiceFormPage.genderSection().isRadioButtonChecked(GenderSection.Genders.MALE), 11 | "Male radio button is not checked!"); 12 | } 13 | 14 | @Test 15 | public void check_female_radio_button(){ 16 | PracticeFormPage practiceFormPage = new PracticeFormPage(driver); 17 | practiceFormPage.genderSection().clickRadioButton(GenderSection.Genders.FEMALE); 18 | Assertions.assertTrue(practiceFormPage.genderSection().isRadioButtonChecked(GenderSection.Genders.FEMALE), 19 | "Female radio button is not checked!"); 20 | } 21 | 22 | @Test 23 | public void check_other_radio_button(){ 24 | PracticeFormPage practiceFormPage = new PracticeFormPage(driver); 25 | practiceFormPage.genderSection().clickRadioButton(GenderSection.Genders.OTHER); 26 | Assertions.assertTrue(practiceFormPage.genderSection().isRadioButtonChecked(GenderSection.Genders.OTHER), 27 | "Other radio button is not checked!"); 28 | } 29 | 30 | public static void main(String[] args) { 31 | System.out.printf("Mustafa"); 32 | } 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/maksu/Test_Setting_Name_Lastname_Email.java: -------------------------------------------------------------------------------- 1 | import org.junit.jupiter.api.Assertions; 2 | import org.junit.jupiter.api.Test; 3 | 4 | public class Test_Setting_Name_Lastname_Email extends BaseTest{ 5 | 6 | 7 | @Test 8 | public void setName() { 9 | PracticeFormPage practiceFormPage = new PracticeFormPage(driver); 10 | practiceFormPage.setName("Mustafa"); 11 | Assertions.assertEquals("Mustafa",practiceFormPage.getName() , "Name value is not correct!"); 12 | } 13 | 14 | @Test 15 | public void setLastName(){ 16 | PracticeFormPage practiceFormPage = new PracticeFormPage(driver); 17 | practiceFormPage.setLastName("Aksu"); 18 | Assertions.assertEquals("Aksu",practiceFormPage.getLastname(), "Last name value is not correct!"); 19 | } 20 | 21 | @Test 22 | public void setEmail(){ 23 | PracticeFormPage practiceFormPage = new PracticeFormPage(driver); 24 | practiceFormPage.setEmail("mustafa123@gmail.com"); 25 | Assertions.assertEquals("mustafa123@gmail.com",practiceFormPage.getEmail(), "Last name value is not correct!"); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/test/resources/junit-platform.properties: -------------------------------------------------------------------------------- 1 | junit.jupiter.execution.parallel.enabled = true 2 | junit.jupiter.execution.parallel.mode.default = same_thread 3 | #junit.jupiter.execution.parallel.mode.classes.default = same_thread -------------------------------------------------------------------------------- /target/classes/BasePage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaksuCode/youtube-selenium-lessons/a64ae8fb91cc23789a47e9bfb58b2f0801f1b154/target/classes/BasePage.class -------------------------------------------------------------------------------- /target/classes/GenderSection$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaksuCode/youtube-selenium-lessons/a64ae8fb91cc23789a47e9bfb58b2f0801f1b154/target/classes/GenderSection$1.class -------------------------------------------------------------------------------- /target/classes/GenderSection$Genders.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaksuCode/youtube-selenium-lessons/a64ae8fb91cc23789a47e9bfb58b2f0801f1b154/target/classes/GenderSection$Genders.class -------------------------------------------------------------------------------- /target/classes/GenderSection.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaksuCode/youtube-selenium-lessons/a64ae8fb91cc23789a47e9bfb58b2f0801f1b154/target/classes/GenderSection.class -------------------------------------------------------------------------------- /target/classes/PracticeFormPage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaksuCode/youtube-selenium-lessons/a64ae8fb91cc23789a47e9bfb58b2f0801f1b154/target/classes/PracticeFormPage.class -------------------------------------------------------------------------------- /target/classes/SamplePage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaksuCode/youtube-selenium-lessons/a64ae8fb91cc23789a47e9bfb58b2f0801f1b154/target/classes/SamplePage.class -------------------------------------------------------------------------------- /target/classes/junit-platform.properties: -------------------------------------------------------------------------------- 1 | junit.jupiter.execution.parallel.enabled = true 2 | junit.jupiter.execution.parallel.mode.default = concurrent 3 | #junit.jupiter.execution.parallel.mode.classes.default = same_thread -------------------------------------------------------------------------------- /target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst: -------------------------------------------------------------------------------- 1 | SamplePage.class 2 | BasePage.class 3 | GenderSection.class 4 | GenderSection$1.class 5 | PracticeFormPage.class 6 | GenderSection$Genders.class 7 | -------------------------------------------------------------------------------- /target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | /Users/mustafaaksu/Desktop/youtube-selenium-lessons/src/main/java/PracticeFormPage.java 2 | /Users/mustafaaksu/Desktop/youtube-selenium-lessons/src/main/java/GenderSection.java 3 | /Users/mustafaaksu/Desktop/youtube-selenium-lessons/src/main/java/SamplePage.java 4 | /Users/mustafaaksu/Desktop/youtube-selenium-lessons/src/main/java/BasePage.java 5 | -------------------------------------------------------------------------------- /target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst: -------------------------------------------------------------------------------- 1 | Test_Setting_Name_Lastname_Email.class 2 | Test_Gender_Selection.class 3 | BaseTest.class 4 | -------------------------------------------------------------------------------- /target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | /Users/mustafaaksu/Desktop/youtube-selenium-lessons/src/test/java/Test_Gender_Selection.java 2 | /Users/mustafaaksu/Desktop/youtube-selenium-lessons/src/test/java/BaseTest.java 3 | /Users/mustafaaksu/Desktop/youtube-selenium-lessons/src/test/java/Test_Setting_Name_Lastname_Email.java 4 | -------------------------------------------------------------------------------- /target/surefire-reports/TEST-Test_Gender_Selection.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /target/surefire-reports/TEST-Test_Setting_Name_Lastname_Email.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /target/surefire-reports/Test_Gender_Selection.txt: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | Test set: Test_Gender_Selection 3 | ------------------------------------------------------------------------------- 4 | Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 20.234 s - in Test_Gender_Selection 5 | -------------------------------------------------------------------------------- /target/surefire-reports/Test_Setting_Name_Lastname_Email.txt: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------- 2 | Test set: Test_Setting_Name_Lastname_Email 3 | ------------------------------------------------------------------------------- 4 | Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 19.915 s - in Test_Setting_Name_Lastname_Email 5 | -------------------------------------------------------------------------------- /target/test-classes/BaseTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaksuCode/youtube-selenium-lessons/a64ae8fb91cc23789a47e9bfb58b2f0801f1b154/target/test-classes/BaseTest.class -------------------------------------------------------------------------------- /target/test-classes/Test_Gender_Selection.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaksuCode/youtube-selenium-lessons/a64ae8fb91cc23789a47e9bfb58b2f0801f1b154/target/test-classes/Test_Gender_Selection.class -------------------------------------------------------------------------------- /target/test-classes/Test_Setting_Name_Lastname_Email.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaksuCode/youtube-selenium-lessons/a64ae8fb91cc23789a47e9bfb58b2f0801f1b154/target/test-classes/Test_Setting_Name_Lastname_Email.class --------------------------------------------------------------------------------