Send mail through Mail.ru
Task:
Using С# and web driver create a program that implements the following functionality:
- Connects to web driver,
- Opens mail service web-interface,
- Performs login to the email account using predefined user credentials,
- On behalf of the user whose credentials were used to login into email account sends an email to the same destination user and verify delivery of the message,
- All actions and results should be logged to the .txt file in a human-readable format.
Requirements:
- All configuration data such as for example web driver parameters, mail service web- interface address, user credentials etc., should be stored in *.xml configuration file,
- The program should support the following browsers: FireFox, Google Chrome, Interтet Explorer 9, 10 or 11, Safari.
- You should implement a class inherited from web driver and overload all methods required to complete the task.
- Name of the browser that is supposed to be used in the test should be taken from *.xml configuration file mentioned above,
- Code implementing the test behavior should be browser independent – probably an intermediate class is required to implement,
- Operations like browser start, mail service page opening, mail sending etc. should be implemented as different class methods,
- Please provide optional logging of the result to the text file (it should be possible to disable this feature on demand).
- All operation listed in the task should be implemented as methods of the class derived from the web driver base class,
- All exceptions such as for example invalid mail service web-interface address, invalid password or username etc. should be handled and should not lead to abnormal program termination,
- The completed program should be presented as an executable module and provide an opportunity to be started through a command-line interface with the file containing configuration data specified.
- Provide brief documentation for your solution describing basic procedures and answering FAQ. For example, how to disable logging, how to use a custom browser, any known bottlenecks, limitations or workarounds, etc.
- Deadline to complete the task is 1 (one) week.
References:
http://docs.seleniumhq.org/projects/webdriver/
Solution:
using System; using System.IO; using Logger; using MailRuTest.Environment; using MailRuTest.UIMap; using MailRuTest.Validators; using Microsoft.VisualStudio.TestTools.UnitTesting; using SeWEBDriver; using Browser = SeWEBDriver.SeWebDriver.Browsers; namespace MailRuTest { [TestClass] public class UnitTest1 { const bool click = true; SeWebDriver driver = null; public Config conf = null; [TestMethod] public void SaveDefaultXmlConfig() { conf.Url = "http://mail.ru"; conf.LoginName = "jumpjump"; conf.Password = "*******"; conf.Domain = LoginParams.DOMAIN.ListRu; conf.Mail = new Mail() { To = "jumpjump@list.ru", Subject = "Send an email to someone, who sometimes want to sleep", Body = "<h1>H1 Text</h1><br><br><b>Bold</b><br>Test html text" }; conf.Browser = Browser.GoogleChrome; conf.LogEnabled = true; conf.LogFilePath = "OneMailRuTestConsole.log"; conf.Save<Config>("OneMailRuTestConsole.config.xml"); } [TestMethod] public void SendAnEmail() { new LoginPage(driver, new LoginParams() { Url = conf.Url, LoginName = conf.LoginName, Password = conf.Password, Domain = conf.Domain, LoginButton = click }); new MainPage(driver, new MainParams() { ComposeButton = click }); var magicString = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss "); new NewMailForm(driver, new NewMailParams() { To = conf.Mail.To, Subject = magicString + conf.Mail.Subject, Body = conf.Mail.Body, SendButton = click }); new MainPage(driver, new MainParams() { InboxMenuItem = click }); new WatchDogComplexValidator(TimeSpan.FromSeconds(10), new TextPresentOnPageValidator(driver, magicString) ).Validate(); } } }