在开始之前,我想说如果有人认为我走的是错误的道路,我可以在我的硒框架内尝试不同的建议。我现在很开心地开发我的硒测试服(c#,Nunit)很长一段时间了,不幸的是,在尝试实施Sikuli4Net时遇到了令人沮丧的事情。
我的项目需要引入画布以图形方式绘制数据流图并与之交互,但这增加了复杂性,即没有任何常用的东西用于识别屏幕上的对象。我去过几个论坛,他们似乎都建议使用Sikuli4Net以图形方式与它进行交互。
我开始关注一些YouTube视频,但我似乎无法正常工作。每次我运行我的测试时,我都会得到以下堆栈跟踪:
at System.Net.HttpWebRequest.GetResponse()
at Sikuli4Net.sikuli_REST.Screen.MakeRequest(String requestURLExtension, String jsonObject)
at Sikuli4Net.sikuli_REST.Screen.Click(Pattern pattern, KeyModifier kmod, Boolean highlight)
at Builder2018.SmokeTests.canvas.canvasBob(String BrowserName, String Environment, String System) in C:\Users\Administrator\Documents\Builder2018\Builder2018\Builder2018\SmokeTests\canvas.cs:line 38
Result Message: System.Net.WebException : The remote server returned an error: (403) Forbidden.
我暂时放弃尝试针对我的实际项目实施它,并且只是试图让一个hello world类型示例使用Google但仍然遇到上述错误。我有什么简单的遗失,因为它不应该这么难......
据我所知,我已经完成了所有必要的配置(JDK,环境变量等),这是我目前尝试实现它:
namespace AutomationStuffs.SmokeTests
{
[TestFixture]
public class canvas : TestBase
{
APILauncher launcher = new APILauncher();
[Test]
[TestCaseSource(typeof(TestBase), "TestData")]
public void canvasBob(String BrowserName, String Environment, String System)
{
//Start API Launcher
launcher.Start();
//Configure test setup - within my environment i would usually perform a repeated login step here within setup
Setup(BrowserName, Environment, System, new string[] { });
//GoTo Google
KnowledgeBasePage.GoToGoogle();
//Test steps i have issue with
Screen screenGoogle = new Screen();
Pattern element1 = new Pattern(@"C:\Users\Administrator\Documents\AutomationStuffs\AutomationStuffs\PageImages\feelinglucky.PNG");
screenGoogle.Click(element1);
//Start API Launcher
launcher.Stop();
}
}
}
为了完整起见 - 我已经包含了被调用的其他适当位:
public void Setup(String BrowserName, String Environment, String System, String[] Additional)
{
//launcher.Start();
Driver.Intialize(BrowserName);
//perform SQL inserts and set appropriate data based on BrowserName, Environment, System, Additional..
//LoginSteps(); //not used for this example test
}
public static void Intialize(String BrowserName)
{
String DRIVER_PATH = chromeDriver;
String DRIVER_PATH_IEFF = ieDriver;
String DRIVER_PATH_EDGE = edgeDriver;
var optionsChrome = new ChromeOptions();
optionsChrome.AddArgument("start-maximized");
optionsChrome.AddArgument("no-sandbox");
var opt = new FirefoxOptions
{
BrowserExecutableLocation = @"c:\program files\mozilla firefox\firefox.exe"
};
//var driver = new FirefoxDriver(opt);
var optionsIe = new InternetExplorerOptions();
if (BrowserName.Equals("ie"))
{
Instance = new InternetExplorerDriver(DRIVER_PATH_IEFF);
Instance.Manage().Window.Maximize();
}
else if (BrowserName.Equals("firefox"))
{
Instance = new FirefoxDriver(opt);
Instance.Manage().Window.Maximize();
Instance.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
}
else if (BrowserName.Equals("edge"))
{
Instance = new EdgeDriver(DRIVER_PATH_EDGE);
Instance.Manage().Window.Maximize();
}
else if (BrowserName.Equals("chrome"))
{
Instance = new ChromeDriver(DRIVER_PATH, optionsChrome);
Instance.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
}
else
{
//Your test has failed because an unsupported browser-name was selected!
Assert.Fail("Your test has failed because an unsupported browser-name was selected! Currently supported browser names in the BrowsersList.resx file are: ie,firefox,edge,chrome - these are Case sensitive");
}
}
答案 0 :(得分:1)
以为我会放弃一些关于我所处理的信息。基本上,我改用并使用了SikuliIntegrator。
代码更容易,没有API启动器。我能够更轻松地重构我的代码并将执行代码的实际代码与我的测试分开,使它们具有人类可读性。唯一的缺点是启动时的等待时间,它会在测试中增加大约2到7秒。我使用的测试和代码如下:
namespace AutomationStuffs.SmokeTests
{
[TestFixture]
public class canvas : TestBase
{
[Test]
[TestCaseSource(typeof(TestBase), "TestData")]
public void canvasBob(String BrowserName, String Environment, String System)
{
//Configure test setup - within my environment i would usually perform a repeated login step here within setup
Setup(BrowserName, Environment, System, new string[] { });
//GoTo Google
KnowledgeBasePage.GoToGoogle();
GooglePage.ClickImFeelingLucky();
Assert.IsTrue(googlePage.OnTheImFeelingLuckyPage());
}
}
}
public static void ClickImFeelingLucky()
{
Wait.WaitForPageElementToBeVisible(By.Name("q"), 10);
string MyPicture = @"C:\..\intractionImages\Capture.PNG";
Console.WriteLine(MyPicture);
SikuliAction.Click(MyPicture);
Wait.WaitForPageElementToBeVisible(By.Id("lang-chooser"), 10);
}
在此处找到所有有用的信息https://qaagent.wordpress.com/2013/07/17/how-to-use-sikuli-in-my-c-coded-tests/
以下是文章的内容:
确保正确配置Java: 要求
java 1.6 - 使用jre-6u35-windows-i586.exe测试
Microsoft .NET 4.5
的NuGet
Add JAVA_HOME environment variable with value = path to installed JRE bin folder.
安装 您可以通过以下步骤获得StartUp项目,也可以创建新项目:
在Visual Studio 2012中创建新项目
在“解决方案资源管理器”中 - 右键单击解决方案
选择“管理解决方案的NuGet包...”
搜索“SikuliIntegrator”并安装
安装完成后,“JSikuliModule.jar”应该是您解决方案的一部分,还有一些其他文件
右键单击“JSikuliModule.jar”并选择“属性”
将“复制到输出目录”属性设置为“始终复制”
我发现第6步和第7步是整个事情中最重要的部分
这是我发现的其他阅读列表,我发现它很有用: