编码的用户界面 - 跨浏览器问题。无法识别Chrome上的控件

时间:2016-01-21 14:07:09

标签: google-chrome cross-browser coded-ui-tests

我在http://localhost/MyWebApplication上托管了一个Web应用程序。我使用Coded UI作为在应用程序上执行UI自动化的工具

我必须执行并发类型的情景,在两个不同的管理员用户(比如user1& user2)登录http://localhost/MyWebApplication。当user1执行任何操作(如编辑或删除)时,应该反映在user2的数据

为实现这一目标,我在IE浏览器上登录MyWebAppliction为user1& Chrome浏览器为user2。我可以启动并登录IE& Chrome为user1& user2分别。

现在我执行了一些编辑,在IE中的user1上删除操作,我需要回去&检查它是否在chrome2中反映在user2中。我也需要做反之亦然(即Chrome到IE)

要在浏览器之间切换,我有以下方法将所需的浏览器(IE或chrome)带到前台

using System.Runtime.InteropServices;
using System.Diagnostics;

    [DllImport("user32.dll")]
    public static extern bool SetForegroundWindow(IntPtr hWnd);

    public void SwitchBrowserForMyWebApp(string browserName)
    {

        System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcessesByName(browserName).Where(x => x.MainWindowTitle.Contains("My Web Application")).ToArray();

        if (p.Length > 0)
        {
            SetForegroundWindow(p[0].MainWindowHandle); // bring the desired browser to the front
        }

       // ========== Till here it works fine & brings the required browser to the front.

        BrowserWindow curWindow;

        if (browserName == "iexplore")
        {
            BrowserWindow.CurrentBrowser = "IE";
        }

        else
        {
            BrowserWindow.CurrentBrowser = browserName;
            Process browserProcess = p[0];

             BrowserWindow bwp = BrowserWindow.FromProcess(p[0]);    // Here it gives null exception - Object not set to instance of an object
            //BrowserWindow.Locate("My Web Application - Google Chrome");             

        }

    }

我面临的问题是,如果我将IE带到前台,那么我可以访问控件并执行编辑或更新

但是如果我将chrome带到前台,那么我无法访问chrome上的任何控件。

我尝试将CurrentBrowser设置为" Chrome",使用BrowserWindow.Locate("我的Web应用程序 - Google Chrome"),还使用了BrowserWindow.FromProcess(p [0]);

无法找到问题所在。我正在使用IE 11& Chrome版本:47.0.2526.111 m

如果我遗失任何东西,任何人都可以告诉我。或任何解决此问题的工作

先谢谢

2 个答案:

答案 0 :(得分:0)

我还没试过这个,但设置" CurrentBrowser"属性不会切换浏览器。在调用Browser.Launch()方法初始化您使用的浏览器驱动程序之前,必须先设置此属性。它默认为IE浏览器。 U必须使用两个不同的浏览器实例并使用一个需求。可能是这样的,

public static BrowserWindow CurrentBrowser= null, Chrome = null, IE = null; 

IE = BrowserWindow.Launch(new Uri("http:\\urAppURLHere.COM"));

BrowserWindow.CurrentBrowser = "Chrome"
Chrome = BrowserWindow.Launch(new Uri("http:\\urAppURLHere.COM"));

CurrentBrowser = GetMeTheBrowserIWant("Chrome");


public static BrowserWindow GetMeTheBrowserIWant(string BrowserType)
{
    if(BrowserType.ToUpper().Equals("CHROME")
    {
       return Chrome;
    } 
      if(BrowserType.ToUpper().Equals("IE")
    {
       return IE;
    } 
}

答案 1 :(得分:0)

您正在切换浏览器,但您确定的测试对象仍然使用Chrome进行实例化。 您必须使用IE Again重新识别测试对象。

类似的东西,

GmailLogOnButton = new HtmlControl(GetMeTheBrowserIWant("IE"));
GmailLogOnButton.SearchProperties.Add(HtmlControl.PropertyNames.Id, "signIn");

考虑到相同步骤的并发执行,未开发编码的Ui框架。因此,当您尝试并发测试时,您将最终执行其他步骤。

您,也可以考虑使用线程,但它可能会给您的同步测试带来困难!