无法在Visual Studio Online上运行Selenium测试用例 [英] Unable to run Selenium test cases on Visual Studio Online

查看:65
本文介绍了无法在Visual Studio Online上运行Selenium测试用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用System; 
使用Microsoft.VisualStudio.TestTools.UnitTesting;
使用OpenQA.Selenium;
使用OpenQA.Selenium.Chrome;
使用OpenQA.Selenium.Firefox;
使用OpenQA.Selenium.IE;
使用OpenQA.Selenium.Remote;
使用静态OpenQA.Selenium.IAlert;使用NUnit.Framework
;
使用OpenQA.Selenium.Support;
使用OpenQA.Selenium.Support.UI;
使用System.IO;使用System.Reflection
;

名称空间SeleniumDemo
{
[TestClass]
public class LoginInApplication
{
public RemoteWebDriver driver;

[SetUp]
public void initialize()
{
// varcutingPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly()。Location);
// FirefoxDriverService服务= FirefoxDriverService.CreateDefaultService(enforcementPath);
// service.FirefoxBinaryPath = String.Format(@" C:\Program Files(x86)\ Mozilla Firefox \ firefox.exe");
driver = new FirefoxDriver();
driver.Manage()。Window.Maximize();
driver.Manage()。Timeouts()。ImplicitlyWait(TimeSpan.FromSeconds(60));

}

// =============================== $==============================================
[测试]
public void Test3VerifyLoginFunctionality()
{

driver.Navigate()。goToUrl(" http://alcamIdev.vdev.digitalmettle.com");
//输入UserName
driver.FindElement(By.Id(" md-input-1"))。Clear();
driver.FindElement(By.Id(" md-input-1"))。Click();
driver.FindElement(By.Id(" md-input-1"))。SendKeys("");

//输入密码
driver.FindElement(By.Id(" md-input-3"))。Clear();
driver.FindElement(By.Id(" md-input-3"))。Click();
driver.FindElement(By.Id(" md-input-3"))。SendKeys("");

//单击按钮登录
driver.FindElement(By.XPath(" // div [@ class ='user-btn-wrapper'] / div / button / span [@类= '垫键式包装']"))点击();
//单击同意按钮
System.Threading.Thread.Sleep(10000);




}

// =================== ================================================== =========


public void Test1VerifyNewUserRegisterInApplication()
{

driver.Navigate()。GoToUrl(" http) ://alcamIdev.vdev.digitalmettle.com");
//打开注册屏幕
driver.FindElement(By.XPath(" // div [@ class ='extra-options'] / div [@ class ='sign-up-link'] / A"))点击();
driver.FindElement(By.Id(" md-input-5"))。Click();
//输入电子邮件ID
driver.FindElement(By.Id(" md-input-5"))。SendKeys("");
//输入名字
driver.FindElement(By.Id(" md-input-7"))。SendKeys(" Tarun");
//输入姓氏
driver.FindElement(By.Id(" md-input-9"))。SendKeys(" Dabas");
//输入密码
driver.FindElement(By.Id(" md-input-11"))。SendKeys("");
//输入确认密码
driver.FindElement(By.Id(" md-input-13"))。SendKeys("");
//输入手机号码
driver.FindElement(By.Id(" md-input-15"))。SendKeys(" 9999999986");
//接受复选框

var elem = driver.FindElement(By.XPath(" // div [@ class ='register-content'] // button [@ class =' mat-raised-button mat-primary']"));
((IJavaScriptExecutor)驱动程序).ExecuteScript(" arguments [0] .scrollIntoView(true);",elem);

driver.FindElement(By.XPath(" // md-checkbox / label / div [@ class ='mat-checkbox-inner-container'] // div [2]") )。单击();
//单击注册按钮并在确认警报后将显示

driver.FindElement(By.XPath(" // div [@ class ='register-content'] // button [@ class ='mat-raised-button mat-primary']"))。Click();


System.Threading.Thread.Sleep(30000);

}

// =============================== $==============================================


public void Test2VerifyNewUserEmail()
{

driver.Navigate()。goToUrl(" https://www.mailinator.com");
driver.FindElement(By.XPath(" // div [@ class ='input-group'] / input [@ Id ='inboxfield']"))。SendKeys(" digitalmettle50 @ mailinator。 COM");
driver.FindElement(By.XPath(" // span [@ class ='input-group-btn'] / button"))。Click();
driver.FindElement(By.XPath(" // div [@ class ='all_message-min'] / div [3]"))。Click();
driver.SwitchTo()。Frame(" msg_body");
driver.FindElement(By.XPath(" // a [starts-with(@ href,'http://alcamidev.vdev.digitalmettle.com')]"))。Click();
System.Threading.Thread.Sleep(30000);

}


// =========================== ================================================== =

[测试]
public void Test4VerifyUserForgotPassword()
{
driver.Navigate()。goToUrl(" http://alcamIdev.vdev.digitalmettle。 COM");
driver.FindElement(By.XPath(" // div [@ class ='extra-options'] / div [1] / a"))。Click();
driver.FindElement(By.XPath(" // div [@ class ='mat-input-infix'] / input"))。SendKeys(" digitalmettle50@mailinator.com");
driver.FindElement(By.XPath(" // div [@ class ='forgot-content'] / button [@ class ='forgot-btn mat-raised-button mat-primary']") )。单击();
System.Threading.Thread.Sleep(10000);

}

// =============================== $==============================================


public void Test5VerifyUpdateUserDetails()
{
//打开网站
driver.Navigate()。GoToUrl(" http://alcamIdev.vdev.digitalmettle .COM");
//输入UserName
driver.FindElement(By.Id(" md-input-1"))。Clear();
driver.FindElement(By.Id(" md-input-1"))。Click();
driver.FindElement(By.Id(" md-input-1"))。SendKeys("");

//输入密码
driver.FindElement(By.Id(" md-input-3"))。Clear();
driver.FindElement(By.Id(" md-input-3"))。Click();
driver.FindElement(By.Id(" md-input-3"))。SendKeys("");

//单击按钮登录
driver.FindElement(By.XPath(" // div [@ class ='user-btn-wrapper'] / div / button / span [@类= '垫键式包装']"))点击();
//点击下一步按钮公司信息
driver.FindElement(By.XPath(" // div [@ class ='next-btn'] / button / span [@ class ='mat - 按钮-包装']"))点击();
//输入强制性详细信息

driver.FindElement(By.Id(" md-input-46"))。SendKeys(" Test Company3");
driver.FindElement(By.Id(" md-input-47"))。SendKeys("");
driver.FindElement(By.Id(" md-input-7"))。SendKeys("");

var elem = driver.FindElement(By.XPath(" .//* [@ Id ='md-option-193']"));
((IJavaScriptExecutor)驱动程序).ExecuteScript(" arguments [0] .scrollIntoView(true);",elem);


//公开公司名单
driver.FindElement(By.XPath(" .//* [@ Id ='md-tab-content-0-1' ] / DIV / APP-公司实体外形帐户/形式/ DIV / MD-卡/ MD-卡内容/ DIV / DIV [2] / DIV [4] / MD-选择/ DIV /跨度[1] "))点击();
//从列表中选择
driver.FindElement(By.XPath(" .//* [@ Id ='md-option-193']"))。点击();

driver.FindElement(By.XPath(" // input [@ placeholder ='Company Size']"))。SendKeys(" 1");
//向上滚动页面以查看下一步按钮

var elem1 = driver.FindElement(By.XPath(" // div [@ class ='next-btn'] / button" ));
((IJavaScriptExecutor)驱动程序).ExecuteScript(" arguments [0] .scrollIntoView(true);",elem1);

//单击下一步按钮
driver.FindElement(By.XPath(" // div [@ class ='next-btn'] / button"))。点击() ;

driver.FindElement(By.XPath(" // div [@ class ='next-btn'] / button"))。Click();

driver.FindElement(By.XPath(" // div [@ class ='user-button-container'] // button"))。Click();
driver.FindElement(By.XPath(" // div [@ class ='list'] / a / span"))。Click();


}

[TearDown]
public void CleanUp()
{
driver.Close();

}

}



}


您好,


我使用上面的代码运行测试用例。


它使用Mozilla firefox驱动程序启动浏览器并运行测试用例。它在本地环境中工作正常。


我在Visual Studio中设置了一个项目,用于运行测试用例。

检查更改并运行后在服务器上构建它失败以下错误。


 2017-11-08T14:17:05.5597438Z# #[section]开始:VsTest  -  testAssemblies 
2017-11-08T14:17:05.5607443Z =========================== ================================================== =
2017-11-08T14:17:05.5607443Z任务:Visual Studio测试
2017-11-08T14:17:05.5607443Z描述:使用Visual Studio测试运行器运行测试
2017-11 -08T14:17:05.5607443Z版本:1.0.86
2017-11-08T14:17:05.5607443Z作者:Microsoft Corporation
2017-11-08T14:17:05.5607443Z帮助:[更多信息] (https://go.microsoft.com/fwlink/?LinkId=624539)
2017-11-08T14:17:05.5607443Z ================== ================================================== ==========
2017-11-08T14:17:05.5677 442Z准备任务执行处理程序。
2017-11-08T14:17:10.6229413Z执行powershell脚本:d:\\\ tasks \ VSTest_ef087383-ee5e-42c7-9a53-ab56c98420f9 \1.0.86 \ VSTest.ps1
2017-11-08T14:17:11.2058029Z测试容器:'REGISTRY :: HKEY_CLASSES_ROOT\CLSID\ {177F0C4A-1CD3-4DE7-A32C-71DBBB9FA36D}'
2017-11-08T14:17:11.2058029 Z
2017-11-08T14:17:11.2058029Z
2017-11-08T14:17:11.2068033Z存在。
2017-11-08T14:17:11.2068033Z
2017-11-08T14:17:11.2068033Z
2017-11-08T14:17:11.2078030Z添加Visual Studio设置助手。
2017-11-08T14:17:11.2078030Z
2017-11-08T14:17:11.2078030Z
2017-11-08T14:17:12.9120902Z获取Visual Studio设置实例。
2017-11-08T14:17:12.9120902Z
2017-11-08T14:17:12.9120902Z
2017-11-08T14:17:12.9691976Z找到1个实例。
2017-11-08T14:17:12.9691976Z
2017-11-08T14:17:12.9691976Z
2017-11-08T14:17:12.9791938Z
2017-11- 08T14:17:12.9791938Z
2017-11-08T14:17:12.9791938Z描述:Microsoft DevOps生产力和协调解决方案
2017-11-08T14:17:12.9791938Z跨越任何规模的团队
2017-11-08T14:17:12.9791938Z DisplayName:Visual Studio Enterprise 2017
2017-11-08T14:17:12.9791938Z Id:9ae0c8de
2017-11-08T14:17:12.9791938Z InstallDate :System.Runtime.InteropServices.ComTypes.FILETIME
2017-11-08T14:17:12.9791938Z名称:VisualStudio / 15.4.0 + 27004.2002
2017-11-08T14:17:12.9791938Z路径:C :\ Program Files(x86)\ Microsoft Visual Studio\2017\Enterprise
2017-11-08T14:17:12.9791938Z版本:15.4.27004.2002
2017-11-08T14:17: 12.9791938Z VersionString:15.4.27004.2002
2017-11-08T14:17:12.9791938Z
2017-11-08T14:17:12.9791938Z
2017-11-08T14:1 7:12.9791938Z
2017-11-08T14:17:12.9791938Z
2017-11-08T14:17:12.9791938Z
2017-11-08T14:17:12.9791938Z
2017-11-08T14:17:13.0141743Z测试叶:'C:\程序文件(x86)\ Microsoft Visual Studio \\\ 2017 \ Enterprise> \\ Common7 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\ 。
2017-11-08T14:17:13.0141743Z
2017-11-08T14:17:13.0141743Z
2017-11-08T14:17:13.0441735Z工作文件夹:d:\ a \ 3 \ $
2017-11-08T14:17:13.0451744Z正在执行C:\Program Files(x86)\ Microsoft Visual Studio \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \微软\ TestWindow \vstest.console.exe" d:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ / logger:trx / TestAdapterPath:" d:\\\\\\
2017-11-08T14:17:13.1891790Z Microsoft(R)测试执行命令行工具版本15.0.26929.2
2017-11-08T14:17:13.1891790Z版权所有(c)Microsoft Corporation。版权所有。
2017-11-08T14:17:13.1891790Z
2017-11-08T14:17:13.3861840Z开始执行测试,请稍候......
2017-11-08T14:17:13.7781939 Z信息:NUnit Adapter 3.8.0.0:测试执行开始
2017-11-08T14:17:13.7781939Z
2017-11-08T14:17:13.7841950Z信息:在d:\中运行所有测试a\3 \\\\SeleniumDemo \bin\Release\SeleniumDemo.dll
2017-11-08T14:17:13.7841950Z
2017-11-08T14:17:14.5634791Z :NUnit3TestExecutor转换2个NUnit测试用例中的2个
2017-11-08T14:17:14.5634791Z
2017-11-08T14:17:14.6964825Z ## [错误] 1510150634694 geckodriver INFO geckodriver 0.19.0
2017-11-08T14:17:14.7024852Z ## [错误] 1510150634702 geckodriver INFO收听127.0.0.1:1633
2017-11-08T14:17:15.9798279Z ## [错误] 1510150635971 geckodriver INFO geckodriver 0.19.0
2017-11-08T14:17:15.9798279Z ## [错误] 1510150635978 geckodriver INFO收听127.0.0.1:1638
2017-11-08T14:17:16.7230900Z测试失败3V erifyLoginFunctionality
2017-11-08T14:17:16.7240900Z错误消息:
2017-11-08T14:17:16.7240900Z OpenQA.Selenium.WebDriverException:预期的浏览器二进制位置,但无法在默认情况下找到二进制文件location,没有提供'moz:firefoxOptions.binary'功能,并且在命令行上没有设置二进制标志
2017-11-08T14:17:16.7240900Z TearDown:System.NullReferenceException:对象引用未设置为实例一个东西。
2017-11-08T14:17:16.7240900Z Stack Trace:
2017-11-08T14:17:16.7250904Z at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
2017 -11-08T14:17:16.7250904Z at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute,Dictionary`2 parameters)
2017-11-08T14:17:16.7250904Z at OpenQA.Selenium.Remote.RemoteWebDriver .StartSession(ICapabilities desiredCapabilities)
2017-11-08T14:17:16.7250904Z在OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor,ICapabilities desiredCapabilities)
2017-11-08T14:17: 16.7250904Z在OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxOptions选项)
2017-11-08T14:17:16.7250904Z在SeleniumDemo.LoginInApplication.initialize()中d:\\\\ s\SeleniumDemo \UnitTest1.cs:第28行
2017-11-08T14:17:16.7250904Z - TelenDown
2017-11-08T14:17:16.7250904Z在SeleniumDemo.LoginInApplication.CleanUp( )在d:\ a \\\\\SeleniumDemo \UnitTest1.cs:第183行
2017-11-08T14:17:17.0199680Z信息:NUnit适配器3.8.0.0:测试执行完成
2017-11-08T14 :17:17.0199680Z
2017-11-08T14:17:17.0299693Z失败的测试4VerifyUserForgotPassword
2017-11-08T14:17:17.0299693Z错误消息:
2017-11-08T14:17: 17.0299693Z OpenQA.Selenium.WebDriverException:预期的浏览器二进制位置,但无法在默认位置找到二进制文件,没有提供'moz:firefoxOptions.binary'功能,并且在命令行上没有设置二进制标志
2017-11- 08T14:17:17.0299693Z TearDown:System.NullReferenceException:对象引用未设置为对象的实例。
2017-11-08T14:17:17.0299693Z Stack Trace:
2017-11-08T14:17:17.0299693Z at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
2017 -11-08T14:17:17.0299693Z在OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute,Dictionary`2 parameters)
2017-11-08T14:17:17.0299693Z at OpenQA.Selenium.Remote.RemoteWebDriver .StartSession(ICapabilities desiredCapabilities)
2017-11-08T14:17:17.0299693Z at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor,ICapabilities desiredCapabilities)
2017-11-08T14:17: 17.0299693Z在OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxOptions options)
2017-11-08T14:17:17.0299693Z at SeleniumDemo.LoginInApplication.initialize()in d:\\\\ s\SeleniumDemo\UnitTest1.cs:第28行
2017-11-08T14:17:17.0299693Z - TelenDown
2017-11-08T14:17:17.0299693Z在SeleniumDemo.LoginInApplication.CleanUp( )在d:\ a \\\\\SeleniumDemo \UnitTest1.cs:第183行
2017-11-08T14:17:17.0802693Z结果文件:d:\\\\\\\TestResults\buildguest_factoryvm -az183 2017-11-08 14_17_16.trx
2017-11-08T14:17:17.0821182Z
2017-11-08T14:17:17.0821182Z总测试:2。通过:0。失败:2 。跳过:0。
2017-11-08T14:17:17.0821182Z ## [错误]测试运行失败。
2017-11-08T14:17:17.0831183Z测试执行时间:3.4303秒
2017-11-08T14:17:24.4575066Z ## [错误] System.Exception:VSTest测试运行失败,退出代码:1
2017-11-08T14:17:24.4790947Z发布测试结果...
2017-11-08T14:17:25.1277305Z测试结果剩余:2
2017-11-08T14 :17:25.3474769Z发布测试运行:https://tarundabas.visualstudio.com/SeleniumAutomationProject/_TestManagement/Runs#runId=9&_a=runCharts
2017-11-08T14:17:25.3775740Z ## [错误] PowerShell脚本完成了1个错误。
2017-11-08T14:17:25.3788393Z ## [section] Finishing:VsTest - testAssemblies


期待及时回复。

解决方案

您好Tarun,


您使用Hosted构建代理吗?或私有构建代理?


Selenium测试通常会以交互方式运行,这在Hosted构建控制器上会失败。所以你需要

部署Windows版本代理
以交互方式运行。


此外,您需要使用
Visual Studio测试代理部署

运行功能测试
任务以运行selenium测试。


详细的信息,请参阅链接如下:


https: //docs.microsoft.com/en-us/vsts/build-release/test/continuous-test-selenium


祝你好运,


using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Remote;
using static OpenQA.Selenium.IAlert;
using NUnit.Framework;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.Support.UI;
using System.IO;
using System.Reflection;

namespace SeleniumDemo
{
    [TestClass]
    public class LoginInApplication
    {
        public RemoteWebDriver driver;

        [SetUp]
        public void initialize()
        {
           // var executingPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
           // FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(executingPath);
           // service.FirefoxBinaryPath = String.Format(@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe");
            driver = new FirefoxDriver();
            driver.Manage().Window.Maximize();
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(60));

        }

        //==============================================================================
        [Test]
        public void Test3VerifyLoginFunctionality()
        {

            driver.Navigate().GoToUrl("http://alcamIdev.vdev.digitalmettle.com");
            //Enter UserName
            driver.FindElement(By.Id("md-input-1")).Clear();
            driver.FindElement(By.Id("md-input-1")).Click();
            driver.FindElement(By.Id("md-input-1")).SendKeys("");

            //Enter Password
            driver.FindElement(By.Id("md-input-3")).Clear();
            driver.FindElement(By.Id("md-input-3")).Click();
            driver.FindElement(By.Id("md-input-3")).SendKeys("");

            //Click On Button For Login
            driver.FindElement(By.XPath("//div[@class='user-btn-wrapper']/div/button/span[@class='mat-button-wrapper']")).Click();
            // Click On Agree Button
            System.Threading.Thread.Sleep(10000);




        }

        //==============================================================================


        public void Test1VerifyNewUserRegisterInApplication()
        {

            driver.Navigate().GoToUrl("http://alcamIdev.vdev.digitalmettle.com");
            //Open register screen
            driver.FindElement(By.XPath("//div[@class='extra-options']/div[@class='sign-up-link']/a")).Click();
            driver.FindElement(By.Id("md-input-5")).Click();
            //Enter email Id
            driver.FindElement(By.Id("md-input-5")).SendKeys("");
            //Enter First Name
            driver.FindElement(By.Id("md-input-7")).SendKeys("Tarun");
            //Enter Last Name
            driver.FindElement(By.Id("md-input-9")).SendKeys("Dabas");
            //Enter Password 
            driver.FindElement(By.Id("md-input-11")).SendKeys("");
            //Enter Confirm Password 
            driver.FindElement(By.Id("md-input-13")).SendKeys("");
            //Enter Mobile Number
            driver.FindElement(By.Id("md-input-15")).SendKeys("9999999986");
            //Accept Checkbox 

            var elem = driver.FindElement(By.XPath("//div[@class='register-content']//button[@class='mat-raised-button mat-primary']"));
            ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", elem);

            driver.FindElement(By.XPath("//md-checkbox/label/div[@class='mat-checkbox-inner-container']//div[2]")).Click();
            // Click On Register Button And After Confirmation Alert Will Display

            driver.FindElement(By.XPath("//div[@class='register-content']//button[@class='mat-raised-button mat-primary']")).Click();


            System.Threading.Thread.Sleep(30000);

        }

        //==============================================================================


        public void Test2VerifyNewUserEmail()
        {

            driver.Navigate().GoToUrl("https://www.mailinator.com");
            driver.FindElement(By.XPath("//div[@class='input-group']/input[@Id='inboxfield']")).SendKeys("digitalmettle50@mailinator.com");
            driver.FindElement(By.XPath("//span[@class='input-group-btn']/button")).Click();
            driver.FindElement(By.XPath("//div[@class='all_message-min']/div[3]")).Click();
            driver.SwitchTo().Frame("msg_body");
            driver.FindElement(By.XPath("//a[starts-with(@href,'http://alcamidev.vdev.digitalmettle.com')]")).Click();
            System.Threading.Thread.Sleep(30000);

        }


        //==============================================================================

        [Test]
        public void Test4VerifyUserForgotPassword()
        {
            driver.Navigate().GoToUrl("http://alcamIdev.vdev.digitalmettle.com");
            driver.FindElement(By.XPath("//div[@class='extra-options']/div[1]/a")).Click();
            driver.FindElement(By.XPath("//div[@class='mat-input-infix']/input")).SendKeys("digitalmettle50@mailinator.com");
            driver.FindElement(By.XPath("//div[@class='forgot-content']/button[@class='forgot-btn mat-raised-button mat-primary']")).Click();
            System.Threading.Thread.Sleep(10000);

        }

        //==============================================================================


        public void Test5VerifyUpdateUserDetails()
        {
            //Open Website
            driver.Navigate().GoToUrl("http://alcamIdev.vdev.digitalmettle.com");
            //Enter UserName
            driver.FindElement(By.Id("md-input-1")).Clear();
            driver.FindElement(By.Id("md-input-1")).Click();
            driver.FindElement(By.Id("md-input-1")).SendKeys("");

            //Enter Password
            driver.FindElement(By.Id("md-input-3")).Clear();
            driver.FindElement(By.Id("md-input-3")).Click();
            driver.FindElement(By.Id("md-input-3")).SendKeys("");

            //Click On Button For Login
            driver.FindElement(By.XPath("//div[@class='user-btn-wrapper']/div/button/span[@class='mat-button-wrapper']")).Click();
            //Click on Next button On Company Info
            driver.FindElement(By.XPath("//div[@class='next-btn']/button/span[@class='mat-button-wrapper']")).Click();
            //Enter mandatory Details 

            driver.FindElement(By.Id("md-input-46")).SendKeys("Test Company3");
            driver.FindElement(By.Id("md-input-47")).SendKeys("");
            driver.FindElement(By.Id("md-input-7")).SendKeys("");

            var elem = driver.FindElement(By.XPath(".//*[@Id='md-option-193']"));
            ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", elem);


            //Open Company List
            driver.FindElement(By.XPath(".//*[@Id='md-tab-content-0-1']/div/app-company-entity-form-account/form/div/md-card/md-card-content/div/div[2]/div[4]/md-select/div/span[1]")).Click();
            //Select From List
            driver.FindElement(By.XPath(".//*[@Id='md-option-193']")).Click();

            driver.FindElement(By.XPath("//input[@placeholder='Company Size']")).SendKeys("1");
            // Scroll up page for checking Next button 

            var elem1 = driver.FindElement(By.XPath("//div[@class='next-btn']/button"));
            ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", elem1);

            //Click On Next Button
            driver.FindElement(By.XPath("//div[@class='next-btn']/button")).Click();

            driver.FindElement(By.XPath("//div[@class='next-btn']/button")).Click();

            driver.FindElement(By.XPath("//div[@class='user-button-container']//button")).Click();
            driver.FindElement(By.XPath("//div[@class='list']/a/span")).Click();


        }

        [TearDown]
        public void CleanUp()
        {
            driver.Close();

        }

    }



}


Hi,

I am using above code to run test case.

It uses Mozilla firefox driver to launch browser and run test case. It works fine in local environment.

I have set up a project in Visual Studio online that is build to run test case.
After checkin the changes and running build on server it fails below error.

2017-11-08T14:17:05.5597438Z ##[section]Starting: VsTest - testAssemblies
2017-11-08T14:17:05.5607443Z ==============================================================================
2017-11-08T14:17:05.5607443Z Task         : Visual Studio Test
2017-11-08T14:17:05.5607443Z Description  : Run tests with Visual Studio test runner
2017-11-08T14:17:05.5607443Z Version      : 1.0.86
2017-11-08T14:17:05.5607443Z Author       : Microsoft Corporation
2017-11-08T14:17:05.5607443Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=624539)
2017-11-08T14:17:05.5607443Z ==============================================================================
2017-11-08T14:17:05.5677442Z Preparing task execution handler.
2017-11-08T14:17:10.6229413Z Executing the powershell script: d:\a\_tasks\VSTest_ef087383-ee5e-42c7-9a53-ab56c98420f9\1.0.86\VSTest.ps1
2017-11-08T14:17:11.2058029Z Testing container: 'REGISTRY::HKEY_CLASSES_ROOT\CLSID\{177F0C4A-1CD3-4DE7-A32C-71DBBB9FA36D}'
2017-11-08T14:17:11.2058029Z 
2017-11-08T14:17:11.2058029Z 
2017-11-08T14:17:11.2068033Z Exists.
2017-11-08T14:17:11.2068033Z 
2017-11-08T14:17:11.2068033Z 
2017-11-08T14:17:11.2078030Z Adding Visual Studio setup helpers.
2017-11-08T14:17:11.2078030Z 
2017-11-08T14:17:11.2078030Z 
2017-11-08T14:17:12.9120902Z Getting Visual Studio setup instances.
2017-11-08T14:17:12.9120902Z 
2017-11-08T14:17:12.9120902Z 
2017-11-08T14:17:12.9691976Z Found 1 instances.
2017-11-08T14:17:12.9691976Z 
2017-11-08T14:17:12.9691976Z 
2017-11-08T14:17:12.9791938Z 
2017-11-08T14:17:12.9791938Z 
2017-11-08T14:17:12.9791938Z Description   : Microsoft DevOps solution for productivity and coordination 
2017-11-08T14:17:12.9791938Z                 across teams of any size
2017-11-08T14:17:12.9791938Z DisplayName   : Visual Studio Enterprise 2017
2017-11-08T14:17:12.9791938Z Id            : 9ae0c8de
2017-11-08T14:17:12.9791938Z InstallDate   : System.Runtime.InteropServices.ComTypes.FILETIME
2017-11-08T14:17:12.9791938Z Name          : VisualStudio/15.4.0+27004.2002
2017-11-08T14:17:12.9791938Z Path          : C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise
2017-11-08T14:17:12.9791938Z Version       : 15.4.27004.2002
2017-11-08T14:17:12.9791938Z VersionString : 15.4.27004.2002
2017-11-08T14:17:12.9791938Z 
2017-11-08T14:17:12.9791938Z 
2017-11-08T14:17:12.9791938Z 
2017-11-08T14:17:12.9791938Z 
2017-11-08T14:17:12.9791938Z 
2017-11-08T14:17:12.9791938Z 
2017-11-08T14:17:13.0141743Z Testing leaf: 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe'
2017-11-08T14:17:13.0141743Z 
2017-11-08T14:17:13.0141743Z 
2017-11-08T14:17:13.0141743Z Exists.
2017-11-08T14:17:13.0141743Z 
2017-11-08T14:17:13.0141743Z 
2017-11-08T14:17:13.0441735Z Working folder: d:\a\3\s
2017-11-08T14:17:13.0451744Z Executing C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe "d:\a\3\s\SeleniumDemo\bin\Release\SeleniumDemo.dll"  /logger:trx /TestAdapterPath:"d:\a\3\s"
2017-11-08T14:17:13.1891790Z Microsoft (R) Test Execution Command Line Tool Version 15.0.26929.2
2017-11-08T14:17:13.1891790Z Copyright (c) Microsoft Corporation.  All rights reserved.
2017-11-08T14:17:13.1891790Z 
2017-11-08T14:17:13.3861840Z Starting test execution, please wait...
2017-11-08T14:17:13.7781939Z Information: NUnit Adapter 3.8.0.0: Test execution started
2017-11-08T14:17:13.7781939Z 
2017-11-08T14:17:13.7841950Z Information: Running all tests in d:\a\3\s\SeleniumDemo\bin\Release\SeleniumDemo.dll
2017-11-08T14:17:13.7841950Z 
2017-11-08T14:17:14.5634791Z Information: NUnit3TestExecutor converted 2 of 2 NUnit test cases
2017-11-08T14:17:14.5634791Z 
2017-11-08T14:17:14.6964825Z ##[error]1510150634694	geckodriver	INFO	geckodriver 0.19.0
2017-11-08T14:17:14.7024852Z ##[error]1510150634702	geckodriver	INFO	Listening on 127.0.0.1:1633
2017-11-08T14:17:15.9798279Z ##[error]1510150635971	geckodriver	INFO	geckodriver 0.19.0
2017-11-08T14:17:15.9798279Z ##[error]1510150635978	geckodriver	INFO	Listening on 127.0.0.1:1638
2017-11-08T14:17:16.7230900Z Failed   Test3VerifyLoginFunctionality
2017-11-08T14:17:16.7240900Z Error Message:
2017-11-08T14:17:16.7240900Z    OpenQA.Selenium.WebDriverException : Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
2017-11-08T14:17:16.7240900Z TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
2017-11-08T14:17:16.7240900Z Stack Trace:
2017-11-08T14:17:16.7250904Z    at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
2017-11-08T14:17:16.7250904Z    at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
2017-11-08T14:17:16.7250904Z    at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
2017-11-08T14:17:16.7250904Z    at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
2017-11-08T14:17:16.7250904Z    at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxOptions options)
2017-11-08T14:17:16.7250904Z    at SeleniumDemo.LoginInApplication.initialize() in d:\a\3\s\SeleniumDemo\UnitTest1.cs:line 28
2017-11-08T14:17:16.7250904Z --TearDown
2017-11-08T14:17:16.7250904Z    at SeleniumDemo.LoginInApplication.CleanUp() in d:\a\3\s\SeleniumDemo\UnitTest1.cs:line 183
2017-11-08T14:17:17.0199680Z Information: NUnit Adapter 3.8.0.0: Test execution complete
2017-11-08T14:17:17.0199680Z 
2017-11-08T14:17:17.0299693Z Failed   Test4VerifyUserForgotPassword
2017-11-08T14:17:17.0299693Z Error Message:
2017-11-08T14:17:17.0299693Z    OpenQA.Selenium.WebDriverException : Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
2017-11-08T14:17:17.0299693Z TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
2017-11-08T14:17:17.0299693Z Stack Trace:
2017-11-08T14:17:17.0299693Z    at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
2017-11-08T14:17:17.0299693Z    at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
2017-11-08T14:17:17.0299693Z    at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
2017-11-08T14:17:17.0299693Z    at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
2017-11-08T14:17:17.0299693Z    at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxOptions options)
2017-11-08T14:17:17.0299693Z    at SeleniumDemo.LoginInApplication.initialize() in d:\a\3\s\SeleniumDemo\UnitTest1.cs:line 28
2017-11-08T14:17:17.0299693Z --TearDown
2017-11-08T14:17:17.0299693Z    at SeleniumDemo.LoginInApplication.CleanUp() in d:\a\3\s\SeleniumDemo\UnitTest1.cs:line 183
2017-11-08T14:17:17.0802693Z Results File: d:\a\3\s\TestResults\buildguest_factoryvm-az183 2017-11-08 14_17_16.trx
2017-11-08T14:17:17.0821182Z 
2017-11-08T14:17:17.0821182Z Total tests: 2. Passed: 0. Failed: 2. Skipped: 0.
2017-11-08T14:17:17.0821182Z ##[error]Test Run Failed.
2017-11-08T14:17:17.0831183Z Test execution time: 3.4303 Seconds
2017-11-08T14:17:24.4575066Z ##[error]System.Exception: VSTest Test Run failed with exit code: 1
2017-11-08T14:17:24.4790947Z Publishing Test Results...
2017-11-08T14:17:25.1277305Z Test results remaining: 2
2017-11-08T14:17:25.3474769Z Published Test Run : https://tarundabas.visualstudio.com/SeleniumAutomationProject/_TestManagement/Runs#runId=9&_a=runCharts
2017-11-08T14:17:25.3775740Z ##[error]PowerShell script completed with 1 errors.
2017-11-08T14:17:25.3788393Z ##[section]Finishing: VsTest - testAssemblies

Looking forward to a prompt reply.

解决方案

Hi Tarun,

Do you use Hosted build agent or private build agent?

Selenium tests will generally be run interactively, which would fail on the Hosted build controller. So you need to deploy a Windows build agent to run interactively.

Also, instead of using VS test task, you need to use Visual Studio Test Agent Deployment, and Run Functional Tests task to run selenium tests.

Detailed inforamtion, please refer to the link below:

https://docs.microsoft.com/en-us/vsts/build-release/test/continuous-test-selenium

Best regards,


这篇关于无法在Visual Studio Online上运行Selenium测试用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆