Skip to content

Commit

Permalink
Merge pull request #87 from ERNI-Academy/feature/selenium-manager
Browse files Browse the repository at this point in the history
Add support for Selenium Manager
  • Loading branch information
mg-diego authored May 23, 2024
2 parents 8f7f9c5 + d61ca9c commit c2f9553
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 138 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Testware provides capabilities to automate:
<img src="https://github.com/devicons/devicon/blob/master/icons/firefox/firefox-original-wordmark.svg" title="Firefox" alt="Firefox" width="40" height="40"/>
<img src="https://github.com/devicons/devicon/blob/master/icons/ie10/ie10-original.svg" title="IE" alt="IE" width="40" height="40"/>
<img src="https://upload.wikimedia.org/wikipedia/commons/3/32/Microsoft_Edge_Dev_Icon_%282019%29.svg" title="Edge" alt="Edge" width="40" height="40"/>
- **Websites** (using Selenoid)
- **Websites** (using [Selenoid](https://aerokube.com/selenoid/latest/))
- Supported Browsers:
<img src="https://github.com/devicons/devicon/blob/master/icons/chrome/chrome-original-wordmark.svg" title="Chrome" alt="Chrome" width="40" height="40"/>
<img src="https://github.com/devicons/devicon/blob/master/icons/firefox/firefox-original-wordmark.svg" title="Firefox" alt="Firefox" width="40" height="40"/>
Expand Down Expand Up @@ -150,9 +150,7 @@ Evidence collection:
"Capabilities": [
{
"Name": "WebDriver",
"Path": "C:\\workspace\\Drivers",
"Driver": "Chrome",
"CommandTimeOutInMinutes": 5,
"Arguments": [
"--start-maximized"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Feature: Chat_multibrowser
Scenario: Chat between two users
Given the 'user1' creates a new chat session on 'browser1Chat'
When the 'user2' joins chat session on 'browser2Chat'
Then the 'has joined.' message from 'user2' appears on 'browser1Chat'
And the 'has joined.' message from 'user1' appears on 'browser2Chat'
Then the ' joined the chat' message from 'user2' appears on 'browser1Chat'
And the ' started the chat' message from 'user1' appears on 'browser2Chat'
When the user sends 'a test' message on 'browser1Chat'
Then the 'a test' message from 'user1' appears on all browsers
Then the ' a test' message from 'user1:' appears on all browsers
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@
using TestWare.Engines.Selenium.Factory;
using TestWare.Engines.Selenium.Pages;

namespace TestWare.Samples.Selenium.Web.POM.Stinto.Chat;
namespace TestWare.Samples.Selenium.Web.POM.Chat;

public class ChatPage : WebPage, IChatPage
{
[FindsBy(How = How.XPath, Using = "//*[contains(@id,'msg')]")]
[FindsBy(How = How.ClassName, Using = "b")]
[FindsBy(How = How.ClassName, Using = "a")]
private IList<IWebElement> ChatMessages { get; set; }

[FindsBy(How = How.Id, Using = "prompt")]
[FindsBy(How = How.Id, Using = "X9225")]
private IWebElement SendMessageInput { get; set; }

public ChatPage(IBrowserDriver driver) : base(driver)
{
}

public void CheckMessage(string userId, string message)
public void CheckChatMessage(string userId, string message)
{
RetryPolicies.ExecuteActionWithRetries(
() =>
{
var messages = ChatMessages.Select(x => x.Text).ToList();
messages.Any(x => x.Contains(string.Concat(userId, message))).Should().BeTrue();
messages.Any(x => x.Contains(string.Concat(userId, message))).Should().BeTrue("Value '" + string.Concat(userId, message) + "' not found");
},
numberOfRetries: 10
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using TestWare.Core.Interfaces;

namespace TestWare.Samples.Selenium.Web.POM.Stinto.Chat;
namespace TestWare.Samples.Selenium.Web.POM.Chat;

public interface IChatPage : ITestWareComponent
{
void CheckMessage(string userId, string message);
void CheckChatMessage(string userId, string message);
void SendMessage(string message);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using OpenQA.Selenium;
using TestWare.Core.Libraries;
using TestWare.Engines.Common.Extras;
using TestWare.Engines.Selenium.Factory;
using TestWare.Engines.Selenium.Pages;

namespace TestWare.Samples.Selenium.Web.POM.CreateChat;

public class CreateChatPage : WebPage, ICreateChatPage
{
[FindsBy(How = How.Id, Using = "X8712")]
private IWebElement UserIdInput { get; set; }

[FindsBy(How = How.Id, Using = "X7728")]
private IWebElement ChatRoomTitleInput { get; set; }

[FindsBy(How = How.XPath, Using = "//*[@type='submit']")]
private IWebElement SubmitButton { get; set; }

public CreateChatPage(IBrowserDriver driver) : base(driver)
{
}

public void SetUserId(string userId)
=> SendKeysElement(this.UserIdInput, userId);

public void SetChatRoomTitle(string chatRoomTitle)
=> SendKeysElement(this.ChatRoomTitleInput, chatRoomTitle);

public void ClickSubmitButton()
{
var initialUrl = GetChatUrl();
ClickElement(this.SubmitButton);
RetryPolicies.ExecuteActionWithRetries(() =>
{
this.Driver.Url.Should().NotBe(initialUrl);
});
}

public string GetChatUrl()
=> this.Driver.Url;

public void NavigateTo(string url)
=> NavigateToUrl(url);
}

Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using TestWare.Core.Interfaces;

namespace TestWare.Samples.Selenium.Web.POM.Stinto.CreateChat;
namespace TestWare.Samples.Selenium.Web.POM.CreateChat;

public interface ICreateChatPage : ITestWareComponent
{
void SetUserId(string userId);
void AcceptTermsOfUse();
void SetChatRoomTitle(string chatRoomTitle);
void ClickSubmitButton();
string GetChatUrl();
void NavigateTo(string url);
}

This file was deleted.

25 changes: 0 additions & 25 deletions samples/TestWare.Samples.Selenium.Web/POM/Stinto/Home/HomePage.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using TestWare.Core;
using TestWare.Samples.Selenium.Web.POM.Stinto;
using TestWare.Samples.Selenium.Web.POM.Stinto.Chat;
using TestWare.Samples.Selenium.Web.POM.Stinto.CreateChat;
using TestWare.Samples.Selenium.Web.POM.Chat;
using TestWare.Samples.Selenium.Web.POM.CreateChat;

namespace TestWare.Samples.Selenium.Web.StepDefinitions.Stinto;
namespace TestWare.Samples.Selenium.Web.StepDefinitions.Chat;

[Binding]
public sealed class ChatSteps
Expand All @@ -21,41 +20,36 @@ public ChatSteps(FeatureContext featureContext, ScenarioContext scenarioContext)
[Given(@"the '([^']*)' creates a new chat session on '([^']*)'")]
public void GivenTheCreatesANewChatSessionOn(string user, string browser)
{
var homePage = ContainerManager.GetTestWareComponent<IHomePage>(browser);
homePage.ClickCreateChat();

var createChatPage = ContainerManager.GetTestWareComponent<ICreateChatPage>(browser);
createChatPage.SetUserId(user);
createChatPage.AcceptTermsOfUse();
createChatPage.SetChatRoomTitle("testRoom");
createChatPage.ClickSubmitButton();
}

[When(@"the '([^']*)' joins chat session on '([^']*)'")]
public void WhenTheJoinsChatSessionOn(string user, string browser)
{
var homePage = ContainerManager.GetTestWareComponent<IHomePage>(browser);
var createChatPage = ContainerManager.GetTestWareComponent<ICreateChatPage>(browser);

var urls = new List<string>();
createChatPages.ToList().ForEach(x => urls.Add(x.GetChatUrl()));

homePage.NavigateTo(urls.OrderByDescending(s => s.Length).First());
createChatPage.NavigateTo(urls.OrderByDescending(s => s.Length).First());
createChatPage.SetUserId(user);
createChatPage.AcceptTermsOfUse();
createChatPage.ClickSubmitButton();
}

[Then(@"the '([^']*)' message from '([^']*)' appears on '([^']*)'")]
public void ThenTheMessageFromAppearsOn(string message, string fromUser, string browser)
{
var chatPage = ContainerManager.GetTestWareComponent<IChatPage>(browser);
chatPage.CheckMessage(fromUser, message);
chatPage.CheckChatMessage(fromUser, message);
}

[Then(@"the '([^']*)' message from '([^']*)' appears on all browsers")]
public void ThenTheMessageFromAppearsOnAllBrowsers(string message, string userFrom)
{
chatPages.ToList().ForEach(x => x.CheckMessage(userFrom, message));
chatPages.ToList().ForEach(x => x.CheckChatMessage(userFrom, message));
}

[When(@"the user sends '([^']*)' message on '([^']*)'")]
Expand Down
29 changes: 3 additions & 26 deletions samples/TestWare.Samples.Selenium.Web/TestConfiguration.Web.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
"Capabilities": [
{
"Name": "WebDriver",
"Path": "C:\\workspace\\Drivers",
"Driver": "Chrome",
"Driver": "Firefox",
"BaseUrl": "https://www.saucedemo.com/",
"CommandTimeOutInMinutes": 5,
"Arguments": [
"--start-maximized"
]
Expand All @@ -20,64 +18,43 @@
"Capabilities": [
{
"Name": "browser1Chat",
"Path": "C:\\workspace\\Drivers",
"Driver": "Chrome",
"BaseUrl": "https://stin.to/en",
"CommandTimeOutInMinutes": 5,
"BaseUrl": "https://www.chatzy.com/",
"Arguments": [
"-window-position=0,0",
"--window-size=800,600"
]
},
{
"Name": "browser2Chat",
"Path": "C:\\workspace\\Drivers",
"Driver": "Chrome",
"BaseUrl": "https://stin.to/en",
"CommandTimeOutInMinutes": 5,
"Arguments": [
"-window-position=800,0",
"--window-size=800,600"
]
},
{
"Name": "browser3Chat",
"Path": "C:\\workspace\\Drivers",
"Driver": "Firefox",
"BaseUrl": "https://stin.to/en",
"CommandTimeOutInMinutes": 5,
"BaseUrl": "https://www.chatzy.com/",
"Arguments": [
"--start-maximized"
]
},
{
"Name": "browser1Swaglabs",
"Path": "C:\\workspace\\Drivers",
"Driver": "Chrome",
"BaseUrl": "https://www.saucedemo.com/",
"CommandTimeOutInMinutes": 5,
"Arguments": [
"-window-position=0,0",
"--window-size=800,600"
]
},
{
"Name": "browser2Swaglabs",
"Path": "C:\\workspace\\Drivers",
"Driver": "Chrome",
"BaseUrl": "https://www.saucedemo.com/",
"CommandTimeOutInMinutes": 5,
"Arguments": [
"-window-position=800,0",
"--window-size=800,600"
]
},
{
"Name": "browser3Swaglabs",
"Path": "C:\\workspace\\Drivers",
"Driver": "Firefox",
"BaseUrl": "https://www.saucedemo.com/",
"CommandTimeOutInMinutes": 5,
"Arguments": [
"--start-maximized"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ internal class Capabilities
{
public string Name { get; set; }

public string Path { get; set; }

public string Driver { get; set; }

public string BaseUrl { get; set; }
public int CommandTimeOutInMinutes { get; set; }


public IEnumerable<string> Arguments { get; set; } = Enumerable.Empty<string>();
Expand Down
Loading

0 comments on commit c2f9553

Please sign in to comment.