硒的webdriver +詹金斯 [英] Selenium WebDriver + Jenkins

查看:299
本文介绍了硒的webdriver +詹金斯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的硒与自动化。使用Selenium IDE和我的Java的一般知识,我能够做出一系列的测试案例在Eclipse中的JUnit的运行。现在,当我在Eclipse和preSS [运行]我的测试目前运行的是。我想导入这些测试用例詹金斯/ Husdson。有两种方法我会preFER做CI。

1安排时间(1 /周)通过测试运行,并发送结果的电子邮件。

2 - 上传我的测试用例在GitHub和存储库时有做储备库的变化,按计划运行(1 /周)。

测试和/或

老实说,香港专业教育学院试图查找教程(视频/文档),但他们似乎都非常不清楚。只是举个例子,我不知道什么是一个build.xml,POM。

它是更好用詹金斯插件做到这一点,或使用Ant或Maven?如果是的话是什么我需要添加在我的code /更改为允许这种情况发生,并在詹金斯配置的东西。

任何帮助将大大AP preciated。

谢谢,

我的例子code如下:

  package配置文件;进口java.util.concurrent.TimeUnit中;
进口的java.util.regex.Pattern;
进口java.util.concurrent.TimeUnit中;
导入org.junit *。
引入静态org.junit.Assert *。
导入org.openqa.selenium *。
进口org.openqa.selenium.firefox.FirefoxDriver;
进口org.openqa.selenium.interactions.Actions;
进口org.openqa.selenium.support.ui.Select;
进口com.opera.core.systems.scope.protos.ExecProtos.ActionList.Action;公共类P_ProfileChangeTestCase {
  私人司机的webdriver;
  私人字符串的baseUrl;
  私人的StringBuffer verificationErrors =新的StringBuffer();//在测试开始之前,创建一个新的webdriver并设置基本URL
  @之前
  公共无效设置()抛出异常{
    司机=新FirefoxDriver();
    的baseUrl =htt​​p://www.test.com/;
    driver.manage()超时()implicitlyWait(10 TimeUnit.SECONDS)。  }  @测试
  公共无效testOpen()抛出异常{
    的System.out.println(**启动配置文件**);
    driver.get(的baseUrl);
//点​​击Login
的System.out.println(点击登录);
driver.findElement(By.cssSelector(div.button.login> a.link))。点击();
//输入用户名
的System.out.println(输入用户名);
driver.findElement(By.xpath(//输入[@ ID ='登录']))的SendKeys(TEST)。
//输入密码
的System.out.println(输入密码);
driver.findElement(By.xpath(//输入[@ ID ='login_password']))的SendKeys(PW);
//点​​击登录按钮
的System.out.println(提交登录);
。driver.findElement(By.className(登录按钮))点击();
//通过回声名称验证用户名登录到控制台
的System.out.println(验证用户登录);
字符串文本= driver.findElement(By.cssSelector(span.username))的getText()。
的System.out.println(用户名是:+文字);
////////////////////////
//点​​击编辑个人资料
的System.out.println(点击编辑个人资料按钮);
。driver.findElement(By.cssSelector(div.button.login))点击();
driver.findElement(By.xpath(// DIV [@ ID ='MLG头']​​ / DIV / DIV [3] / DIV / DIV [7] / DIV / DIV [2] / A))。点击();
//在个人资料变更说明
的System.out.println(编辑个人资料利益科);
。driver.findElement(By.name(利益))清();
driver.findElement(By.name(利益))的SendKeys(硒Eclipse的编辑个人资料)。
//更新个人信息
的System.out.println(点击提交修改个人资料);
driver.findElement(By.cssSelector(输入[类型= \\提交\\]))点击()。
//验证更新已应用于简介
的System.out.println(Verifing这种变化已取得);
的assertEquals(个人资料已更新。driver.findElement(By.cssSelector(B> B))的getText());
断言声明//控制台输出大于
的System.out.println(个人资料已更新!);
的System.out.println(**完整的档案**!);  }  @后
  公共无效拆解()抛出异常{
driver.quit();
串verificationErrorString = verificationErrors.toString();
如果(!。等于(verificationErrorString)){
  失败(verificationErrorString);
    }
  }
  私人布尔isAlert present(){
    尝试{
      driver.switchTo()警报()。
      返回true;
    }赶上(NoAlert presentException E){
      返回false;
    }
      }
}


解决方案

根据您的信息,您可以创建使用maven项目基地的硒自动化。在这种情况下,如果你想使用詹金斯作为CI,这里是步骤:


  1. 确保你已经安装了Maven和建立maven的家在您的系统。

  2. 建立一个自由风格的软件项目创建新项目

  3. 转至 .jenkins 在您的系统文件夹中。如果您使用的是Mac,它会被放在里面的家。复制并粘贴自动化的工作文件夹中的硒项目(.jenkins /职位/自动化/ 工作区)。工作区文件夹需要手工创建。

  4. 创建任务/项目后,进入到来源$ C ​​$ C管理并设置为none(我假设你目前正在使用您的硒code从本地系统)。如果你想抓住从Git仓库的code,则需要先添加git的插件:詹金斯 - > 管理詹金斯 - > 管理插件 - >点击可用标签 - >搜索 Github的插件

  5. 检查建立定期构建触发器部分并将其设置为(0 7 * * *)。这意味着您的自动化将自动7日常运行。

  6. 添加构建 基于Maven命令来运行自动化的 MVN干净的测试。请选择执行shell 如果您使用 MAC / Linux的,或选择执行Windows批处理命令如果您使用视窗系统

  7. 如果您要发送的自动化结果的电子邮件,您需要安装电子邮件外部插件在詹金斯 - 管理插件,并成立了编辑电子邮件通知即可。如果有附件,Maven项目结果通常放置在目标文件夹下。下面我给大家例如压缩文件中,我有目标文件夹中。

  8. 保存詹金斯/项目。

  9. 设置了电子邮件发件人:进入詹金斯 - >管理詹金斯 - >配置系统,并按照以下附加步骤

  10. 最后,建立自己的詹金斯的项目/任务:

  11. 让我知道如果你还有什么问题;)

I am very new to Selenium and Automation. Using Selenium IDE and my general knowledge of Java I was able to make a series of test cases in Eclipse that run on Junit. Now my test currently run when I am in eclipse and press [run]. I would like to import these test cases to Jenkins/Husdson. There are two ways I would prefer doing the CI.

1- Schedule a time (1/week) to run through the tests and send email of result.

2- Upload my test cases to a repository on GitHub and when there is a change done to the repository, run the tests and/or on a schedule (1/week).

Ive honestly tried to look up tutorials (videos/documents) but they all seem very unclear. Just to give an example, I do not know what is a build.xml, POM.

Is it better to do this with a Jenkins Plugin or using ANT or Maven? If so what are the things I need to add/change in my code to allow this to happen, and configure in Jenkins.

Any help would greatly be appreciated.

Thanks,

My Example Code is Below:

package Profile;

import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import com.opera.core.systems.scope.protos.ExecProtos.ActionList.Action;

public class P_ProfileChangeTestCase {
  private WebDriver driver;
  private String baseUrl;
  private StringBuffer verificationErrors = new StringBuffer();

//Before the test begins, creates a new webdriver and sets the base url
  @Before
  public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = "http://www.test.com/";
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

  }

  @Test
  public void testOpen() throws Exception {
    System.out.println("**Starting Profile**");
    driver.get(baseUrl);
//Click LogIn
System.out.println("Clicking Log In");
driver.findElement(By.cssSelector("div.button.login > a.link")).click();
//Enter User name
System.out.println("Entering Username");
driver.findElement(By.xpath("//input[@id='login']")).sendKeys("TEST");
//Enter Password
System.out.println("Entering Password");
driver.findElement(By.xpath("//input[@id='login_password']")).sendKeys("PW");
//Click LogIn Button
System.out.println("Submit Log In");
driver.findElement(By.className("login-button")).click();
//Verify user name login by echo name to console
System.out.println("Verify User Log In");
String text = driver.findElement(By.cssSelector("span.username")).getText();
System.out.println("Username is :" + text);
////////////////////////
//Click on Edit Profile
System.out.println("Clicking on Edit Profile Button");
driver.findElement(By.cssSelector("div.button.login")).click();
driver.findElement(By.xpath("//div[@id='mlg-header']/div/div[3]/div/div[7]/div/div[2]/a")).click();
//Change description in profile
System.out.println("Editing the Interests section of profile");
driver.findElement(By.name("interests")).clear();
driver.findElement(By.name("interests")).sendKeys("Edit Profile in Selenium Eclipse");
//Update Profile
System.out.println("Click on submit to change profile");
driver.findElement(By.cssSelector("input[type=\"submit\"]")).click();
//Verify that update has been applied to profile
System.out.println("Verifing that change has been made");
assertEquals("Profile has been updated.", driver.findElement(By.cssSelector("b > b")).getText());
//Console Output of Assert Statement Above
System.out.println("Profile has been updated!");
System.out.println("**Profile Complete!**");

  }

  @After
  public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
  fail(verificationErrorString);
    }
  }
  private boolean isAlertPresent() {
    try {
      driver.switchTo().alert();
      return true;
    } catch (NoAlertPresentException e) {
      return false;
    }
      }
}

解决方案

Based on your information, you create your selenium automation using maven project base. In this case, if you want to use Jenkins as your CI, here is the steps :

  1. Make sure you have already installed maven and set up the maven home in your system.
  2. Create new item with Build a free-style software project.
  3. Go to the .jenkins folder in your system. If you are using mac, it'll be placed inside home. Copy and paste your selenium project inside the Automation job folder (.jenkins/jobs/Automation/workspace). The workspace folder should be created manually.
  4. After creating the job/project, go to the Source Code Management and set it as none (I assume currently you are using your selenium code from your local system). If you want to grab the code from git repository, you need to add the git plugin first : Jenkins -> Manage Jenkins -> Manage Plugins -> click on Available tab -> search for Github Plugin.
  5. Check the Build Periodically under Build Triggers part and set it to (0 7 * * *). It means your automation will automatically be run at 7 everyday.
  6. Add build to run your automation through maven command mvn clean test. Please choose Execute Shell if you use mac/linux, or choose Execute Windows Batch Command if you use Windows system.
  7. If you want to send the email of the automation result, you need to install the Email Ext Plugin in Jenkins-Manage Plugin and set up the Editable Email Notification. If you have the attachment, the maven project result usually placed under the target folder. Below I give you example of zip file that I have in target folder.
  8. Save your jenkins/project.
  9. Set up the email sender : Go to Jenkins -> Manage Jenkins -> Configure System and follow the steps attached below.
  10. Finally, build your jenkins project/job :
  11. Let me know if you still have any issue ;)

这篇关于硒的webdriver +詹金斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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