File tree 9 files changed +115
-10
lines changed
9 files changed +115
-10
lines changed Original file line number Diff line number Diff line change 3
3
<modelVersion >4.0.0</modelVersion >
4
4
5
5
<groupId >qa.example.java</groupId >
6
- <artifactId >bbc-tests </artifactId >
6
+ <artifactId >test-automation-java </artifactId >
7
7
<version >1.0-SNAPSHOT</version >
8
8
<build >
9
9
<plugins >
20
20
</build >
21
21
<packaging >jar</packaging >
22
22
23
- <name >bbc -tests</name >
23
+ <name >test-automation -tests</name >
24
24
<url >http://maven.apache.org</url >
25
25
26
26
<properties >
Original file line number Diff line number Diff line change 13
13
</groups >
14
14
15
15
<classes >
16
- <!-- < class name="tests.BookingFlowTests"/> -- >
16
+ <class name =" tests.HomePageTests " / >
17
17
</classes >
18
18
</test >
19
19
26
26
</groups >
27
27
28
28
<classes >
29
- <!-- <class name="tests.BookingFlowTests " /> -->
29
+ <!-- <class name="tests.HomePageTests " />-->
30
30
</classes >
31
31
</test >
32
32
39
39
</groups >
40
40
41
41
<classes >
42
- <!-- <class name="tests.BookingFlowTests " /> -->
42
+ <!-- <class name="tests.HomePageTests " />-->
43
43
</classes >
44
44
</test > <!-- Test -->
45
45
64
64
</groups >
65
65
66
66
<classes >
67
+ <!-- <class name="tests.HomePageTests" />-->
67
68
</classes >
68
69
</test >
69
70
Original file line number Diff line number Diff line change 7
7
import org .openqa .selenium .firefox .FirefoxProfile ;
8
8
import org .openqa .selenium .remote .DesiredCapabilities ;
9
9
import org .openqa .selenium .remote .RemoteWebDriver ;
10
- import org .testng .Reporter ;
11
10
import pages .HomePage ;
12
11
13
12
import java .net .MalformedURLException ;
20
19
public class Browser {
21
20
22
21
23
- public Browser (String browserName , String port , String baseUrl ) {
24
- Reporter .log ("Create new instance of the browser" , true );
22
+ public Browser (String browserName , String baseUrl ) {
25
23
setBrowser (browserName );
26
24
setBaseUrl (baseUrl );
27
25
Initialise (getBrowser ());
28
26
}
29
27
30
28
private void Initialise (String browser ) {
31
29
capabilities = new DesiredCapabilities ();
32
- seleniumFolderPath = System .getProperty ("user.home" ) + "/Documents/services /selenium3/" ;
30
+ seleniumFolderPath = System .getProperty ("user.home" ) + "/Documents/umservices /selenium3/" ;
33
31
34
32
switch (browser ) {
35
33
case "Chrome" :
@@ -77,7 +75,6 @@ private void Initialise(String browser) {
77
75
}
78
76
79
77
try {
80
- Reporter .log ("Create new instance of remote web driver" , true );
81
78
_driver = new RemoteWebDriver (new URL ("http://0.0.0.0:4444/wd/hub" ), capabilities );
82
79
} catch (MalformedURLException e ) {
83
80
e .printStackTrace ();
Original file line number Diff line number Diff line change @@ -11,4 +11,5 @@ public class HomePage extends Page {
11
11
public HomePage (Browser browser ) {
12
12
super (browser );
13
13
}
14
+
14
15
}
Original file line number Diff line number Diff line change 1
1
package pages .shared ;
2
2
3
3
import helper .Browser ;
4
+ import org .openqa .selenium .JavascriptExecutor ;
5
+ import org .openqa .selenium .WebDriver ;
6
+ import org .openqa .selenium .WebElement ;
7
+ import org .openqa .selenium .support .PageFactory ;
8
+ import org .openqa .selenium .support .ui .WebDriverWait ;
4
9
5
10
/**
6
11
* Created by opantsjoha on 02/07/2017.
7
12
*/
8
13
public class Element {
14
+
9
15
public Element (Browser browser ) {
16
+ this .browser = browser ;
17
+ driver = browser ._driver ;
18
+ PageFactory .initElements (driver , this );
19
+ }
10
20
21
+ // Draws a red border around the found element. Does not set it back anyhow.
22
+ public WebElement highlightElement (WebElement elem ) {
23
+ // draw a border around the found element
24
+ if (driver instanceof JavascriptExecutor ) {
25
+ ((JavascriptExecutor ) driver ).executeScript ("arguments[0].style.border='3px solid red'" , elem );
26
+ }
27
+ return elem ;
11
28
}
29
+
30
+ protected WebDriver driver ;
31
+ protected WebDriverWait wait ;
32
+ protected Browser browser ;
33
+ protected static int DURATION = 5000 ;
12
34
}
Original file line number Diff line number Diff line change
1
+ package pages .shared ;
2
+
3
+ import helper .Browser ;
4
+ import org .openqa .selenium .WebElement ;
5
+ import org .openqa .selenium .support .FindBy ;
6
+
7
+ /**
8
+ * Created by opantsjoha on 02/07/2017.
9
+ */
10
+ public class HeaderSection extends Element {
11
+
12
+ public HeaderSection (Browser browser ) {
13
+ super (browser );
14
+ }
15
+
16
+ @ FindBy (id = "orb-search-q" )
17
+ private WebElement searchField ;
18
+
19
+ // This search button is actually useless - as it just opens another search box
20
+ @ FindBy (id = "orb-search-button" )
21
+ private WebElement searchButton ;
22
+
23
+ @ FindBy (className = "se-searchbox__submit" )
24
+ private WebElement searchSubmitButton ;
25
+
26
+ public void setSearchField (String value ) {
27
+ searchField .sendKeys (value );
28
+ }
29
+
30
+ public void clickOnSearchButton () {
31
+ // this element only appears when something is input into search field.
32
+ searchSubmitButton .click ();
33
+ }
34
+
35
+ }
Original file line number Diff line number Diff line change @@ -9,4 +9,14 @@ public class Page extends Element {
9
9
public Page (Browser browser ) {
10
10
super (browser );
11
11
}
12
+
13
+ // Create HeaderSection object when called.
14
+ public HeaderSection HeaderSection (){
15
+ if (headerSection == null ){
16
+ headerSection = new HeaderSection (browser );
17
+ }
18
+ return headerSection ;
19
+ }
20
+
21
+ private HeaderSection headerSection ;
12
22
}
Original file line number Diff line number Diff line change
1
+ package helper ;
2
+
3
+ /**
4
+ * Created by opantsjoha on 02/07/2017.
5
+ */
6
+ public class TestHelper {
7
+ }
Original file line number Diff line number Diff line change
1
+ package tests ;
2
+
3
+ import helper .Browser ;
4
+ import helper .TestHelper ;
5
+ import org .testng .annotations .*;
6
+
7
+ /**
8
+ * Created by opantsjoha on 02/07/2017.
9
+ */
10
+ public class HomePageTests extends TestHelper {
11
+
12
+ Browser browser ;
13
+
14
+ @ Parameters ({"browserName" , "baseUrl" })
15
+ @ BeforeClass (groups = {"web" })
16
+ public void setUp (String browserName , String baseUrl ) {
17
+ browser = new Browser (browserName , baseUrl );
18
+ browser .navigateToBaseUrl ();
19
+ }
20
+
21
+ @ Test (groups = {"web" })
22
+ public void searchTest () throws InterruptedException {
23
+ browser .HomePage ().HeaderSection ().setSearchField ("Cooking" );
24
+ browser .HomePage ().HeaderSection ().clickOnSearchButton ();
25
+ }
26
+
27
+ @ AfterClass (groups = {"web" })
28
+ public void tearDown () {
29
+ browser ._driver .quit ();
30
+ }
31
+
32
+ }
You can’t perform that action at this time.
0 commit comments