![](/img/trans.png)
[英]Selenium tests(in C#) failing when run from the command line but not VS
[英]C# Selenium WebDriver tests failing when run consecutively but succeeding when run individually
所以我有一個.feature文件,其中我添加了4個方案。
.feature文件
Feature: BleKeys beheren
Het beheren van BLE-keys
d.m.v. de WebInterface.
@notfs
Scenario: BLE-key toevoegen aan database
Given I'm at the BleKey/Create page.
And I have entered acceptable BLE-data.
When I press Create
Then The BLE-key should be added to the database.
@notfs
Scenario: BLE-key data aanpassen
Given There is a BleKey in the database.
And I'm at the BleKey/Edit page of that BleKey
When I edit the MAC-Adress
And I edit the Conditional Report
And I edit the Flag
And I edit the Distance
And I edit the Reference
And I edit the ExtraCfg
And I press Save
Then The BleKey should have changed correctly.
@notfs
Scenario: BLE-key data verwijderen
Given There is a BleKey in the database.
And I navigate to the Delete page of that BleKey
When I press Delete
Then The BleKey should be deleted.
@notfs
Scenario: BLE-key data van 1 sleutel bekijken
Given There is a BleKey in the database.
And I navigate to the Details page of that BleKey
Then The correct data of that BleKey should be displayed
現在,當我在Visual Studio(ReSharper單元測試會話窗口)中單獨運行這些測試時,它們都會成功,但是當連續運行時,第一個成功但任何連續測試都會失敗並出現以下異常:
OpenQA.Selenium.WebDriverException:意外錯誤。 System.Net.WebException:無法連接到遠程服務器---> System.Net.Sockets.SocketException:無法建立連接,因為目標計算機主動拒絕它127.0.0.1:5595
正如您所看到的,測試嘗試連接到某個本地IP地址,同時應該導航到以下基本URL:
http:// localhost:58759 / + controller +方法取決於測試。
我在我的步驟文件中創建了WebDriver實例。 像這樣:
public class BleKeyBeherenSteps
{
public static RemoteWebDriver RemoteWebDriver = new ChromeDriver();
public WebinterfaceSelenium SeleniumTest = new
WebinterfaceSelenium(RemoteWebDriver);
public Navigate Navigate = new Navigate(RemoteWebDriver);
public Check Check = new Check(RemoteWebDriver);
public Edit Edit = new Edit(RemoteWebDriver);
public Delete Delete = new Delete(RemoteWebDriver);
private readonly BeheerContext _db = new BeheerContext();
}
在我的方法中,我像這樣導航:
Driver.Navigate().GoToUrl(Adress + BleKeyIndexUrl);
Adress =“ http:// localhost:58759 / ”
和BleKeyIndexUrl =“BleKeys / Index”
因此,由於某種原因,WebDriver導航到本地IP地址而不是localhost地址。
編輯:每次測試后我都關閉驅動程序:Driver.Quit(); 我的猜測是,由於某種原因,在第一次測試后,Driver.Url屬性丟失了。
不要擔心localhost對IP地址的歧義,localhost通常會解析為127.0.0.1。
連續單元測試失敗通常是由於在應用程序代碼中使用靜態聲明引起的。 我今天早上處理了這個問題,我不得不在每個單元測試開始時在我的應用程序中重置一個麻煩的靜態變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.