Merge branch 'Sandeep4odesk-master'
This commit is contained in:
		
						commit
						ab5af65705
					
				| @ -20,14 +20,35 @@ | ||||
|                 <artifactId>maven-surefire-plugin</artifactId> | ||||
|                 <version>2.19.1</version> | ||||
|                 <configuration> | ||||
|                     <testSourceDirectory></testSourceDirectory> | ||||
|                     <testFailureIgnore>true</testFailureIgnore> | ||||
|                     <includes> | ||||
|                         <include>Test*.java</include> | ||||
|                         <include>**/*UnitTest.java</include> | ||||
|                     </includes> | ||||
|                     <systemPropertyVariables></systemPropertyVariables> | ||||
|                 </configuration> | ||||
|             </plugin> | ||||
|         </plugins> | ||||
|     </build> | ||||
|     <profiles> | ||||
|         <profile> | ||||
|             <id>live</id> | ||||
|             <build> | ||||
|                 <plugins> | ||||
|                     <plugin> | ||||
|                         <groupId>org.apache.maven.plugins</groupId> | ||||
|                         <artifactId>maven-surefire-plugin</artifactId> | ||||
|                         <version>2.19.1</version> | ||||
|                         <configuration> | ||||
|                             <includes> | ||||
|                                 <include>**/*LiveTest.java</include> | ||||
|                             </includes> | ||||
|                         </configuration> | ||||
|                     </plugin> | ||||
|                 </plugins> | ||||
|             </build> | ||||
|         </profile> | ||||
|     </profiles> | ||||
| 
 | ||||
|     <dependencies> | ||||
|         <dependency> | ||||
|             <groupId>org.seleniumhq.selenium</groupId> | ||||
| @ -37,12 +58,12 @@ | ||||
|         <dependency> | ||||
|             <groupId>junit</groupId> | ||||
|             <artifactId>junit</artifactId> | ||||
|             <version>4.8.1</version> | ||||
|             <version>4.12</version> | ||||
|         </dependency> | ||||
|         <dependency> | ||||
|             <groupId>org.testng</groupId> | ||||
|             <artifactId>testng</artifactId> | ||||
|             <version>6.9.10</version> | ||||
|             <version>6.9.13.6</version> | ||||
|         </dependency> | ||||
|     </dependencies> | ||||
| </project> | ||||
| @ -1,15 +1,22 @@ | ||||
| package main.java.com.baeldung.selenium; | ||||
| 
 | ||||
| import java.util.List; | ||||
| import java.util.concurrent.TimeUnit; | ||||
| 
 | ||||
| import org.openqa.selenium.By; | ||||
| import org.openqa.selenium.WebDriver; | ||||
| import org.openqa.selenium.WebElement; | ||||
| import org.openqa.selenium.firefox.FirefoxDriver; | ||||
| 
 | ||||
| public class SeleniumExample { | ||||
| 
 | ||||
|     private WebDriver webDriver; | ||||
|     private String url = "http://www.baeldung.com/"; | ||||
|      | ||||
| 
 | ||||
|     public SeleniumExample() { | ||||
|         webDriver = new FirefoxDriver(); | ||||
|         webDriver.manage().window().maximize(); | ||||
|         webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); | ||||
|         webDriver.get(url); | ||||
|     } | ||||
| 
 | ||||
| @ -21,4 +28,30 @@ public class SeleniumExample { | ||||
|         return webDriver.getTitle(); | ||||
|     } | ||||
| 
 | ||||
|     public void getAboutBaeldungPage() { | ||||
|         closeOverlay(); | ||||
|         clickAboutLink(); | ||||
|         clickAboutUsLink(); | ||||
|     } | ||||
| 
 | ||||
|     private void closeOverlay() { | ||||
|         List<WebElement> webElementList = webDriver.findElements(By.tagName("a")); | ||||
|         if (webElementList != null && !webElementList.isEmpty()) { | ||||
|             webElementList.stream().filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title"))).findAny().get().click(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private void clickAboutLink() { | ||||
|         webDriver.findElement(By.partialLinkText("About")).click(); | ||||
|     } | ||||
| 
 | ||||
|     private void clickAboutUsLink() { | ||||
|         webDriver.findElement(By.partialLinkText("About Baeldung.")).click(); | ||||
|     } | ||||
| 
 | ||||
|     public boolean isAuthorInformationAvailable() { | ||||
|         return webDriver | ||||
|                 .findElement(By.xpath("//*[contains(text(), 'Eugen – an engineer')]")) | ||||
|                 .isDisplayed(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -0,0 +1,41 @@ | ||||
| package test.java.com.baeldung.selenium.junit; | ||||
| 
 | ||||
| import static org.testng.Assert.assertEquals; | ||||
| import static org.testng.Assert.assertNotNull; | ||||
| import static org.testng.Assert.assertTrue; | ||||
| import main.java.com.baeldung.selenium.SeleniumExample; | ||||
| 
 | ||||
| import org.junit.AfterClass; | ||||
| import org.junit.BeforeClass; | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| public class SeleniumWithJUnitLiveTest { | ||||
| 
 | ||||
|     private static SeleniumExample seleniumExample; | ||||
|     private String expecteTilteAboutBaeldungPage = "About Baeldung | Baeldung"; | ||||
| 
 | ||||
|     @BeforeClass | ||||
|     public static void setUp() { | ||||
|         seleniumExample = new SeleniumExample(); | ||||
|     } | ||||
| 
 | ||||
|     @AfterClass | ||||
|     public static void tearDown() { | ||||
|         seleniumExample.closeWindow(); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void whenAboutBaeldungIsLoaded_thenAboutEugenIsMentionedOnPage() { | ||||
|         try { | ||||
|             seleniumExample.getAboutBaeldungPage(); | ||||
|             String actualTitle = seleniumExample.getTitle(); | ||||
|             assertNotNull(actualTitle); | ||||
|             assertEquals(actualTitle, expecteTilteAboutBaeldungPage); | ||||
|             assertTrue(seleniumExample.isAuthorInformationAvailable()); | ||||
|         } catch (Exception exception) { | ||||
|             exception.printStackTrace(); | ||||
|             seleniumExample.closeWindow(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -1,32 +0,0 @@ | ||||
| package test.java.com.baeldung.selenium.junit; | ||||
| 
 | ||||
| import static org.testng.Assert.assertEquals; | ||||
| import static org.testng.Assert.assertNotNull; | ||||
| import main.java.com.baeldung.selenium.SeleniumExample; | ||||
| 
 | ||||
| import org.junit.After; | ||||
| import org.junit.Before; | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| public class TestSeleniumWithJUnit { | ||||
| 
 | ||||
|     private SeleniumExample seleniumExample; | ||||
| 	private String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials"; | ||||
| 
 | ||||
|     @Before | ||||
|     public void setUp() { | ||||
|         seleniumExample = new SeleniumExample(); | ||||
|     } | ||||
| 
 | ||||
|     @After | ||||
|     public void tearDown() { | ||||
|         seleniumExample.closeWindow(); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void whenPageIsLoaded_thenTitleIsAsPerExpectation() { | ||||
|         String actualTitle = seleniumExample.getTitle(); | ||||
|         assertNotNull(actualTitle); | ||||
|         assertEquals(actualTitle, expectedTitle); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,40 @@ | ||||
| package test.java.com.baeldung.selenium.testng; | ||||
| 
 | ||||
| import static org.testng.Assert.assertEquals; | ||||
| import static org.testng.Assert.assertNotNull; | ||||
| import static org.testng.Assert.assertTrue; | ||||
| import main.java.com.baeldung.selenium.SeleniumExample; | ||||
| 
 | ||||
| import org.testng.annotations.AfterSuite; | ||||
| import org.testng.annotations.BeforeSuite; | ||||
| import org.testng.annotations.Test; | ||||
| 
 | ||||
| public class SeleniumWithTestNGLiveTest { | ||||
| 
 | ||||
|     private SeleniumExample seleniumExample; | ||||
|     private String expecteTilteAboutBaeldungPage = "About Baeldung | Baeldung"; | ||||
| 
 | ||||
|     @BeforeSuite | ||||
|     public void setUp() { | ||||
|         seleniumExample = new SeleniumExample(); | ||||
|     } | ||||
| 
 | ||||
|     @AfterSuite | ||||
|     public void tearDown() { | ||||
|         seleniumExample.closeWindow(); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void whenAboutBaeldungIsLoaded_thenAboutEugenIsMentionedOnPage() { | ||||
|         try { | ||||
|             seleniumExample.getAboutBaeldungPage(); | ||||
|             String actualTitle = seleniumExample.getTitle(); | ||||
|             assertNotNull(actualTitle); | ||||
|             assertEquals(actualTitle, expecteTilteAboutBaeldungPage); | ||||
|             assertTrue(seleniumExample.isAuthorInformationAvailable()); | ||||
|         } catch (Exception exception) { | ||||
|             exception.printStackTrace(); | ||||
|             seleniumExample.closeWindow(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -1,32 +0,0 @@ | ||||
| package test.java.com.baeldung.selenium.testng; | ||||
| 
 | ||||
| import static org.testng.Assert.assertEquals; | ||||
| import static org.testng.Assert.assertNotNull; | ||||
| import main.java.com.baeldung.selenium.SeleniumExample; | ||||
| 
 | ||||
| import org.testng.annotations.AfterSuite; | ||||
| import org.testng.annotations.BeforeSuite; | ||||
| import org.testng.annotations.Test; | ||||
| 
 | ||||
| public class TestSeleniumWithTestNG { | ||||
| 
 | ||||
|     private SeleniumExample seleniumExample; | ||||
|     private String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials"; | ||||
| 
 | ||||
|     @BeforeSuite | ||||
|     public void setUp() { | ||||
|         seleniumExample = new SeleniumExample(); | ||||
|     } | ||||
| 
 | ||||
|     @AfterSuite | ||||
|     public void tearDown() { | ||||
|         seleniumExample.closeWindow(); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void whenPageIsLoaded_thenTitleIsAsPerExpectation() { | ||||
|         String actualTitle = seleniumExample.getTitle(); | ||||
|         assertNotNull(actualTitle); | ||||
|         assertEquals(actualTitle, expectedTitle); | ||||
|     } | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user