2017-05-10 2 views
0

src/test/java/Stepdefinations/pagesの下にあるページパッケージ内に基本クラスを作成しました。ページパッケージにAccountクラス(ページオブジェクト)を作成しました。作成されたアカウントステップクラス(ステップ定義ファイル)、ステップ定義パッケージのランナークラス。ランナークラス実行時にコードのクリックメソッドがスキップされる

ランナークラスを実行したときにブラウザを開くことができましたが、クリックメソッドはセレンの基本クラスでは発生していません。あなたがに見ることができます

//Selenium base class: 

    package Stepdfinations.pages; 


    import java.io.File; 
    import java.net.URL; 
    import java.io.FileInputStream; 
    import java.io.FileNotFoundException; 
    import java.io.IOException; 
    import java.util.Properties; 
    import java.util.concurrent.TimeUnit; 

    import org.apache.commons.logging.Log; 
    import org.apache.log4j.Logger; 
    import org.openqa.selenium.WebDriver; 
    import org.openqa.selenium.WebElement; 
    import org.openqa.selenium.chrome.ChromeDriver; 
    import org.testng.annotations.Test; 
    import java.net.HttpURLConnection; 
    import java.net.MalformedURLException; 
    public class SeleniumBaseclass 
    { 


     Properties prop; 
     public HttpURLConnection connection = null; 
     String currenturl; 

     protected WebDriver driver; 
     public SeleniumBaseclass (WebDriver driver) 
     { 
      this.driver=driver; 
     } 
    public void Property() throws Exception 
     { 




       File f= new File("C:\\Users\\watareuman9\\workspace\\Cucumberproject\\src\\test\\resources\\data\\config.property"); 

       FileInputStream fis = new FileInputStream(f); 
       prop=new Properties(); 

         prop.load(fis); 
         System.setProperty("webdriver.chrome.driver", getChromespath()); 
         driver=new ChromeDriver(); 
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); 

        driver.get(getAppurl()); 
        Thread.sleep(500); 


     } 
         public String getChromespath() 
         { 
           return prop.getProperty("ChromePath"); 
         } 

         public String getAppurl() 
         { 
           return prop.getProperty("URL"); 
         } 

         //click method 

         public void click(String objstr,WebElement objname) 

         {try 
         { 
          Thread.sleep(5000); 
          objname.click(); 


          System.out.println("'"+objstr+"'"+"is clickde"); 
         } 
         catch(Exception e) 
         { 
          getHttpResponse(); 
         } 
         } 

         public void getCurrenturl() 
         { 
          String currenturl=driver.getCurrentUrl(); 
         } 

         public void getHttpResponse() 
         { 
          try 
          { 
           getCurrenturl(); 

           URL url=new URL(currenturl); 
           HttpURLConnection connection=(HttpURLConnection)url.openConnection(); 
           connection.setConnectTimeout(3000); 
           connection.connect(); 
           if(connection.getResponseCode()==200) 
           { 
            System.out.println(currenturl +"-"+connection.getResponseMessage()); 

           } 
           else if(connection.getResponseCode()==connection.HTTP_NOT_FOUND) 
           { 
            System.out.println(currenturl +"-"+connection.getResponseMessage()); 
           } 
          } 
           catch(Exception e) 
           { 
            e.getMessage(); 
           } 
         } 
          public void getQuitdriver() 
          { 
           driver.close(); 
          } 
         } 


    //Account class(page objects) 

    package Stepdfinations.pages; 


    import org.openqa.selenium.By; 
    import org.openqa.selenium.WebDriver; 
    import org.openqa.selenium.WebElement; 
    import org.openqa.selenium.support.FindBy; 
    import org.openqa.selenium.support.How; 

    public class Account extends SeleniumBaseclass 
    { 
     public Account(WebDriver driver) 
     { 
      super(driver); 

      this.driver=driver; 
     } 

     @FindBy(how = How.XPATH, using = "//*[@id='bodyContent']/div/div[1]/a[1]/u") 
     private WebElement login_button; 
    public void clickLoginButton() 
    { 
    click("login_button",login_button); 


    } 
    } 


    //Accountsteps(Step defination file) 

    package Stepdfinations; 


import java.util.concurrent.TimeUnit; 

import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.chrome.ChromeDriver; 

    import cucumber.api.java.en.Given; 
import cucumber.api.java.en.When; 

import org.openqa.selenium.support.FindBy; 
    import org.openqa.selenium.By; 
    import Stepdfinations.pages.Account; 

    import Stepdfinations.pages.SeleniumBaseclass; 

    public class Acoountsteps 
    { 
     WebDriver driver; 
     Account act; 
     @Given("^I navigated to the Login page$") 
     public void i_navigated_to_the_Login_page() throws Throwable 
     { 
      act=new Account(driver); 
      act.Property(); 
     } 
     @When("^I click on the New Account link$") 
     public void i_click_on_the_New_Account_link() throws Throwable 
     { 
      act.clickLoginButton(); 


     } 

    } 



    //Runner class 



    package Stepdfinations; 

    import org.junit.runner.RunWith; 
    import cucumber.api.junit.Cucumber; 
    import cucumber.api.CucumberOptions; 

    @RunWith(Cucumber.class) 
    @CucumberOptions(features="src/test/resources/features") 

    public class Runner 
    { 

    } 
+0

[最小、完全で検証可能な例を追加してください](https://stackoverflow.com/help/mcve) –

+0

私はすべての情報を提供しています。私は何を追加する必要があるのだろうかと疑問に思っています –

+0

ステップ定義クラスがありません。 accountpoを2回コピーしました。 ur xpathは正しいですか? url接続コードの目的は何ですか? – Grasshopper

答えて

0

いくつかのこと:

  • (あなたはそれのために放火犯を使用することができます)あなたのxのパスを確認してください、あなたのコードをデバッグしてみ - あなたにテストしたりしませデバッガ着陸です。
  • おそらく、テストクラスまたはテストメソッドをランナークラスに記述する必要があります(たとえば、testNGでは、testNGランナーを通してコードが実行される場合、testNGが実行するXMLファイルにTestまたはクラスを記述する必要があります)。何がないか)。
関連する問題