小编Yan*_*iav的帖子

在应用之间切换

我有一个场景,我需要使用Selenium和Appium切换应用程序.我从浏览器开始,然后我需要从通知栏中获取一些信息,然后切换回浏览器.我设法将每个过程作为一个独立的过程.但现在我正在努力做到端到端的过程.

我已经开始创建一个webdriver会话,但是当他第一个仍在运行时我无法打开一个新会话.问题是浏览器和appium有不同的会话.一个被称为

_driver = new AndroidDriver<AppiumWebElement>(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities, TimeSpan.FromSeconds(180));
Run Code Online (Sandbox Code Playgroud)

而第二个是

_webdriver = new RemoteWebDriver(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities, TimeSpan.FromSeconds(180));
Run Code Online (Sandbox Code Playgroud)

selenium android appium

5
推荐指数
1
解决办法
401
查看次数

配置源路径使用错误

我正在尝试通过从 那里定向来使用配置文件App.configConfig我在解决方案中创建了一个名为 的文件夹,并创建了一个名为 的新配置文件Environment.config

我的App.Config样子如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /></startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <appSettings configSource="Config/Environment.config"/>
</configuration>
Run Code Online (Sandbox Code Playgroud)

看起来Environment.config如下:

  <appSettings>
    <add …
Run Code Online (Sandbox Code Playgroud)

c# app-config

5
推荐指数
1
解决办法
5934
查看次数

等待结果后再继续

我正在使用 Google 的 reCaptcha V3 作为我的 Angular(7) 项目的一部分。

我想在继续执行其余代码并检查令牌是否经过验证之前等待令牌的响应。

declare var grecaptcha: any;

  ngOnInit() {
    this.validateCaptcha();
    if(this.gToken)
    {
      ...
    }
  }
  gToken:string;
  validateCaptcha()
  {
    let self = this;
    grecaptcha.ready(function() {
    grecaptcha.execute('reCAPTCHA_site_key', {action: 'homepage'}).then(function(token){
      self.gToken = token;
    });
});
  }
Run Code Online (Sandbox Code Playgroud)

问题是它this.gToken是未定义的,因为它不等待validateCaptcha完成其工作。我也尝试过asyncawait但没有帮助。也许我用错了。

javascript angular recaptcha-v3

4
推荐指数
1
解决办法
5056
查看次数

错误:不支持给定路径的格式

我究竟做错了什么?我的主要问题是我收到错误说:

错误:不支持给定路径的格式

我想将项目本身保存在我已经创建的文件夹下的名称:Screenshots

public void TakeScreenShot()
{
    string pth = System.Reflection.Assembly.GetCallingAssembly().CodeBase;
    string actualPath = pth.Substring(0, pth.LastIndexOf("bin"));
    string projectPath = new Uri(actualPath).LocalPath;

    Screenshot ss = ((ITakesScreenshot)_driver).GetScreenshot();
    string screenshot = ss.AsBase64EncodedString;
    byte[] screenshotAsByteArray = ss.AsByteArray;
    ss.SaveAsFile(projectPath+"Screenshots\\Drisha"+DateTime.Now.ToString()+".jpeg", ImageFormat.Jpeg); 
}
Run Code Online (Sandbox Code Playgroud)

c# screenshot appium

3
推荐指数
1
解决办法
2264
查看次数

DesiredCapabilities已过时

我曾经有以下代码,以便以不同的用户身份运行驱动程序.

 public static IWebDriver RunIEAsDifferentUser(string User,string Password)
    {

        var capabilitiesInternet = DesiredCapabilities.InternetExplorer();
        capabilitiesInternet.SetCapability("ignoreProtectedModeSettings", true);
        capabilitiesInternet.SetCapability("EnsureCleanSession ", true);
        RunAs("C:\\Exlporer/IEDriverServer.exe", User, Password);
        _webdriverIE = new RemoteWebDriver(new Uri("http://localhost:5555/"), capabilitiesInternet, TimeSpan.FromSeconds(300));
        return _webdriverIE;

    }
    public static void RunAs(string path, string username, string password)
    {
        ProcessStartInfo myProcess = new ProcessStartInfo(path);
        myProcess.UserName = username;
        myProcess.Password = MakeSecureString(password);
        myProcess.UseShellExecute = false;
        myProcess.LoadUserProfile = true;
        myProcess.Verb = "runas";
        myProcess.Domain = "DOM001";
        Process.Start(myProcess);
    }

    public static SecureString MakeSecureString(string text)
    {
        SecureString secure = new SecureString();
        foreach (char c in …
Run Code Online (Sandbox Code Playgroud)

c# selenium selenium-webdriver desiredcapabilities

3
推荐指数
1
解决办法
6778
查看次数

405(不允许的方法)并被 CORS 策略阻止

我在客户端有基于 Angular(7.2.1) 的 UI 的 Asp.Net Core(3) WebApi 项目。使用 Postman 或仅使用 URL 时,我可以使用 GET 和 POST 而不会出现任何特定错误。通过 Angular(Chrome\FireFox\IE Browser) 尝试相同的操作时,我收到以下错误。

zone.js:3243 OPTIONS http://localhost:8888/api/PaymentDetails 405 (Method Not Allowed) ccess to XMLHttpRequest at 'http://localhost:8888/api/PaymentDetails' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

我会尽量分享尽可能多的代码来演示流程。

WebApi Startup.cs:

公共 IConfiguration 配置 { 获取;}

// This method gets called by the runtime. Use this method to add …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core asp.net-core-webapi angular

3
推荐指数
1
解决办法
3654
查看次数

所需属性为 null 时反序列化并抛出异常

我可能错过了一些东西。我想测试 API 调用响应返回 null 属性时的行为,并且希望在发生这种情况时引发异常。

我有一个Form对象如下

public class Form
{
    [Required]
    public string Html { get; set; }
    public string Json { get; set; }
    public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我已经初始化了一个对象

var myData = new
{
    Json = "foo",
};

string jsonData = JsonConvert.SerializeObject(myData);
var response = JsonConvert.DeserializeObject<Form>(File.ReadAllText(jsonPath));
Run Code Online (Sandbox Code Playgroud)

我本来期望有一个异常,因为Html属性 isrequired且 not nullable,但实际上将对象获取为

{
    Html = null, 
    Json = foo,
    Name = null
}
Run Code Online (Sandbox Code Playgroud)

我尝试JsonSerializerSettings按如下方式使用,但这实际上仅在存在其他不需要的属性时才会引发异常,而不是在缺少属性时才会引发异常。

{
    Html = null, …
Run Code Online (Sandbox Code Playgroud)

c# json.net deserialization

3
推荐指数
1
解决办法
1471
查看次数

在多个浏览器上并行运行测试

我找到了在多个浏览器上一个接一个地运行测试的方法,但是我找不到一种使用 selenium grid 的方法来在多个浏览器上并行运行我的测试(使用 C#)。这就是我目前使用的:

using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using System.Threading;

namespace SeleniumTests 
{
[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
public class TestWithMultipleBrowsers<TWebDriver> where TWebDriver : IWebDriver, new()
{
    private IWebDriver driver;

    [SetUp]
    public void CreateDriver () {
        this.driver = new TWebDriver();
    }

    [Test]
    public void GoogleTest() {
        driver.Navigate().GoToUrl("http://www.google.com/");
        IWebElement query = driver.FindElement(By.Name("q"));
        query.SendKeys("Bread" + Keys.Enter);

        Thread.Sleep(2000);

        Assert.AreEqual("bread - Google Search", driver.Title);
        driver.Quit();
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

从 C# NUnit 一个接一个地在多个浏览器中运行 Selenium 测试

c# selenium selenium-grid

2
推荐指数
1
解决办法
5579
查看次数

formArrayName必须与父formGroup指令一起使用

我收到一个错误:formArrayName must be used with a parent formGroup directive. You'll want to add a formGroup directive and pass it an existing FormGroup instance。我不确定我在做什么错。我希望FormGroup迭代几次(使用ngFor),并认为使用formArrayName将是答案。

HTML:

<div formArrayName = "PaymentArray" *ngFor = "let meshalem of paymentForm.get('PaymentArray').controls;let i =index;">
    <div [formGroup]="i">
        <div class="row box-border" >
            <div class="form-group col-xs-12 col-sm-12 col-md-5 pull-right required">
                <label class="control-label">???? ?.?. ????</label>
                <input #PidField name="id_pay" id="id_pay" formControlName="id_pay" class="form-control input-lg"
                    maxlength="9" (input)="searchChange($event.target.value)" />
            </div>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

.ts文件:

  paymentForm = this.fb.group({
    PaymentArray: this.fb.array([])
  }) …
Run Code Online (Sandbox Code Playgroud)

html javascript angular

2
推荐指数
1
解决办法
340
查看次数

对象属性的深度计数

我想计算一个对象内的属性数量。我找到了几种解决方案,但没有一个真正计算子\嵌套属性。

例如,我有以下 JSON 对象。

{
        "id": "259a36d2-3852-425f-a70c-3f9477753210",
        "name": "foo",
        "type": "na",
        "text": "ABC.pdf",
        "left": 333,
        "top": 130,
        "w": 134,
        "h": 34,
        "customData": {
            "A": "fa6css4ec8-8ffb-55bca4dde06a",
            "name": "SDF.pdf",
            "IsExists": false,
            "PNumber": 1,
        }
    }
Run Code Online (Sandbox Code Playgroud)

当尝试以下操作时,我得到的结果是 9,而我期望的是 12(这是整个属性的计数)。

JObject sourceJObject = JsonConvert.DeserializeObject<JObject>(json);
var res= sourceJObject.Count;
Run Code Online (Sandbox Code Playgroud)

当助理我会很高兴。

c# json json.net

1
推荐指数
1
解决办法
632
查看次数