3
3
import java .io .File ;
4
4
import java .io .FileReader ;
5
5
import java .util .Properties ;
6
+
7
+ import com .crossover .pages .GmailPage ;
8
+ import com .crossover .pages .LoginPage ;
6
9
import junit .framework .TestCase ;
7
10
import org .junit .Test ;
8
11
import org .openqa .selenium .*;
@@ -23,7 +26,7 @@ public void setUp() throws Exception {
23
26
System .setProperty ("webdriver.chrome.driver" ,properties .getProperty ("webdriver.chrome.driver" ) );
24
27
driver = new ChromeDriver ();
25
28
driver .manage ().window ().maximize ();
26
- wait = new WebDriverWait (driver ,20 );
29
+ wait = new WebDriverWait (driver ,Integer . parseInt ( properties . getProperty ( "timeout" )) );
27
30
}
28
31
29
32
public void tearDown () {
@@ -34,85 +37,13 @@ public void tearDown() {
34
37
public void testSendEmail () {
35
38
driver .get ("https://mail.google.com/" );
36
39
37
- //Enter User Name read from the properties file
38
- WebElement userElement = driver .findElement (By .id ("identifierId" ));
39
- String userName = properties .getProperty ("username" );
40
- userElement .sendKeys (userName );
41
-
42
- //Click next
43
- driver .findElement (By .id ("identifierNext" )).click ();
44
-
45
- //Enter Password read from the properties file
46
- By passwordElementIdentifier = By .name ("password" );
47
- wait .until (ExpectedConditions .presenceOfElementLocated (passwordElementIdentifier ));
48
- WebElement passwordElement = driver .findElement (passwordElementIdentifier );
49
- String passwordValue = properties .getProperty ("password" );
50
- passwordElement .sendKeys (passwordValue );
51
- wait .until (ExpectedConditions .presenceOfElementLocated (By .id ("passwordNext" )));
52
- driver .findElement (By .id ("passwordNext" )).click ();
53
-
54
- //Click Compose
55
- By composeElementIdentifier = By .xpath ("//*[@role='button' and (.)='Compose']" );
56
- wait .until (ExpectedConditions .presenceOfElementLocated (composeElementIdentifier ));
57
- driver .findElement (composeElementIdentifier ).click ();
58
-
59
- By toFieldIdentifier = By .name ("to" );
60
- wait .until (ExpectedConditions .presenceOfElementLocated (toFieldIdentifier ));
61
- WebElement txtBoxToField = driver .findElement (toFieldIdentifier );
62
- txtBoxToField .clear ();
63
- String toUserValue = properties .getProperty ("username" );
64
- txtBoxToField .sendKeys (String .format ("%s@gmail.com" ,toUserValue ));
65
-
66
- // emailSubject and emailbody to be used in this unit test.
67
- String emailSubject = properties .getProperty ("email.subject" );
68
- String emailBody = properties .getProperty ("email.body" );
69
-
70
- //Enter subject
71
- By subjectBoxIdentifier = By .name ("subjectbox" );
72
- wait .until (ExpectedConditions .presenceOfElementLocated (subjectBoxIdentifier ));
73
- WebElement subjectBox = driver .findElement (subjectBoxIdentifier );
74
- subjectBox .clear ();
75
- subjectBox .sendKeys (emailSubject );
76
-
77
- //Enter email body
78
- driver .findElement (By .xpath ("//div[@class='Am Al editable LW-avf']" )).clear ();
79
- driver .findElement (By .xpath ("//div[@class='Am Al editable LW-avf']" )).sendKeys (emailBody );
80
-
81
- //Click More settings
82
- wait .until (ExpectedConditions .presenceOfElementLocated (
83
- By .xpath ("//div[@class='J-JN-M-I J-J5-Ji Xv L3 T-I-ax7 T-I']/div[2]" ))).click ();
84
- wait .until (ExpectedConditions .presenceOfElementLocated (
85
- By .xpath ("//span[@class='J-Ph-hFsbo']" ))).click ();
40
+ LoginPage loginPage = new LoginPage (driver , wait , properties );
41
+ loginPage .login ();
86
42
87
- //Choose Social label
88
- wait .until (ExpectedConditions .presenceOfElementLocated (
89
- By .xpath ("//div[@class='J-LC-Jz' and text()='Social']/div[@class='J-LC-Jo J-J5-Ji']" ))).click ();
90
- wait .until (ExpectedConditions .presenceOfElementLocated (
91
- By .xpath ("//div[@class='J-JK-Jz' and text()='Apply']" ))).click ();
92
-
93
- //Click Send
94
- driver .findElement (By .xpath ("//*[@role='button' and text()='Send']" )).click ();
95
-
96
- //Click Social Tab
97
- wait .until (ExpectedConditions .presenceOfElementLocated (
98
- By .xpath ("//div[@class='aKz' and text()='Social']" ))).click ();
99
-
100
- //Thread.sleep(5000);
101
- wait .until (ExpectedConditions .presenceOfElementLocated (
102
- By .xpath ("//table[@class='F cf zt']/tbody/tr[1]/td[3]/span" )));
103
-
104
- try {
105
- driver .findElement (By .xpath ("//table[@class='F cf zt']/tbody/tr[1]/td[3]/span" )).click ();
106
- }catch (ElementNotVisibleException e ){
107
- driver .findElements (By .xpath ("//table[@class='F cf zt']/tbody/tr[1]/td[3]/span" )).get (1 ).click ();
108
- }
109
-
110
- //Open the received email
111
- try {
112
- driver .findElement (By .xpath ("//table[@class='F cf zt']/tbody/tr[1]" )).click ();
113
- }catch (ElementNotVisibleException e ){
114
- driver .findElements (By .xpath ("//table[@class='F cf zt']/tbody/tr[1]" )).get (1 ).click ();
115
- }
43
+ GmailPage gmailPage = new GmailPage (driver ,wait ,properties );
44
+ gmailPage .composeEmail ();
45
+ gmailPage .clickSocialTab ();
46
+ gmailPage .openReceivedEmail ();
116
47
117
48
//Verify email came under proper Label i.e. "Social"
118
49
try {
@@ -128,10 +59,13 @@ public void testSendEmail() {
128
59
//Verify the subject and body of the received email
129
60
String subjectOfReceivedEmail = wait .until (ExpectedConditions .presenceOfElementLocated (
130
61
By .xpath ("//h2[@class='hP']" ))).getText ();
62
+
63
+ String emailSubject = properties .getProperty ("email.subject" );
131
64
assertEquals (emailSubject , subjectOfReceivedEmail );
132
65
133
66
String bodyOfReceivedEmail = wait .until (ExpectedConditions .presenceOfElementLocated (
134
67
By .xpath ("//div[@class='a3s aXjCH ']" ))).getText ();
68
+ String emailBody = properties .getProperty ("email.body" );
135
69
assertEquals (emailBody , bodyOfReceivedEmail );
136
70
}
137
71
}
0 commit comments