优化了显示

This commit is contained in:
fengjiayi
2024-08-08 21:39:42 +08:00
parent 81206ffbd5
commit 0ddbcc7ef6
11 changed files with 101 additions and 28 deletions

View File

@@ -4,6 +4,7 @@ using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using Serein.NodeFlow;
using static System.Net.Mime.MediaTypeNames;
namespace Serein.Module
{
@@ -69,14 +70,11 @@ namespace Serein.Module
public void Wait([Explicit]int time = 1000)
{
Thread.Sleep(time);
}
[MethodDetail(DynamicNodeType.Action,"启动浏览器")]
public WebDriver OpenDriver([Explicit] bool isVisible = true,[Explicit] DriverType driverType = DriverType.Chrome)
{
if(driverType == DriverType.Chrome)
{
ChromeOptions options = new ChromeOptions();
@@ -145,6 +143,34 @@ namespace Serein.Module
[MethodDetail(DynamicNodeType.Action,"定位元素")]
public IWebElement FindElement([Explicit] string key = "", [Explicit] ByType byType = ByType.XPath, [Explicit] int index = 0)
{
By by = byType switch
{
ByType.Id => By.Id(key),
ByType.XPath => By.XPath(key),
ByType.Class => By.ClassName(key),
ByType.Name => By.Name(key),
ByType.CssSelector => By.CssSelector(key),
ByType.PartialLinkText => By.PartialLinkText(key),
};
if(index == -1)
{
return WebDriver.FindElements(by).First();
}
else
{
return WebDriver.FindElements(by)[index];
}
}
[MethodDetail(DynamicNodeType.Action, "定位并操作元素")]
public IWebElement FindAndUseElement([Explicit] ByType byType = ByType.XPath,
[Explicit] string key = "",
[Explicit] ActionType actionType = ActionType.Click,
[Explicit] string text = "",
[Explicit] int index = 0,
[Explicit] int waitTime = 0)
{
Thread.Sleep(waitTime);
By by = byType switch
{
ByType.Id => By.Id(key),
@@ -155,8 +181,29 @@ namespace Serein.Module
ByType.PartialLinkText => By.PartialLinkText(key),
};
var element = WebDriver.FindElements(by)[index];
Thread.Sleep(waitTime);
var actions = new OpenQA.Selenium.Interactions.Actions(WebDriver);
switch (actionType)
{
case ActionType.Click:
actions.Click(element).Perform();
break;
case ActionType.DoubleClick:
actions.DoubleClick(element).Perform();
break;
case ActionType.RightClick:
actions.ContextClick(element).Perform();
break;
case ActionType.SendKeys:
element.Click();
element.Clear();
element.SendKeys(text);
break;
}
return element;
}
[MethodDetail(DynamicNodeType.Action, "操作元素")]
public void PerformAction(IWebElement element, [Explicit] ActionType actionType = ActionType.Click, [Explicit] string text = "")
{
@@ -191,6 +238,10 @@ namespace Serein.Module
}
else if (scriptOp == ScriptOp.Modify)
{
element.SetAttribute(WebDriver, attributeName, value);
string newHref = element.GetAttribute("href");
Console.WriteLine("New href value: " + newHref);
WebDriver.ExecuteScript("arguments[0].setAttribute(arguments[1], arguments[2]);", element, attributeName, value);
}
else if (scriptOp == ScriptOp.Delete)
@@ -206,4 +257,13 @@ namespace Serein.Module
return element.GetAttribute(attributeName);
}
}
public static class MyExtension
{
public static void SetAttribute(this IWebElement element, IWebDriver driver, string attributeName, string value)
{
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript($"arguments[0].setAttribute('{attributeName}', '{value}');", element);
}
}
}

View File

@@ -34,7 +34,6 @@ namespace Serein.WorkBench
{
#if false //测试 操作表达式,条件表达式
#region
string expression = "";
@@ -151,13 +150,14 @@ namespace Serein.WorkBench
Shutdown(); // 关闭应用程序
}
}
//else if (1 == 1)
//{
// string filePath = @"F:\临时\project\wat project.dnf";
// string content = System.IO.File.ReadAllText(filePath); // 读取整个文件内容
// FData = JsonConvert.DeserializeObject<SereinOutputFileData>(content);
// App.FileDataPath = System.IO.Path.GetDirectoryName(filePath);
//}
else if (1 == 1)
{
string filePath = @"F:\临时\project\U9 project.dnf";
//string filePath = @"D:\Project\C#\DynamicControl\SereinFlow\.Output\Debug\net8.0-windows7.0\U9 project.dnf";
string content = System.IO.File.ReadAllText(filePath); // 读取整个文件内容
FData = JsonConvert.DeserializeObject<SereinOutputFileData>(content);
App.FileDataPath = System.IO.Path.GetDirectoryName(filePath);
}
}
}

View File

@@ -397,7 +397,7 @@ namespace Serein.WorkBench
}
var connection = new Connection { Start = fromNode, End = toNode, Type = connectionType };
toNode.Node.PreviousNodes.Add(fromNode.Node);
DraggableControl.CreateLinx(FlowChartCanvas, connection);
BsControl.Draw(FlowChartCanvas, connection);
ConfigureLineContextMenu(connection);
connections.Add(connection);
}
@@ -1362,7 +1362,7 @@ namespace Serein.WorkBench
}
// 保存连接关系
DraggableControl.CreateLinx(FlowChartCanvas, connection);
BsControl.Draw(FlowChartCanvas, connection);
ConfigureLineContextMenu(connection);
targetBlock.Node.PreviousNodes.Add(startConnectBlock.Node); // 将当前发起连接的节点,添加到被连接的节点的上一节点队列。(用于回溯)
@@ -2004,9 +2004,9 @@ namespace Serein.WorkBench
#region UI层面上显示为 线
public static class DraggableControl
public static class BsControl
{
public static Connection CreateLinx(Canvas canvas, Connection connection)
public static Connection Draw(Canvas canvas, Connection connection)
{
UpdateBezierLine(canvas, connection);
//MakeDraggable(canvas, connection, connection.Start);
@@ -2101,7 +2101,6 @@ namespace Serein.WorkBench
//}
}

View File

@@ -6,7 +6,7 @@
xmlns:local="clr-namespace:Serein.WorkBench.Node.View"
xmlns:vm="clr-namespace:Serein.WorkBench.Node.ViewModel"
xmlns:themes="clr-namespace:Serein.WorkBench.Themes"
>
MaxWidth="300">
<Grid>
<Grid.ToolTip>
<ToolTip Background="LightYellow" Foreground="Black" Content="{Binding MethodDetails.MethodName, UpdateSourceTrigger=PropertyChanged}" />
@@ -17,10 +17,18 @@
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" Background="#FFCFDF" BorderBrush="#FFCFDF" BorderThickness="1">
<TextBlock Text="{Binding MethodDetails.MethodTips, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<StackPanel Grid.Row="0" Orientation="Horizontal" Background="#FFCFDF">
<CheckBox VerticalContentAlignment="Center">
</CheckBox>
<TextBlock Text="测试方法" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
<themes:MethodDetailsControl Grid.Row="1" MethodDetails="{Binding MethodDetails}" />
<Grid Grid.Row="2" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>

View File

@@ -3,7 +3,8 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Serein.WorkBench.Node.View">
xmlns:local="clr-namespace:Serein.WorkBench.Node.View"
MaxWidth="300">
<Grid>
<Border BorderBrush="Black" BorderThickness="1" Padding="10">
<StackPanel>

View File

@@ -5,7 +5,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Serein.WorkBench.Node.View"
xmlns:vm="clr-namespace:Serein.WorkBench.Node.ViewModel"
xmlns:themes="clr-namespace:Serein.WorkBench.Themes">
xmlns:themes="clr-namespace:Serein.WorkBench.Themes"
MaxWidth="300">
<!--d:DataContext="{d:DesignInstance Type=vm:ConditionNodeControlViewModel}"-->
<UserControl.Resources>

View File

@@ -3,7 +3,8 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Serein.WorkBench.Node.View">
xmlns:local="clr-namespace:Serein.WorkBench.Node.View"
MaxWidth="300">
<Grid>
<Border BorderBrush="Black" BorderThickness="1" Padding="10">

View File

@@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Serein.WorkBench.Node.View"
MaxWidth="300"
>
<DockPanel>
<StackPanel DockPanel.Dock="Top" >

View File

@@ -3,7 +3,8 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Serein.WorkBench.Node.View">
xmlns:local="clr-namespace:Serein.WorkBench.Node.View"
MaxWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>

View File

@@ -5,7 +5,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Serein.WorkBench.Node.View"
xmlns:vm="clr-namespace:Serein.WorkBench.Node.ViewModel"
xmlns:themes="clr-namespace:Serein.WorkBench.Themes">
xmlns:themes="clr-namespace:Serein.WorkBench.Themes"
MaxWidth="300">
<UserControl.Resources>
<vm:TypeToStringConverter x:Key="TypeToStringConverter"/>

View File

@@ -35,7 +35,7 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Index,StringFormat=agr{0}}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<CheckBox Grid.Column="1" IsChecked="{Binding IsExplicitData, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></CheckBox>
<CheckBox Grid.Column="1" IsChecked="{Binding IsExplicitData, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalContentAlignment="Center"/>
<TextBlock Grid.Column="2" MinWidth="50" Text="{Binding ParameterName}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBlock Grid.Column="3" MinWidth="50" Text="无须指定参数"/>
</Grid>
@@ -60,7 +60,7 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Index,StringFormat=agr{0}}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<CheckBox Grid.Column="1" IsChecked="{Binding IsExplicitData, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></CheckBox>
<CheckBox Grid.Column="1" IsChecked="{Binding IsExplicitData, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalContentAlignment="Center"/>
<TextBlock Grid.Column="2" MinWidth="50" Text="{Binding ParameterName}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<ComboBox Grid.Column="3"
MinWidth="50"
@@ -90,7 +90,7 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Index,StringFormat=agr{0}}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<CheckBox Grid.Column="1" IsChecked="{Binding IsExplicitData, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></CheckBox>
<CheckBox Grid.Column="1" IsChecked="{Binding IsExplicitData, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalContentAlignment="Center"/>
<TextBlock Grid.Column="2" MinWidth="50" Text="{Binding ParameterName}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBox Grid.Column="3" MinWidth="50" Text="{Binding DataValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</Grid>