2017-05-22 9 views
0

거의 자동화 테스트가 시작되었으므로 명확히 할 수 없으면 사과하고 싶습니다.Selenium 및 NUnit을 사용한 UI 자동화 테스트 실행

그래서, 자동화에 대한 블로그를 읽는의 2 주 후에, 나는 UI 자동화를위한 셀레늄 WebdriverNUNIT를 사용하기로 결정했습니다.

내 응용 프로그램은 3 년 동안 개발 중이다. 프로젝트 및 포트폴리오 관리 시스템입니다.

나는 수백 페이지가 있으며 그 중 약 50 %는 CRUD 작업을 수행합니다.

[ 
    { 
    "Name": "Finance", 
    "Description": "division with complete test data", 
    "Color": "#ff0000", 
    "ExpectedStatus": { 
     "WillBeAdded": true, 
     "WillBeDeleted": true, 
     "WillBeUpdated": true 
    }, 
    "PerformableActions": { 
     "ShouldAdd": true, 
     "ShouldDelete": false, 
     "ShouldUpdate": true 
    } 
    }, 
    { 
    "Name": "IT", 
    "Description": "IT projects", 
    "Color": "pink", 
    "ExpectedStatus": { 
     "WillBeAdded": true, 
     "WillBeDeleted": true, 
     "WillBeUpdated": true 
    }, 
    "PerformableActions": { 
     "ShouldAdd": true, 
     "ShouldDelete": false, 
     "ShouldUpdate": true 
    } 
    }, 
    { 
    "Name": "Business", 
    "Description": "division with name and color name", 
    "Color": "yellow", 
    "ExpectedStatus": { 
     "WillBeAdded": true, 
     "WillBeDeleted": true, 
     "WillBeUpdated": true 
    }, 
    "PerformableActions": { 
     "ShouldAdd": true, 
     "ShouldDelete": false, 
     "ShouldUpdate": true 
    } 
    }, 
    { 
    "Name": "", 
    "Description": "division without name and color name, should add white color", 
    "Color": "", 
    "ExpectedStatus": { 
     "WillBeAdded": true, 
     "WillBeDeleted": true, 
     "WillBeUpdated": true 
    }, 
    "PerformableActions": { 
     "ShouldAdd": true, 
     "ShouldDelete": true, 
     "ShouldUpdate": true 
    } 
    }, 
    { 
    "Name": "", 
    "Description": "without name and color name and will not be added", 
    "Color": "black", 
    "ExpectedStatus": { 
     "WillBeAdded": false, 
     "WillBeDeleted": false, 
     "WillBeUpdated": false 
    }, 
    "PerformableActions": { 
     "ShouldAdd": true, 
     "ShouldDelete": false, 
     "ShouldUpdate": false 
    } 
    } 
] 

내가 : 나는 형식을 다음 JSON으로 테스트 데이터를 사용하여 내보기 모델이 데이터를 가져 오지하고

Project structure

:

나는 내 응용 프로그램에 대해 다음 strucutre 결정 여기에 두 가지를 사용 :

1. PerformableActions 즉 무엇 이 테스트 사례 데이터를 사용하여 수행 할 수있는 작업. 예 : shouldAdd는 레코드 추가를 위해이 TestCase를 수행해야 함을 의미하며 shouldDelete는 레코드를 삭제하기 위해이 testCase를 실행해야 함을 의미합니다. 마찬가지로 shouldUpdate가 실행됩니다.

2 ExpectedStatus 즉 테스트 케이스의 예상 결과, WillBeAdded 수단이 데이터 그리드에 추가 될 수 무슨. 마찬가지로 WillBeDeleted 및 WillBeUpdated 작업.

질문 :

1) 나는 모든 CUD 작업에 동일한 테스트 데이터를 사용하고, 그 이유는 내가 내 응용 프로그램에서 CUD의 흐름을 유지해야한다는 것입니다. UI를 테스트 할 필요가 있기 때문에 Create, Retrieve 및 Delete가 순서대로 작동한다고 가정하고 있습니다.

CRUD 작업의 경우 테스트를 수행하는 올바른 방법입니까?

2) 내가 유일하게 가능한 방법으로 주문 속성을 사용하는 것입니다 볼 수 있기 때문에 나는, 질서를 유지 할 방법이 수백 또는 수천 될 수있다, 나는 내 프로젝트의 모든 테스트를 실행해야한다는 생각 NUNit. 어떻게 그것을 사용할 수 있습니까? 아니면 독립적 인 모듈과 종속 모듈의 그룹을 별도로 테스트 할 수 있습니까?

답변

1
  1. 아무런 문제가 없습니다. 각각의 경우에 대해 함수를 생성하고 C, U 및 D를 원하는 순서대로 만들 수 있습니다. 어쩌면 당신은 그들 사이에 wait을 추가해야합니다.
  2. NUnit을 사용한 OrderAttribute는 더 나은 방법이있을지라도 충분히 훌륭하게 작동합니다. 또한 테스트 케이스 목록을 만들고 순서대로 실행할 수 있습니다. 왜 안돼? 자신을 클래스와 메소드로 제한하지 마십시오.
  3. 나는 당신의 질문에 C#으로 태그를 붙 였지만,이 작업량에 대해서는 아마도 지금 가지고있는 것보다 다른 라이브러리를 살펴볼 가치가있을 것입니다. 약간의 학습의 당신을 두려워하지, 당신은 F 번호를 즐길 수 있습니다 경우 Expecto

    • 당신은 당신이 Canopy
    • 당신이 셀레늄을위한 좋은 DSL을 실행하는 순서와 어떤 테스트에서 완벽하게 제어 할 수 있습니다. 예를 들어 starter kit입니다. 그리고 당신은 헤드리스 (headless) 모드
    • 에 크롬으로 docker에서 실행도 할 수 있고 심지어 Json Type Provider

UPDATE와 JSON 테스트 정의에 대한 인텔리 센스를 얻을 수 있습니다 : 당신이를 정의 할 수 있습니다 주문에 대한 자신의 속성을 사용하거나 심지어 NUnit에서 기존을 사용하고 올바른 순서로 리플렉션마다 메소드를 호출하십시오. 또는 테스트 용으로 자체 DSL을 정의하고 목록을 탐색하여 필요한 정보를 추출 할 수 있습니다.

public struct CRUD 
{ 
    public bool C; 
    public bool R; 
    public bool U; 
    public bool D; 
    public CRUD(bool c, bool r, bool u, bool d) 
    { 
     this.C = c; 
     this.R = r; 
     this.U = u; 
     this.D = d; 
    } 
} 
public enum ActionKind 
{ 
    Create, 
    Read, 
    Update, 
    Delete 
} 
public struct TestResult 
{ 
    public ActionKind Action; 
    public bool IsPerformed; 
} 
public class TestCase 
{ 
    public string Name { get; set; } 
    public string Description { get; set; } 
    public string Color { get; set; } 
    public CRUD Action { get; set; } 
    public List<TestResult> Actual { get; set; } 
    public List<TestResult> Expected { get; set; } // or List<TestResult> 

} 
public class Tests 
{ 
    public void TestAListOfCases() 
    { 
     var cases = new List<TestCase> 
     { 
      new TestCase { Name = "Finance", Description = "division with complete test data", Color = "#ff0000", 
       Expected = new List<TestResult> {new TestResult {Action = ActionKind.Create, IsPerformed = true }, 
               new TestResult {Action = ActionKind.Update, IsPerformed = false}, 
               new TestResult {Action = ActionKind.Delete, IsPerformed = true } 
       }}, 
      new TestCase { Name = "IT", Description = "Description"} 
     }; 

     cases 
      .Where(x => x.Name == "IT") 
      .Where(x => x.Color != "pink") 
      .Select(RunTestCase) 
      .Where(x => !x.Item2) 
      .Select(x => OutputFailedTestCase(x.Item1)); // boah c# is verbose 
    } 
    public Tuple<TestCase, bool> RunTestCase(TestCase testCase) 
    { 
     foreach(var exp in testCase.Expected) 
     { 
      switch (exp.Action) { 
       case ActionKind.Delete: 
        // do delete if needed and create actual result 
        var actual = exp.IsPerformed 
         ? new TestResult { Action = exp.Action, IsPerformed = true } 
         : new TestResult { Action = exp.Action, IsPerformed = false }; 
        break; 

      } 
     } 
     var isFailed = 
      Enumerable.Zip(
       testCase.Actual, 
       testCase.Expected, 
       (expected, actual) => expected.Action == actual.Action && expected.IsPerformed == actual.IsPerformed) 
      .All(x=>x); 
     // your selenium stuff 
     return Tuple.Create(testCase, isFailed); 
    } 
    public bool OutputFailedTestCase(TestCase testCase) 
    { 
     // write to console or do something else 
     Console.Write($"{testCase.Name} is failed to perform following actions: {calculateFailedActions}"); 
     return true; 
    } 
} 
+0

감사합니다. 누군가 내 문제를 들여다 주셔서 감사합니다. 너에게 큰 감사! 주요 문제는 여전히 주문 중입니다. CUD에 20 개 이상의 엔터티가 있습니다. 주문을 사용하면 1,2,3,4를 따라야하고 9보다 많은 주문을하면 1,12,13,2,3으로 목록이 업데이트됩니다. , 4 등. 그것이 사전 순으로 주문하는 것입니다. 나는 갇혀있어 셀렌과 함께 Nunit을 사용하는 데 매우 지쳤다. 몇 가지 데모를 제공해 주시겠습니까? 테스트가 수백 개가되고 내 욕망에 따라 테스트를 수행해야하는 경우 어떻게해야합니까? 그렇게하기 위해 래퍼 (wrapper)를 사용할 수도 있습니다. 나는 내가 어떤 것을 받아 들일 수있는 지점에있다. – Umar