-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from bashilovpa/master
Provide element locator by image c# issue #176
- Loading branch information
Showing
21 changed files
with
911 additions
and
14 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
122 changes: 122 additions & 0 deletions
122
C#.Net/JDI ImageToWebElement/JDI ImageToWebElement.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="..\packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{1DA1B1B5-F890-4EEB-B65A-4BC7DFB5EF2F}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>JDI_ImageToWebElement</RootNamespace> | ||
<AssemblyName>JDI ImageToWebElement</AssemblyName> | ||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath> | ||
<IsCodedUITest>False</IsCodedUITest> | ||
<TestProjectType>UnitTest</TestProjectType> | ||
<NuGetPackageImportStamp> | ||
</NuGetPackageImportStamp> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Ionic.Zip, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\SikuliIntegrator.1.1.0\lib\Ionic.Zip.dll</HintPath> | ||
</Reference> | ||
<Reference Include="nunit.framework, Version=3.9.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\NUnit.3.9.0\lib\net45\nunit.framework.dll</HintPath> | ||
</Reference> | ||
<Reference Include="SikuliModule, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\SikuliIntegrator.1.1.0\lib\SikuliModule.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Drawing"> | ||
<HintPath>..\packages\SikuliIntegrator.1.1.0\lib\System.Drawing.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="WebDriver, Version=3.7.0.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Selenium.WebDriver.3.7.0\lib\net45\WebDriver.dll</HintPath> | ||
</Reference> | ||
<Reference Include="WebDriver.Support, Version=3.7.0.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Selenium.Support.3.7.0\lib\net45\WebDriver.Support.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="ImagePattnerSerach.cs" /> | ||
<Compile Include="Tests\GetElementByImage.cs" /> | ||
<Compile Include="Tests\TestBase.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Content Include="Images\calculate.png"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
<Content Include="Images\checkbox.png"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
<Content Include="Images\paginatorFirst.png"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
<Content Include="Images\submit.png"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
<Content Include="JSikuliModule.jar"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\JDI\Commons\JDI Commons\JDI Commons.csproj"> | ||
<Project>{c749644d-5901-4fd6-9add-06209bdc1cd2}</Project> | ||
<Name>JDI Commons</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\JDI\Core\JDI Core.csproj"> | ||
<Project>{99ee5894-9f49-43e2-a129-7916d924d49c}</Project> | ||
<Name>JDI Core</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\JDI\Matchers\JDI Matchers\JDI Matchers.csproj"> | ||
<Project>{822c29a7-c835-40ef-9e83-ae5388be9a1c}</Project> | ||
<Name>JDI Matchers</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\JDI\Web\JDI Web\JDI Web.csproj"> | ||
<Project>{48a9b353-cb6b-4a15-84b4-b062b1c9bacc}</Project> | ||
<Name>JDI Web</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\Tests\JDI UIWebTests\JDI UIWebTests\JDI UIWebTests.csproj"> | ||
<Project>{e49ac2c4-cdc7-4bfe-bfac-d49830e0e748}</Project> | ||
<Name>JDI UIWebTests</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup /> | ||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" /> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> | ||
<PropertyGroup> | ||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> | ||
</PropertyGroup> | ||
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props'))" /> | ||
<Error Condition="!Exists('..\packages\Selenium.Chrome.WebDriver.2.33\build\Selenium.Chrome.WebDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.Chrome.WebDriver.2.33\build\Selenium.Chrome.WebDriver.targets'))" /> | ||
</Target> | ||
<Import Project="..\packages\Selenium.Chrome.WebDriver.2.33\build\Selenium.Chrome.WebDriver.targets" Condition="Exists('..\packages\Selenium.Chrome.WebDriver.2.33\build\Selenium.Chrome.WebDriver.targets')" /> | ||
</Project> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
[assembly: AssemblyTitle("JDI ImageToWebElement")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("EPAM Systems")] | ||
[assembly: AssemblyProduct("JDI ImageToWebElement")] | ||
[assembly: AssemblyCopyright("Copyright © EPAM Systems 2017")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
[assembly: ComVisible(false)] | ||
|
||
[assembly: Guid("1da1b1b5-f890-4eeb-b65a-4bc7dfb5ef2f")] | ||
|
||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using NUnit.Framework; | ||
using OpenQA.Selenium; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using static Epam.JDI.Core.Settings.JDISettings; | ||
using static JDI_UIWebTests.UIObjects.TestSite; | ||
|
||
namespace JDI_ImageToWebElement.Tests | ||
{ | ||
|
||
public class GetElementByImage | ||
{ | ||
private string imagesPath = Path.GetDirectoryName(typeof(GetElementByImage).Assembly.Location) + "\\Images\\"; | ||
[Test] | ||
public void GetCalculateButtonLocators() | ||
{ | ||
Logger.Info("Try to get calculate button locators"); | ||
var locators = | ||
ImagePattnerSerach.GetElementLocatorsByElementImage(MetalsColorsPage.WebDriver, imagesPath + "calculate.png"); | ||
|
||
foreach(var locator in locators) | ||
{ | ||
Logger.Info("Css locator " + locator.CssLocator); | ||
Logger.Info("xPath locator " + locator.XPathLocator); | ||
foreach(var item in locator.ElementAttributesLocators) | ||
{ | ||
Logger.Info("Element attribute locator key: " + item.Key + " value " + item.Value); | ||
} | ||
IWebElement element = MetalsColorsPage.WebDriver.FindElement(By.CssSelector(locator.CssLocator)); | ||
Assert.IsTrue(MetalsColorsPage.CalculateButton.WebElement.Text == element.Text); | ||
|
||
Assert.IsTrue(MetalsColorsPage.CalculateButton.WebElement.Text == MetalsColorsPage.WebDriver.FindElement(By.XPath(locator.XPathLocator)).Text); | ||
|
||
} | ||
|
||
Assert.IsTrue(MetalsColorsPage.CalculateButton.WebElement.GetAttribute("Id") == locators[0].WebElement.GetAttribute("Id")); | ||
|
||
|
||
|
||
} | ||
|
||
[Test] | ||
public void GetCheckBoxButtonLocators() | ||
{ | ||
Logger.Info("Try to get calculate button locators"); | ||
var locators = | ||
ImagePattnerSerach.GetElementLocatorsByElementImage(MetalsColorsPage.WebDriver, imagesPath + "checkbox.png"); | ||
|
||
foreach (var locator in locators) | ||
{ | ||
Logger.Info("Css locator " + locator.CssLocator); | ||
Logger.Info("xPath locator " + locator.XPathLocator); | ||
foreach (var item in locator.ElementAttributesLocators) | ||
{ | ||
Logger.Info("Element attribute locator key: " + item.Key + " value " + item.Value); | ||
} | ||
|
||
if(locator.WebElement.Text == "Water") | ||
{ | ||
IWebElement element = MetalsColorsPage.WebDriver.FindElement(By.CssSelector(locator.CssLocator)); | ||
Assert.IsTrue(MetalsColorsPage.CbWater.WebElement.Text == element.Text); | ||
|
||
Assert.IsTrue(MetalsColorsPage.CbWater.WebElement.Text == MetalsColorsPage.WebDriver.FindElement(By.XPath(locator.XPathLocator)).Text); | ||
} | ||
} | ||
|
||
//var linq = locators.Where(x=>x.WebElement.GetAttribute("NaM")) | ||
Assert.IsTrue(MetalsColorsPage.CbWater.WebElement.Text == locators.Where(x=>x.WebElement.Text == "Water").Select(x=>x.WebElement.Text).First()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Epam.JDI.Core.Settings; | ||
using JDI_UIWebTests.Entities; | ||
using JDI_UIWebTests.UIObjects; | ||
using JDI_Web.Selenium.DriverFactory; | ||
using JDI_Web.Selenium.Elements.Composite; | ||
using JDI_Web.Settings; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using static JDI_UIWebTests.UIObjects.TestSite; | ||
|
||
namespace JDI_ImageToWebElement.Tests | ||
{ | ||
[SetUpFixture] | ||
public class TestBase | ||
{ | ||
[OneTimeSetUp] | ||
protected void SetUp() | ||
{ | ||
WebSettings.InitNUnitDefault(); | ||
var logger = JDISettings.Logger; | ||
logger.Info("Init test run..."); | ||
WinProcUtils.KillAllRunWebDrivers(); | ||
WebSite.Init(typeof(TestSite)); | ||
TestSite.HomePage.Open(); | ||
TestSite.LoginForm.Submit(User.DefaultUser); | ||
logger.Info("Run test..."); | ||
logger.Info("Navigating to Metals and Colors page."); | ||
MetalsColorsPage.Open(); | ||
MetalsColorsPage.CheckTitle(); | ||
MetalsColorsPage.IsOpened(); | ||
} | ||
|
||
[OneTimeTearDown] | ||
protected void TearDown() | ||
{ | ||
// Some log outputs | ||
WinProcUtils.KillAllRunWebDrivers(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="NUnit" version="3.9.0" targetFramework="net461" /> | ||
<package id="NUnit.ConsoleRunner" version="3.7.0" targetFramework="net461" /> | ||
<package id="NUnit.Extension.NUnitProjectLoader" version="3.6.0" targetFramework="net461" /> | ||
<package id="NUnit.Extension.NUnitV2Driver" version="3.7.0" targetFramework="net461" /> | ||
<package id="NUnit.Extension.NUnitV2ResultWriter" version="3.6.0" targetFramework="net461" /> | ||
<package id="NUnit.Extension.TeamCityEventListener" version="1.0.3" targetFramework="net461" /> | ||
<package id="NUnit.Extension.VSProjectLoader" version="3.7.0" targetFramework="net461" /> | ||
<package id="NUnit.Runners" version="3.7.0" targetFramework="net461" /> | ||
<package id="NUnit3TestAdapter" version="3.9.0" targetFramework="net461" /> | ||
<package id="Selenium.Chrome.WebDriver" version="2.33" targetFramework="net461" /> | ||
<package id="Selenium.Support" version="3.7.0" targetFramework="net461" /> | ||
<package id="Selenium.WebDriver" version="3.7.0" targetFramework="net461" /> | ||
<package id="SikuliIntegrator" version="1.1.0" targetFramework="net461" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.