2016-05-25 8 views
-1

この質問で私を助けてくれますか?ウェブドライバコードを個別に管理する

私はテスト自動化フレームワークに取り組んでいます。私はウェブドライバコードを別に保存し、テストケースから開始したいと思います。

私を助けてください。 - 私はそれを正しく理解している場合のおかげ

+0

詳細を教えてください。あなたの必要は何ですか?あなたが求めているものは不明ですか? – Haxor

+0

不明な質問。 –

+0

申し訳ありませんでした - 私はFirefoxのドライバー、クロームドライバー、IEのドライバー、クッキーを管理するようなWebdriverのコードを処理でき、プロジェクトの下の場所でブラウザーを最大化し、私のテストケースでは、すべてのwebdriverコードを書くのではなく、1行のコードを追加するだけです。 –

答えて

0

行くための一place.Clickで作られるUIの変化による必要な変更を可能にします。以下の例では、すべてのテストクラスで使用できるTest Setupクラスを作成しました。

だから、これはTestSetupクラス -

 using NUnit.Framework; 
    using OpenQA.Selenium; 
    using OpenQA.Selenium.Chrome; 
    using OpenQA.Selenium.Firefox; 
    using OpenQA.Selenium.IE; 



    namespace dummy 
    { 
     [SetUpFixture] 
     public class TestSetup 
     { 
      public static IWebDriver driver; 


      [OneTimeSetUp] 
      public void testSetup() 
      { 

       if (driver == null) 
       { 
        //Local Tests 
        driver = new FirefoxDriver(); 

       } 
      } 


      public static bool IsElementPresent(By by) 
      { 
       try 
       { 
        driver.FindElement(by); 
        return true; 
       } 
       catch (NoSuchElementException) 
       { 
        return false; 
       } 
      } 

      [OneTimeTearDown] 
      public void TearDown() 
      { 
       driver.Quit(); 
      } 

     } 
    } 

それ以下のTestCaseクラスますすることができますでしょう。 testクラスのすべての関数をテストクラスが継承することに注意してください。

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

namespace dummy 
{ 
    [TestFixture] 
    [Parallelizable] 
    public class TESTCASE 
    {   

     IWebDriver driver = TestSetup.driver; 

     [Test] 

     public void siteVisit() 
     { 
      driver.Navigate().GoToUrl("http://google.com"); 
      Assert.IsTrue(String.Equals("Google, driver.Title)); 

     } 

    } 
} 
+0

ありがとうRahul ..私は確かにこれを試して、あなたを知ってみましょう。 –

0

こんにちはその後、POM(Pageオブジェクトフレームワーク)

1.The main advantage of Page Object Model is that if the UI changes for any page, it don’t 
require us to change any tests, we just need to change only the code within the page objects 
(Only at one place). 

2.Page Object model is writing all the functionalities/reusable components of a page that 
we want to automate in a separate class. 

3.As per google wiki Page object **"Within your web app’s UI there are areas that your tests 
interact with. A Page Object simply models these as objects within the test code. This 
reduces the amount of duplicated code and means that if the UI changes, the fix need only 
be applied in one place."** 

Example : google home page 

1.Say now if we consider our google home page as Home page. 
2.For the above pages we will create class as HomePage.class. 
3.In class we will identify and write reusable methods which are specific to Home page. 
4.'google home page' which will have many options like Search, Sign In, +You, Images etc. 
5.Now all functionalities that we want to automate should have reusable methods/components 
for each page. 
6.as our main page is google page we can navigate to other pages by clicking on any link 
from the google page. When ever we are navigating to other page, we need to return that page 
object. Else Return the current page object as this action doesn't navigate to a other page 
represented by another Page Object. 

利点のために行ってください。

1.There is clean separation between test code and page specific code such as locators 
(or their use if you’re using a UI map) and layout. 
2.There is single repository for the services or operations offered by the page rather than 
    having these services scattered through out the tests. 

は、両方の場合において、これは、すべてのカプセル化とPOMモデルのより上のPOM

+0

ありがとうRaj - 私はこれを試み、あなたに知らせます。 –

+0

あなたがPOMの助けを必要とする場合は確かにお気軽にお問い合わせください –

関連する問題